3 days until Hackathon49 days until Conference

Connect and innovate with the AsyncAPI Community.

2.1.0

Found an error? Have a suggestion?Edit this page on Github

AsyncAPI Specification

Disclaimer

Part of this content has been taken from the great work done by the folks at the OpenAPI Initiative. Mainly because it's a great work and we want to keep as much compatibility as possible with the OpenAPI Specification.

Version 2.1.0

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

The AsyncAPI Specification is licensed under The Apache License, Version 2.0.

Introduction

The AsyncAPI Specification is a project used to describe and document message-driven APIs in a machine-readable format. It’s protocol-agnostic, so you can use it for APIs that work over any protocol (e.g., AMQP, MQTT, WebSockets, Kafka, STOMP, HTTP, Mercure, etc).

The AsyncAPI Specification defines a set of files required to describe such an API. These files can then be used to create utilities, such as documentation, integration and/or testing tools.

The file(s) MUST describe the operations an application accepts. For instance, consider the following AsyncAPI definition snippet:

1
2
3
user/signedup:
  subscribe:
    $ref: "#/components/messages/userSignUp"

It means that the application allows consumers to subscribe to the user/signedup channel to receive userSignUp messages produced by the application.

The AsyncAPI specification does not assume any kind of software topology, architecture or pattern. Therefore, a server MAY be a message broker, a web server or any other kind of computer program capable of sending and/or receiving data. However, AsyncAPI offers a mechanism called "bindings" that aims to help with more specific information about the protocol.

Definitions

Application

An application is any kind of computer program or a group of them. It MUST be a producer, a consumer or both. An application MAY be a microservice, IoT device (sensor), mainframe process, etc. An application MAY be written in any number of different programming languages as long as they support the selected protocol. An application MUST also use a protocol supported by the server in order to connect and exchange messages.

Producer

A producer is a type of application, connected to a server, that is creating messages and addressing them to channels. A producer MAY be publishing to multiple channels depending on the server, protocol, and use-case pattern.

Consumer

A consumer is a type of application, connected to a server via a supported protocol, that is consuming messages from channels. A consumer MAY be consuming from multiple channels depending on the server, protocol, and the use-case pattern.

Message

A message is the mechanism by which information is exchanged via a channel between servers and applications. A message MUST contain a payload and MAY also contain headers. The headers MAY be subdivided into protocol-defined headers and header properties defined by the application which can act as supporting metadata. The payload contains the data, defined by the application, which MUST be serialized into a format (JSON, XML, Avro, binary, etc.). Since a message is a generic mechanism, it can support multiple interaction patterns such as event, command, request, or response.

Channel

A channel is an addressable component, made available by the server, for the organization of messages. Producer applications send messages to channels and consumer applications consume messages from channels. Servers MAY support many channel instances, allowing messages with different content to be addressed to different channels. Depending on the server implementation, the channel MAY be included in the message via protocol-defined headers.

Protocol

A protocol is the mechanism (wireline protocol or API) by which messages are exchanged between the application and the channel. Example protocols include, but are not limited to, AMQP, HTTP, JMS, Kafka, MQTT, STOMP, Mercure, WebSocket.

Bindings

A "binding" (or "protocol binding") is a mechanism to define protocol-specific information. Therefore, a protocol binding MUST define protocol-specific information only.

Specification

Format

The files describing the message-driven API in accordance with the AsyncAPI Specification are represented as JSON objects and conform to the JSON standards. YAML, being a superset of JSON, can be used as well to represent a A2S (AsyncAPI Specification) file.

For example, if a field is said to have an array value, the JSON array representation will be used:

1
2
3
{
   "field" : [...]
}

While the API is described using JSON it does not impose a JSON input/output to the API itself.

All field names in the specification are case sensitive.

The schema exposes two types of fields. Fixed fields, which have a declared name, and Patterned fields, which declare a regex pattern for the field name. Patterned fields can have multiple occurrences as long as each has a unique name.

In order to preserve the ability to round-trip between YAML and JSON formats, YAML version 1.2 is recommended along with some additional constraints:

  • Tags MUST be limited to those allowed by the JSON Schema ruleset
  • Keys used in YAML maps MUST be limited to a scalar string, as defined by the YAML Failsafe schema ruleset

File Structure

The A2S representation of the API is made of a single file. However, parts of the definitions can be split into separate files, at the discretion of the user. This is applicable for $ref fields in the specification as follows from the JSON Schema definitions.

By convention, the AsyncAPI Specification (A2S) file is named asyncapi.json or asyncapi.yaml.

Schema

AsyncAPI Object

This is the root document object for the API specification. It combines resource listing and API declaration together into one document.

Fixed Fields
Field NameTypeDescription
asyncapiAsyncAPI Version StringRequired. Specifies the AsyncAPI Specification version being used. It can be used by tooling Specifications and clients to interpret the version. The structure shall be major.minor.patch, where patch versions must be compatible with the existing major.minor tooling. Typically patch versions will be introduced to address errors in the documentation, and tooling should typically be compatible with the corresponding major.minor (1.0.*). Patch versions will correspond to patches of this document.
idIdentifierIdentifier of the application the AsyncAPI document is defining.
infoInfo ObjectRequired. Provides metadata about the API. The metadata can be used by the clients if needed.
serversServers ObjectProvides connection details of servers.
defaultContentTypeDefault Content TypeDefault content type to use when encoding/decoding a message's payload.
channelsChannels ObjectRequired The available channels and messages for the API.
componentsComponents ObjectAn element to hold various schemas for the specification.
tagsTags ObjectA list of tags used by the specification with additional metadata. Each tag name in the list MUST be unique.
externalDocsExternal Documentation ObjectAdditional external documentation.

This object can be extended with Specification Extensions.

AsyncAPI Version String

The version string signifies the version of the AsyncAPI Specification that the document complies to. The format for this string must be major.minor.patch. The patch may be suffixed by a hyphen and extra alphanumeric characters.

A major.minor shall be used to designate the AsyncAPI Specification version, and will be considered compatible with the AsyncAPI Specification specified by that major.minor version. The patch version will not be considered by tooling, making no distinction between 1.0.0 and 1.0.1.

In subsequent versions of the AsyncAPI Specification, care will be given such that increments of the minor version should not interfere with operations of tooling developed to a lower minor version. Thus a hypothetical 1.1.0 specification should be usable with tooling designed for 1.0.0.

Identifier

This field represents a unique universal identifier of the application the AsyncAPI document is defining. It must conform to the URI format, according to RFC3986.

It is RECOMMENDED to use a URN to globally and uniquely identify the application during long periods of time, even after it becomes unavailable or ceases to exist.

Examples
1
2
3
{
  "id": "urn:com:smartylighting:streetlights:server"
}
id: 'urn:com:smartylighting:streetlights:server'
1
2
3
{
  "id": "https://github.com/smartylighting/streetlights-server"
}
id: 'https://github.com/smartylighting/streetlights-server'

Info Object

The object provides metadata about the API. The metadata can be used by the clients if needed.

Fixed Fields
Field NameTypeDescription
titlestringRequired. The title of the application.
versionstringRequired Provides the version of the application API (not to be confused with the specification version).
descriptionstringA short description of the application. CommonMark syntax can be used for rich text representation.
termsOfServicestringA URL to the Terms of Service for the API. MUST be in the format of a URL.
contactContact ObjectThe contact information for the exposed API.
licenseLicense ObjectThe license information for the exposed API.

This object can be extended with Specification Extensions.

Info Object Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
  "title": "AsyncAPI Sample App",
  "description": "This is a sample server.",
  "termsOfService": "https://asyncapi.org/terms/",
  "contact": {
    "name": "API Support",
    "url": "https://www.asyncapi.org/support",
    "email": "support@asyncapi.org"
  },
  "license": {
    "name": "Apache 2.0",
    "url": "https://www.apache.org/licenses/LICENSE-2.0.html"
  },
  "version": "1.0.1"
}
1
2
3
4
5
6
7
8
9
10
11
title: AsyncAPI Sample App
description: This is a sample server.
termsOfService: https://asyncapi.org/terms/
contact:
  name: API Support
  url: https://www.asyncapi.org/support
  email: support@asyncapi.org
license:
  name: Apache 2.0
  url: https://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.1

Contact Object

Contact information for the exposed API.

Fixed Fields
Field NameTypeDescription
namestringThe identifying name of the contact person/organization.
urlstringThe URL pointing to the contact information. MUST be in the format of a URL.
emailstringThe email address of the contact person/organization. MUST be in the format of an email address.

This object can be extended with Specification Extensions.

Contact Object Example:
1
2
3
4
5
{
  "name": "API Support",
  "url": "https://www.example.com/support",
  "email": "support@example.com"
}
1
2
3
name: API Support
url: https://www.example.com/support
email: support@example.com

License Object

License information for the exposed API.

Fixed Fields
Field NameTypeDescription
namestringRequired. The license name used for the API.
urlstringA URL to the license used for the API. MUST be in the format of a URL.

This object can be extended with Specification Extensions.

License Object Example:
1
2
3
4
{
  "name": "Apache 2.0",
  "url": "https://www.apache.org/licenses/LICENSE-2.0.html"
}
1
2
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html

Servers Object

The Servers Object is a map of Server Objects.

Patterned Fields
Field PatternTypeDescription
^[A-Za-z0-9_\-]+$Server ObjectThe definition of a server this application MAY connect to.
Servers Object Example
1
2
3
4
5
6
7
8
{
  "production": {
    "url": "development.gigantic-server.com",
    "description": "Development server",
    "protocol": "kafka",
    "protocolVersion": "1.0.0"
  }
}
1
2
3
4
5
production:
  url: development.gigantic-server.com
  description: Development server
  protocol: kafka
  protocolVersion: '1.0.0'

Server Object

An object representing a message broker, a server or any other kind of computer program capable of sending and/or receiving data. This object is used to capture details such as URIs, protocols and security configuration. Variable substitution can be used so that some details, for example usernames and passwords, can be injected by code generation tools.

Fixed Fields
Field NameTypeDescription
urlstringREQUIRED. A URL to the target host. This URL supports Server Variables and MAY be relative, to indicate that the host location is relative to the location where the AsyncAPI document is being served. Variable substitutions will be made when a variable is named in {brackets}.
protocolstringREQUIRED. The protocol this URL supports for connection. Supported protocol include, but are not limited to: amqp, amqps, http, https, ibmmq, jms, kafka, kafka-secure, mqtt, secure-mqtt, stomp, stomps, ws, wss, mercure.
protocolVersionstringThe version of the protocol used for connection. For instance: AMQP 0.9.1, HTTP 2.0, Kafka 1.0.0, etc.
descriptionstringAn optional string describing the host designated by the URL. CommonMark syntax MAY be used for rich text representation.
variablesMap[string, Server Variable Object]A map between a variable name and its value. The value is used for substitution in the server's URL template.
security[Security Requirement Object]A declaration of which security mechanisms can be used with this server. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a connection or operation.
bindingsServer Bindings Object | Reference ObjectA map where the keys describe the name of the protocol and the values describe protocol-specific definitions for the server.

This object MAY be extended with Specification Extensions.

Server Object Example

A single server would be described as:

1
2
3
4
5
6
{
  "url": "development.gigantic-server.com",
  "description": "Development server",
  "protocol": "kafka",
  "protocolVersion": "1.0.0"
}
1
2
3
4
url: development.gigantic-server.com
description: Development server
protocol: kafka
protocolVersion: '1.0.0'

The following shows how multiple servers can be described, for example, at the AsyncAPI Object's servers:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
  "servers": {
    "development": {
      "url": "development.gigantic-server.com",
      "description": "Development server",
      "protocol": "amqp",
      "protocolVersion": "0.9.1"
    },
    "staging": {
      "url": "staging.gigantic-server.com",
      "description": "Staging server",
      "protocol": "amqp",
      "protocolVersion": "0.9.1"
    },
    "production": {
      "url": "api.gigantic-server.com",
      "description": "Production server",
      "protocol": "amqp",
      "protocolVersion": "0.9.1"
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
servers:
  development:
    url: development.gigantic-server.com
    description: Development server
    protocol: amqp
    protocolVersion: 0.9.1
  staging:
    url: staging.gigantic-server.com
    description: Staging server
    protocol: amqp
    protocolVersion: 0.9.1
  production:
    url: api.gigantic-server.com
    description: Production server
    protocol: amqp
    protocolVersion: 0.9.1

The following shows how variables can be used for a server configuration:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
  "servers": {
    "production": {
      "url": "{username}.gigantic-server.com:{port}/{basePath}",
      "description": "The production API server",
      "protocol": "secure-mqtt",
      "variables": {
        "username": {
          "default": "demo",
          "description": "This value is assigned by the service provider, in this example `gigantic-server.com`"
        },
        "port": {
          "enum": [
            "8883",
            "8884"
          ],
          "default": "8883"
        },
        "basePath": {
          "default": "v2"
        }
      }
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
servers:
  production:
    url: '{username}.gigantic-server.com:{port}/{basePath}'
    description: The production API server
    protocol: secure-mqtt
    variables:
      username:
        # note! no enum here means it is an open value
        default: demo
        description: This value is assigned by the service provider, in this example `gigantic-server.com`
      port:
        enum:
          - '8883'
          - '8884'
        default: '8883'
      basePath:
        # open meaning there is the opportunity to use special base paths as assigned by the provider, default is `v2`
        default: v2

Server Variable Object

An object representing a Server Variable for server URL template substitution.

Fixed Fields
Field NameTypeDescription
enum[string]An enumeration of string values to be used if the substitution options are from a limited set.
defaultstringThe default value to use for substitution, and to send, if an alternate value is not supplied.
descriptionstringAn optional description for the server variable. CommonMark syntax MAY be used for rich text representation.
examples[string]An array of examples of the server variable.

This object MAY be extended with Specification Extensions.

Default Content Type

A string representing the default content type to use when encoding/decoding a message's payload. The value MUST be a specific media type (e.g. application/json). This value MUST be used by schema parsers when the contentType property is omitted.

In case a message can't be encoded/decoded using this value, schema parsers MUST use their default content type.

Default Content Type Example
1
2
3
{
  "defaultContentType": "application/json"
}
defaultContentType: application/json

Channels Object

Holds the relative paths to the individual channel and their operations. Channel paths are relative to servers.

Channels are also known as "topics", "routing keys", "event types" or "paths".

Patterned Fields
Field PatternTypeDescription
{channel}Channel Item ObjectA relative path to an individual channel. The field name MUST be in the form of a RFC 6570 URI template. Query parameters and fragments SHALL NOT be used, instead use bindings to define them.
Channels Object Example
1
2
3
4
5
6
7
{
  "user/signedup": {
    "subscribe": {
      "$ref": "#/components/messages/userSignedUp"
    }
  }
}
1
2
3
user/signedup:
  subscribe:
    $ref: "#/components/messages/userSignedUp"

Channel Item Object

Describes the operations available on a single channel.

Fixed Fields
Field NameTypeDescription
$refstringAllows for an external definition of this channel item. The referenced structure MUST be in the format of a Channel Item Object. If there are conflicts between the referenced definition and this Channel Item's definition, the behavior is undefined.
descriptionstringAn optional description of this channel item. CommonMark syntax can be used for rich text representation.
subscribeOperation ObjectA definition of the SUBSCRIBE operation, which defines the messages produced by the application and sent to the channel.
publishOperation ObjectA definition of the PUBLISH operation, which defines the messages consumed by the application from the channel.
parametersParameters ObjectA map of the parameters included in the channel name. It SHOULD be present only when using channels with expressions (as defined by RFC 6570 section 2.2).
bindingsChannel Bindings Object | Reference ObjectA map where the keys describe the name of the protocol and the values describe protocol-specific definitions for the channel.

This object can be extended with Specification Extensions.

Channel Item Object Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
  "description": "This channel is used to exchange messages about users signing up",
  "subscribe": {
    "summary": "A user signed up.",
    "message": {
      "description": "A longer description of the message",
      "payload": {
        "type": "object",
        "properties": {
          "user": {
            "$ref": "#/components/schemas/user"
          },
          "signup": {
            "$ref": "#/components/schemas/signup"
          }
        }
      }
    }
  },
  "bindings": {
    "amqp": {
      "is": "queue",
      "queue": {
        "exclusive": true
      }
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
description: This channel is used to exchange messages about users signing up
subscribe:
  summary: A user signed up.
  message:
    description: A longer description of the message
    payload:
      type: object
      properties:
        user:
          $ref: "#/components/schemas/user"
        signup:
bindings:
  amqp:
    is: queue
    queue:
      exclusive: true

Using oneOf to specify multiple messages per operation:

1
2
3
4
5
6
7
8
9
10
{
  "subscribe": {
    "message": {
      "oneOf": [
        { "$ref": "#/components/messages/signup" },
        { "$ref": "#/components/messages/login" }
      ]
    }
  }
}
1
2
3
4
5
subscribe:
  message:
    oneOf:
      - $ref: '#/components/messages/signup'
      - $ref: '#/components/messages/login'

Operation Object

Describes a publish or a subscribe operation. This provides a place to document how and why messages are sent and received.

For example, an operation might describe a chat application use case where a user sends a text message to a group. A publish operation describes messages that are received by the chat application, whereas a subscribe operation describes messages that are sent by the chat application.

Fixed Fields
Field NameTypeDescription
operationIdstringUnique string used to identify the operation. The id MUST be unique among all operations described in the API. The operationId value is case-sensitive. Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is RECOMMENDED to follow common programming naming conventions.
summarystringA short summary of what the operation is about.
descriptionstringA verbose explanation of the operation. CommonMark syntax can be used for rich text representation.
tagsTags ObjectA list of tags for API documentation control. Tags can be used for logical grouping of operations.
externalDocsExternal Documentation ObjectAdditional external documentation for this operation.
bindingsOperation Bindings Object | Reference ObjectA map where the keys describe the name of the protocol and the values describe protocol-specific definitions for the operation.
traits[Operation Trait Object | Reference Object ]A list of traits to apply to the operation object. Traits MUST be merged into the operation object using the JSON Merge Patch algorithm in the same order they are defined here.
message[Message Object | Reference Object]A definition of the message that will be published or received on this channel. oneOf is allowed here to specify multiple messages, however, a message MUST be valid only against one of the referenced message objects.

This object can be extended with Specification Extensions.

Operation Object Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{
  "operationId": "registerUser",
  "summary": "Action to sign a user up.",
  "description": "A longer description",
  "tags": [
    { "name": "user" },
    { "name": "signup" },
    { "name": "register" }
  ],
  "message": {
    "headers": {
      "type": "object",
      "properties": {
        "applicationInstanceId": {
          "description": "Unique identifier for a given instance of the publishing application",
          "type": "string"
        }
      }
    },
    "payload": {
      "type": "object",
      "properties": {
        "user": {
          "$ref": "#/components/schemas/userCreate"
        },
        "signup": {
          "$ref": "#/components/schemas/signup"
        }
      }
    }
  },
  "bindings": {
    "amqp": {
      "ack": false
    }
  },
  "traits": [
    { "$ref": "#/components/operationTraits/kafka" }
  ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
operationId: registerUser
summary: Action to sign a user up.
description: A longer description
tags:
  - name: user
  - name: signup
  - name: register
message:
  headers:
    type: object
    properties:
      applicationInstanceId:
        description: Unique identifier for a given instance of the publishing application
        type: string
  payload:
    type: object
    properties:
      user:
        $ref: "#/components/schemas/userCreate"
      signup:
        $ref: "#/components/schemas/signup"
bindings:
  amqp:
    ack: false
traits:
  - $ref: "#/components/operationTraits/kafka"

Operation Trait Object

Describes a trait that MAY be applied to an Operation Object. This object MAY contain any property from the Operation Object, except message and traits.

If you're looking to apply traits to a message, see the Message Trait Object.

Fixed Fields
Field NameTypeDescription
operationIdstringUnique string used to identify the operation. The id MUST be unique among all operations described in the API. The operationId value is case-sensitive. Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is RECOMMENDED to follow common programming naming conventions.
summarystringA short summary of what the operation is about.
descriptionstringA verbose explanation of the operation. CommonMark syntax can be used for rich text representation.
tagsTags ObjectA list of tags for API documentation control. Tags can be used for logical grouping of operations.
externalDocsExternal Documentation ObjectAdditional external documentation for this operation.
bindingsOperation Bindings Object | Reference ObjectA map where the keys describe the name of the protocol and the values describe protocol-specific definitions for the operation.

This object can be extended with Specification Extensions.

Operation Trait Object Example
1
2
3
4
5
6
7
{
  "bindings": {
    "amqp": {
      "ack": false
    }
  }
}
1
2
3
bindings:
  amqp:
    ack: false

Parameters Object

Describes a map of parameters included in a channel name.

This map MUST contain all the parameters used in the parent channel name.

Patterned Fields
Field PatternTypeDescription
^[A-Za-z0-9_\-]+$Parameter Object | Reference ObjectThe key represents the name of the parameter. It MUST match the parameter name used in the parent channel name.
Parameters Object Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
  "user/{userId}/signup": {
    "parameters": {
      "userId": {
        "description": "Id of the user.",
        "schema": {
          "type": "string"
        }
      }
    },
    "subscribe": {
      "$ref": "#/components/messages/userSignedUp"
    }
  }
}
1
2
3
4
5
6
7
8
user/{userId}/signup:
  parameters:
    userId:
      description: Id of the user.
      schema:
        type: string
  subscribe:
    $ref: "#/components/messages/userSignedUp"

Parameter Object

Describes a parameter included in a channel name.

Fixed Fields
Field NameTypeDescription
descriptionstringA verbose explanation of the parameter. CommonMark syntax can be used for rich text representation.
schemaSchema Object | Reference ObjectDefinition of the parameter.
locationstringA runtime expression that specifies the location of the parameter value. Even when a definition for the target field exists, it MUST NOT be used to validate this parameter but, instead, the schema property MUST be used.

This object can be extended with Specification Extensions.

Parameter Object Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
  "user/{userId}/signup": {
    "parameters": {
      "userId": {
        "description": "Id of the user.",
        "schema": {
          "type": "string"
        },
        "location": "$message.payload#/user/id"
      }
    },
    "subscribe": {
      "$ref": "#/components/messages/userSignedUp"
    }
  }
}
1
2
3
4
5
6
7
8
9
user/{userId}/signup:
  parameters:
    userId:
      description: Id of the user.
      schema:
        type: string
      location: $message.payload#/user/id
  subscribe:
    $ref: "#/components/messages/userSignedUp"

Server Bindings Object

Map describing protocol-specific definitions for a server.

Fixed Fields
Field NameTypeDescription
httpHTTP Server BindingProtocol-specific information for an HTTP server.
wsWebSockets Server BindingProtocol-specific information for a WebSockets server.
kafkaKafka Server BindingProtocol-specific information for a Kafka server.
amqpAMQP Server BindingProtocol-specific information for an AMQP 0-9-1 server.
amqp1AMQP 1.0 Server BindingProtocol-specific information for an AMQP 1.0 server.
mqttMQTT Server BindingProtocol-specific information for an MQTT server.
mqtt5MQTT 5 Server BindingProtocol-specific information for an MQTT 5 server.
natsNATS Server BindingProtocol-specific information for a NATS server.
jmsJMS Server BindingProtocol-specific information for a JMS server.
snsSNS Server BindingProtocol-specific information for an SNS server.
sqsSQS Server BindingProtocol-specific information for an SQS server.
stompSTOMP Server BindingProtocol-specific information for a STOMP server.
redisRedis Server BindingProtocol-specific information for a Redis server.
mercureMercure Server BindingProtocol-specific information for a Mercure server.
ibmmqIBM MQ Server BindingProtocol-specific information for an IBM MQ server.

This object can be extended with Specification Extensions.

Channel Bindings Object

Map describing protocol-specific definitions for a channel.

Fixed Fields
Field NameTypeDescription
httpHTTP Channel BindingProtocol-specific information for an HTTP channel.
wsWebSockets Channel BindingProtocol-specific information for a WebSockets channel.
kafkaKafka Channel BindingProtocol-specific information for a Kafka channel.
amqpAMQP Channel BindingProtocol-specific information for an AMQP 0-9-1 channel.
amqp1AMQP 1.0 Channel BindingProtocol-specific information for an AMQP 1.0 channel.
mqttMQTT Channel BindingProtocol-specific information for an MQTT channel.
mqtt5MQTT 5 Channel BindingProtocol-specific information for an MQTT 5 channel.
natsNATS Channel BindingProtocol-specific information for a NATS channel.
jmsJMS Channel BindingProtocol-specific information for a JMS channel.
snsSNS Channel BindingProtocol-specific information for an SNS channel.
sqsSQS Channel BindingProtocol-specific information for an SQS channel.
stompSTOMP Channel BindingProtocol-specific information for a STOMP channel.
redisRedis Channel BindingProtocol-specific information for a Redis channel.
mercureMercure Channel BindingProtocol-specific information for a Mercure channel.
ibmmqIBM MQ Channel BindingProtocol-specific information for an IBM MQ channel.

This object can be extended with Specification Extensions.

Operation Bindings Object

Map describing protocol-specific definitions for an operation.

Fixed Fields
Field NameTypeDescription
httpHTTP Operation BindingProtocol-specific information for an HTTP operation.
wsWebSockets Operation BindingProtocol-specific information for a WebSockets operation.
kafkaKafka Operation BindingProtocol-specific information for a Kafka operation.
amqpAMQP Operation BindingProtocol-specific information for an AMQP 0-9-1 operation.
amqp1AMQP 1.0 Operation BindingProtocol-specific information for an AMQP 1.0 operation.
mqttMQTT Operation BindingProtocol-specific information for an MQTT operation.
mqtt5MQTT 5 Operation BindingProtocol-specific information for an MQTT 5 operation.
natsNATS Operation BindingProtocol-specific information for a NATS operation.
jmsJMS Operation BindingProtocol-specific information for a JMS operation.
snsSNS Operation BindingProtocol-specific information for an SNS operation.
sqsSQS Operation BindingProtocol-specific information for an SQS operation.
stompSTOMP Operation BindingProtocol-specific information for a STOMP operation.
redisRedis Operation BindingProtocol-specific information for a Redis operation.
mercureMercure Operation BindingProtocol-specific information for a Mercure operation.

This object can be extended with Specification Extensions.

Message Bindings Object

Map describing protocol-specific definitions for a message.

Fixed Fields
Field NameTypeDescription
httpHTTP Message BindingProtocol-specific information for an HTTP message, i.e., a request or a response.
wsWebSockets Message BindingProtocol-specific information for a WebSockets message.
kafkaKafka Message BindingProtocol-specific information for a Kafka message.
amqpAMQP Message BindingProtocol-specific information for an AMQP 0-9-1 message.
amqp1AMQP 1.0 Message BindingProtocol-specific information for an AMQP 1.0 message.
mqttMQTT Message BindingProtocol-specific information for an MQTT message.
mqtt5MQTT 5 Message BindingProtocol-specific information for an MQTT 5 message.
natsNATS Message BindingProtocol-specific information for a NATS message.
jmsJMS Message BindingProtocol-specific information for a JMS message.
snsSNS Message BindingProtocol-specific information for an SNS message.
sqsSQS Message BindingProtocol-specific information for an SQS message.
stompSTOMP Message BindingProtocol-specific information for a STOMP message.
redisRedis Message BindingProtocol-specific information for a Redis message.
mercureMercure Message BindingProtocol-specific information for a Mercure message.
ibmmqIBM MQ Message BindingProtocol-specific information for an IBM MQ message.

This object can be extended with Specification Extensions.

Message Object

Describes a message received on a given channel and operation.

Fixed Fields
Field NameTypeDescription
headersSchema Object | Reference ObjectSchema definition of the application headers. Schema MUST be of type "object". It MUST NOT define the protocol headers.
payloadanyDefinition of the message payload. It can be of any type but defaults to Schema object. It must match the schema format, including encoding type - e.g Avro should be inlined as either a YAML or JSON object NOT a string to be parsed as YAML or JSON.
correlationIdCorrelation ID Object | Reference ObjectDefinition of the correlation ID used for message tracing or matching.
schemaFormatstringA string containing the name of the schema format used to define the message payload. If omitted, implementations should parse the payload as a Schema object. When the payload is defined using a $ref to a remote file, it is RECOMMENDED the schema format includes the file encoding type to allow implementations to parse the file correctly. E.g., adding +yaml if content type is application/vnd.apache.avro results in application/vnd.apache.avro+yaml.

Check out the supported schema formats table for more information. Custom values are allowed but their implementation is OPTIONAL. A custom value MUST NOT refer to one of the schema formats listed in the table.
contentTypestringThe content type to use when encoding/decoding a message's payload. The value MUST be a specific media type (e.g. application/json). When omitted, the value MUST be the one specified on the defaultContentType field.
namestringA machine-friendly name for the message.
titlestringA human-friendly title for the message.
summarystringA short summary of what the message is about.
descriptionstringA verbose explanation of the message. CommonMark syntax can be used for rich text representation.
tagsTags ObjectA list of tags for API documentation control. Tags can be used for logical grouping of messages.
externalDocsExternal Documentation ObjectAdditional external documentation for this message.
bindingsMessage Bindings Object | Reference ObjectA map where the keys describe the name of the protocol and the values describe protocol-specific definitions for the message.
examples[Map[string, any]]An array of key/value pairs where keys MUST be either headers and/or payload. Values MUST contain examples that validate against the headers or payload fields, respectively. Example MAY also have the name and summary additional keys to provide respectively a machine-friendly name and a short summary of what the example is about.
traits[Message Trait Object | Reference Object]A list of traits to apply to the message object. Traits MUST be merged into the message object using the JSON Merge Patch algorithm in the same order they are defined here. The resulting object MUST be a valid Message Object.

This object can be extended with Specification Extensions.

Schema formats table

The following table contains a set of values that every implementation MUST support.

NameAllowed valuesNotes
AsyncAPI 2.1.0 Schema Objectapplication/vnd.aai.asyncapi;version=2.1.0, application/vnd.aai.asyncapi+json;version=2.1.0, application/vnd.aai.asyncapi+yaml;version=2.1.0This is the default when a schemaFormat is not provided.
JSON Schema Draft 07application/schema+json;version=draft-07, application/schema+yaml;version=draft-07

The following table contains a set of values that every implementation is RECOMMENDED to support.

NameAllowed valuesNotes
Avro 1.9.0 schemaapplication/vnd.apache.avro;version=1.9.0, application/vnd.apache.avro+json;version=1.9.0, application/vnd.apache.avro+yaml;version=1.9.0
OpenAPI 3.0.0 Schema Objectapplication/vnd.oai.openapi;version=3.0.0, application/vnd.oai.openapi+json;version=3.0.0, application/vnd.oai.openapi+yaml;version=3.0.0
RAML 1.0 data typeapplication/raml+yaml;version=1.0
Message Object Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{
  "name": "UserSignup",
  "title": "User signup",
  "summary": "Action to sign a user up.",
  "description": "A longer description",
  "contentType": "application/json",
  "tags": [
    { "name": "user" },
    { "name": "signup" },
    { "name": "register" }
  ],
  "headers": {
    "type": "object",
    "properties": {
      "correlationId": {
        "description": "Correlation ID set by application",
        "type": "string"
      },
      "applicationInstanceId": {
        "description": "Unique identifier for a given instance of the publishing application",
        "type": "string"
      }
    }
  },
  "payload": {
    "type": "object",
    "properties": {
      "user": {
        "$ref": "#/components/schemas/userCreate"
      },
      "signup": {
        "$ref": "#/components/schemas/signup"
      }
    }
  },
  "correlationId": {
    "description": "Default Correlation ID",
    "location": "$message.header#/correlationId"
  },
  "traits": [
    { "$ref": "#/components/messageTraits/commonHeaders" }
  ],
  "examples": [
    {
      "name": "SimpleSignup",
      "summary": "A simple UserSignup example message",
      "headers": {
        "correlationId": "my-correlation-id",
        "applicationInstanceId": "myInstanceId"
      },
      "payload": {
        "user": {
          "someUserKey": "someUserValue"
        },
        "signup": {
          "someSignupKey": "someSignupValue"
        }
      }
    }
  ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
name: UserSignup
title: User signup
summary: Action to sign a user up.
description: A longer description
contentType: application/json
tags:
  - name: user
  - name: signup
  - name: register
headers:
  type: object
  properties:
    correlationId:
      description: Correlation ID set by application
      type: string
    applicationInstanceId:
      description: Unique identifier for a given instance of the publishing application
      type: string
payload:
  type: object
  properties:
    user:
      $ref: "#/components/schemas/userCreate"
    signup:
      $ref: "#/components/schemas/signup"
correlationId:
  description: Default Correlation ID
  location: $message.header#/correlationId
traits:
  - $ref: "#/components/messageTraits/commonHeaders"
examples:
  - name: SimpleSignup
    summary: A simple UserSignup example message
    headers:
      correlationId: my-correlation-id
      applicationInstanceId: myInstanceId
    payload:
      user:
        someUserKey: someUserValue
      signup:
        someSignupKey: someSignupValue

Example using Avro to define the payload:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
  "name": "UserSignup",
  "title": "User signup",
  "summary": "Action to sign a user up.",
  "description": "A longer description",
  "tags": [
    { "name": "user" },
    { "name": "signup" },
    { "name": "register" }
  ],
  "schemaFormat": "application/vnd.apache.avro+json;version=1.9.0",
  "payload": {
    "$ref": "path/to/user-create.avsc#/UserCreate"
  }
}
1
2
3
4
5
6
7
8
9
10
11
name: UserSignup
title: User signup
summary: Action to sign a user up.
description: A longer description
tags:
  - name: user
  - name: signup
  - name: register
schemaFormat: 'application/vnd.apache.avro+yaml;version=1.9.0'
payload:
  $ref: 'path/to/user-create.avsc/#UserCreate'

Message Trait Object

Describes a trait that MAY be applied to a Message Object. This object MAY contain any property from the Message Object, except payload and traits.

If you're looking to apply traits to an operation, see the Operation Trait Object.

Fixed Fields
Field NameTypeDescription
headersSchema Object | Reference ObjectSchema definition of the application headers. Schema MUST be of type "object". It MUST NOT define the protocol headers.
correlationIdCorrelation ID Object | Reference ObjectDefinition of the correlation ID used for message tracing or matching.
schemaFormatstringA string containing the name of the schema format/language used to define the message payload. If omitted, implementations should parse the payload as a Schema object.
contentTypestringThe content type to use when encoding/decoding a message's payload. The value MUST be a specific media type (e.g. application/json). When omitted, the value MUST be the one specified on the defaultContentType field.
namestringA machine-friendly name for the message.
titlestringA human-friendly title for the message.
summarystringA short summary of what the message is about.
descriptionstringA verbose explanation of the message. CommonMark syntax can be used for rich text representation.
tagsTags ObjectA list of tags for API documentation control. Tags can be used for logical grouping of messages.
externalDocsExternal Documentation ObjectAdditional external documentation for this message.
bindingsMessage Bindings Object | Reference ObjectA map where the keys describe the name of the protocol and the values describe protocol-specific definitions for the message.
examples[Map[string, any]]An array with examples of valid message objects.

This object can be extended with Specification Extensions.

Message Trait Object Example
1
2
3
4
{
  "schemaFormat": "application/vnd.apache.avro+json;version=1.9.0",
  "contentType": "application/json"
}
1
2
schemaFormat: 'application/vnd.apache.avro+yaml;version=1.9.0'
contentType: application/json

Tags Object

A Tags object is a list of Tag Objects.

Tag Object

Allows adding meta data to a single tag.

Fixed Fields
Field NameTypeDescription
namestringRequired. The name of the tag.
descriptionstringA short description for the tag. CommonMark syntax can be used for rich text representation.
externalDocsExternal Documentation ObjectAdditional external documentation for this tag.

This object can be extended with Specification Extensions.

Tag Object Example
1
2
3
4
{
    "name": "user",
    "description": "User-related messages"
}
1
2
name: user
description: User-related messages

External Documentation Object

Allows referencing an external resource for extended documentation.

Fixed Fields
Field NameTypeDescription
descriptionstringA short description of the target documentation. CommonMark syntax can be used for rich text representation.
urlstringRequired. The URL for the target documentation. Value MUST be in the format of a URL.

This object can be extended with Specification Extensions.

External Documentation Object Example
1
2
3
4
{
  "description": "Find more info here",
  "url": "https://example.com"
}
1
2
description: Find more info here
url: https://example.com

Reference Object

A simple object to allow referencing other components in the specification, internally and externally.

The Reference Object is defined by JSON Reference and follows the same structure, behavior and rules. A JSON Reference SHALL only be used to refer to a schema that is formatted in either JSON or YAML. In the case of a YAML-formatted Schema, the JSON Reference SHALL be applied to the JSON representation of that schema. The JSON representation SHALL be made by applying the conversion described here.

For this specification, reference resolution is done as defined by the JSON Reference specification and not by the JSON Schema specification.

Fixed Fields
Field NameTypeDescription
$refstringRequired. The reference string.

This object cannot be extended with additional properties and any properties added SHALL be ignored.

Reference Object Example
1
2
3
{
  "$ref": "#/components/schemas/Pet"
}
  $ref: '#/components/schemas/Pet'

Components Object

Holds a set of reusable objects for different aspects of the AsyncAPI specification. All objects defined within the components object will have no effect on the API unless they are explicitly referenced from properties outside the components object.

Fixed Fields
Field NameTypeDescription
schemasMap[string, Schema Object | Reference Object]An object to hold reusable Schema Objects.
messagesMap[string, Message Object | Reference Object]An object to hold reusable Message Objects.
securitySchemesMap[string, Security Scheme Object | Reference Object]An object to hold reusable Security Scheme Objects.
parametersMap[string, Parameter Object | Reference Object]An object to hold reusable Parameter Objects.
correlationIdsMap[string, Correlation ID Object | Reference Object]An object to hold reusable Correlation ID Objects.
operationTraitsMap[string, Operation Trait Object | Reference Object]An object to hold reusable Operation Trait Objects.
messageTraitsMap[string, Message Trait Object | Reference Object]An object to hold reusable Message Trait Objects.
serverBindingsMap[string, Server Bindings Object | Reference Object]An object to hold reusable Server Bindings Objects.
channelBindingsMap[string, Channel Bindings Object | Reference Object]An object to hold reusable Channel Bindings Objects.
operationBindingsMap[string, Operation Bindings Object | Reference Object]An object to hold reusable Operation Bindings Objects.
messageBindingsMap[string, Message Bindings Object | Reference Object]An object to hold reusable Message Bindings Objects.

This object can be extended with Specification Extensions.

All the fixed fields declared above are objects that MUST use keys that match the regular expression: ^[a-zA-Z0-9\.\-_]+$.

Field Name Examples:

1
2
3
4
5
User
User_1
User_Name
user-name
my.org.User
Components Object Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{
  "components": {
    "schemas": {
      "Category": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "name": {
            "type": "string"
          }
        }
      },
      "Tag": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "messages": {
      "userSignUp": {
        "summary": "Action to sign a user up.",
        "description": "Multiline description of what this action does.\nHere you have another line.\n",
        "tags": [
          {
            "name": "user"
          },
          {
            "name": "signup"
          }
        ],
        "headers": {
          "type": "object",
          "properties": {
            "applicationInstanceId": {
              "description": "Unique identifier for a given instance of the publishing application",
              "type": "string"
            }
          }
        },
        "payload": {
          "type": "object",
          "properties": {
            "user": {
              "$ref": "#/components/schemas/userCreate"
            },
            "signup": {
              "$ref": "#/components/schemas/signup"
            }
          }
        }
      }
    },
    "parameters": {
      "userId": {
        "description": "Id of the user.",
        "schema": {
          "type": "string"
        }
      }
    },
    "correlationIds": {
      "default": {
        "description": "Default Correlation ID",
        "location": "$message.header#/correlationId"
      }
    },
    "messageTraits": {
      "commonHeaders": {
        "headers": {
          "type": "object",
          "properties": {
            "my-app-header": {
              "type": "integer",
              "minimum": 0,
              "maximum": 100
            }
          }
        }
      }
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
components:
  schemas:
    Category:
      type: object
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
    Tag:
      type: object
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
  messages:
    userSignUp:
      summary: Action to sign a user up.
      description: |
        Multiline description of what this action does.
        Here you have another line.
      tags:
        - name: user
        - name: signup
      headers:
        type: object
        properties:
          applicationInstanceId:
            description: Unique identifier for a given instance of the publishing application
            type: string
      payload:
        type: object
        properties:
          user:
            $ref: "#/components/schemas/userCreate"
          signup:
            $ref: "#/components/schemas/signup"
  parameters:
    userId:
      description: Id of the user.
      schema:
        type: string
  correlationIds:
    default:
      description: Default Correlation ID
      location: $message.header#/correlationId
  messageTraits:
    commonHeaders:
      headers:
        type: object
        properties:
          my-app-header:
            type: integer
            minimum: 0
            maximum: 100

Schema Object

The Schema Object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. This object is a superset of the JSON Schema Specification Draft 07. The empty schema (which allows any instance to validate) MAY be represented by the boolean value true and a schema which allows no instance to validate MAY be represented by the boolean value false.

Further information about the properties can be found in JSON Schema Core and JSON Schema Validation. Unless stated otherwise, the property definitions follow the JSON Schema specification as referenced here.

Properties

The AsyncAPI Schema Object is a JSON Schema vocabulary which extends JSON Schema Core and Validation vocabularies. As such, any keyword available for those vocabularies is by definition available in AsyncAPI, and will work the exact same way, including but not limited to:

  • title
  • type
  • required
  • multipleOf
  • maximum
  • exclusiveMaximum
  • minimum
  • exclusiveMinimum
  • maxLength
  • minLength
  • pattern (This string SHOULD be a valid regular expression, according to the ECMA 262 regular expression dialect)
  • maxItems
  • minItems
  • uniqueItems
  • maxProperties
  • minProperties
  • enum
  • const
  • examples
  • if / then / else
  • readOnly
  • writeOnly
  • properties
  • patternProperties
  • additionalProperties
  • additionalItems
  • items
  • propertyNames
  • contains
  • allOf
  • oneOf
  • anyOf
  • not

The following properties are taken from the JSON Schema definition but their definitions were adjusted to the AsyncAPI Specification.

  • description - CommonMark syntax can be used for rich text representation.
  • format - See Data Type Formats for further details. While relying on JSON Schema's defined formats, the AsyncAPI Specification offers a few additional predefined formats.
  • default - The default value represents what would be assumed by the consumer of the input as the value of the schema if one is not provided. Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object defined at the same level. For example, of type is string, then default can be "foo" but cannot be 1.

Alternatively, any time a Schema Object can be used, a Reference Object can be used in its place. This allows referencing definitions in place of defining them inline.

In addition to the JSON Schema fields, the following AsyncAPI vocabulary fields MAY be used for further schema documentation:

Fixed Fields
Field NameTypeDescription
discriminatorstringAdds support for polymorphism. The discriminator is the schema property name that is used to differentiate between other schema that inherit this schema. The property name used MUST be defined at this schema and it MUST be in the required property list. When used, the value MUST be the name of this schema or any schema that inherits it. See Composition and Inheritance for more details.
externalDocsExternal Documentation ObjectAdditional external documentation for this schema.
deprecatedbooleanSpecifies that a schema is deprecated and SHOULD be transitioned out of usage. Default value is false.

This object can be extended with Specification Extensions.

Composition and Inheritance (Polymorphism)

The AsyncAPI Specification allows combining and extending model definitions using the allOf property of JSON Schema, in effect offering model composition. allOf takes in an array of object definitions that are validated independently but together compose a single object.

While composition offers model extensibility, it does not imply a hierarchy between the models. To support polymorphism, AsyncAPI Specification adds the support of the discriminator field. When used, the discriminator will be the name of the property used to decide which schema definition is used to validate the structure of the model. As such, the discriminator field MUST be a required field. There are are two ways to define the value of a discriminator for an inheriting instance.

  • Use the schema's name.
  • Override the schema's name by overriding the property with a new value. If exists, this takes precedence over the schema's name.

As such, inline schema definitions, which do not have a given id, cannot be used in polymorphism.

Schema Object Examples
Primitive Sample
1
2
3
4
{
  "type": "string",
  "format": "email"
}
1
2
type: string
format: email
Simple Model
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
  "type": "object",
  "required": [
    "name"
  ],
  "properties": {
    "name": {
      "type": "string"
    },
    "address": {
      "$ref": "#/components/schemas/Address"
    },
    "age": {
      "type": "integer",
      "format": "int32",
      "minimum": 0
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
type: object
required:
- name
properties:
  name:
    type: string
  address:
    $ref: '#/components/schemas/Address'
  age:
    type: integer
    format: int32
    minimum: 0
Model with Map/Dictionary Properties

For a simple string to string mapping:

1
2
3
4
5
6
{
  "type": "object",
  "additionalProperties": {
    "type": "string"
  }
}
1
2
3
type: object
additionalProperties:
  type: string

For a string to model mapping:

1
2
3
4
5
6
{
  "type": "object",
  "additionalProperties": {
    "$ref": "#/components/schemas/ComplexModel"
  }
}
1
2
3
type: object
additionalProperties:
  $ref: '#/components/schemas/ComplexModel'
Model with Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
  "type": "object",
  "properties": {
    "id": {
      "type": "integer",
      "format": "int64"
    },
    "name": {
      "type": "string"
    }
  },
  "required": [
    "name"
  ],
  "example": {
    "name": "Puma",
    "id": 1
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
type: object
properties:
  id:
    type: integer
    format: int64
  name:
    type: string
required:
- name
example:
  name: Puma
  id: 1
Model with Boolean Schemas
1
2
3
4
5
6
7
8
9
10
{
  "type": "object",
  "required": [
    "anySchema"
  ],
  "properties": {
    "anySchema": true,
    "cannotBeDefined": false
  }
}
1
2
3
4
5
6
type: object
required:
- anySchema
properties:
  anySchema: true
  cannotBeDefined: false
Models with Composition
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{
  "schemas": {
    "ErrorModel": {
      "type": "object",
      "required": [
        "message",
        "code"
      ],
      "properties": {
        "message": {
          "type": "string"
        },
        "code": {
          "type": "integer",
          "minimum": 100,
          "maximum": 600
        }
      }
    },
    "ExtendedErrorModel": {
      "allOf": [
        {
          "$ref": "#/components/schemas/ErrorModel"
        },
        {
          "type": "object",
          "required": [
            "rootCause"
          ],
          "properties": {
            "rootCause": {
              "type": "string"
            }
          }
        }
      ]
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
schemas:
  ErrorModel:
    type: object
    required:
    - message
    - code
    properties:
      message:
        type: string
      code:
        type: integer
        minimum: 100
        maximum: 600
  ExtendedErrorModel:
    allOf:
    - $ref: '#/components/schemas/ErrorModel'
    - type: object
      required:
      - rootCause
      properties:
        rootCause:
          type: string
Models with Polymorphism Support
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{
  "schemas": {
    "Pet": {
      "type": "object",
      "discriminator": "petType",
      "properties": {
        "name": {
          "type": "string"
        },
        "petType": {
          "type": "string"
        }
      },
      "required": [
        "name",
        "petType"
      ]
    },
    "Cat": {
      "description": "A representation of a cat. Note that `Cat` will be used as the discriminator value.",
      "allOf": [
        {
          "$ref": "#/components/schemas/Pet"
        },
        {
          "type": "object",
          "properties": {
            "huntingSkill": {
              "type": "string",
              "description": "The measured skill for hunting",
              "enum": [
                "clueless",
                "lazy",
                "adventurous",
                "aggressive"
              ]
            }
          },
          "required": [
            "huntingSkill"
          ]
        }
      ]
    },
    "Dog": {
      "description": "A representation of a dog. Note that `Dog` will be used as the discriminator value.",
      "allOf": [
        {
          "$ref": "#/components/schemas/Pet"
        },
        {
          "type": "object",
          "properties": {
            "packSize": {
              "type": "integer",
              "format": "int32",
              "description": "the size of the pack the dog is from",
              "minimum": 0
            }
          },
          "required": [
            "packSize"
          ]
        }
      ]
    },
    "StickInsect": {
      "description": "A representation of an Australian walking stick. Note that `StickBug` will be used as the discriminator value.",
      "allOf": [
        {
          "$ref": "#/components/schemas/Pet"
        },
        {
          "type": "object",
          "properties": {
            "petType": {
              "const": "StickBug"
            },
            "color": {
              "type": "string"
            }
          },
          "required": [
            "color"
          ]
        }
      ]
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
schemas:
  Pet:
    type: object
    discriminator: petType
    properties:
      name:
        type: string
      petType:
        type: string
    required:
    - name
    - petType
  ## applies to instances with `petType: "Cat"`
  ## because that is the schema name
  Cat:
    description: A representation of a cat
    allOf:
    - $ref: '#/components/schemas/Pet'
    - type: object
      properties:
        huntingSkill:
          type: string
          description: The measured skill for hunting
          enum:
          - clueless
          - lazy
          - adventurous
          - aggressive
      required:
      - huntingSkill
  ## applies to instances with `petType: "Dog"`
  ## because that is the schema name
  Dog:
    description: A representation of a dog
    allOf:
    - $ref: '#/components/schemas/Pet'
    - type: object
      properties:
        packSize:
          type: integer
          format: int32
          description: the size of the pack the dog is from
          minimum: 0
      required:
      - packSize
  ## applies to instances with `petType: "StickBug"`
  ## because that is the required value of the discriminator field,
  ## overriding the schema name
  StickInsect:
    description: A representation of an Australian walking stick
    allOf:
    - $ref: '#/components/schemas/Pet'
    - type: object
      properties:
        petType:
          const: StickBug
        color:
          type: string
      required:
      - color

Security Scheme Object

Defines a security scheme that can be used by the operations. Supported schemes are:

  • User/Password.
  • API key (either as user or as password).
  • X.509 certificate.
  • End-to-end encryption (either symmetric or asymmetric).
  • HTTP authentication.
  • HTTP API key.
  • OAuth2's common flows (Implicit, Resource Owner Protected Credentials, Client Credentials and Authorization Code) as defined in RFC6749.
  • OpenID Connect Discovery.
  • SASL (Simple Authentication and Security Layer) as defined in RFC4422.
Fixed Fields
Field NameTypeApplies ToDescription
typestringAnyREQUIRED. The type of the security scheme. Valid values are "userPassword", "apiKey", "X509", "symmetricEncryption", "asymmetricEncryption", "httpApiKey", "http", "oauth2", "openIdConnect", "plain", "scramSha256", "scramSha512", and "gssapi".
descriptionstringAnyA short description for security scheme. CommonMark syntax MAY be used for rich text representation.
namestringhttpApiKeyREQUIRED. The name of the header, query or cookie parameter to be used.
instringapiKey | httpApiKeyREQUIRED. The location of the API key. Valid values are "user" and "password" for apiKey and "query", "header" or "cookie" for httpApiKey.
schemestringhttpREQUIRED. The name of the HTTP Authorization scheme to be used in the Authorization header as defined in RFC7235.
bearerFormatstringhttp ("bearer")A hint to the client to identify how the bearer token is formatted. Bearer tokens are usually generated by an authorization server, so this information is primarily for documentation purposes.
flowsOAuth Flows Objectoauth2REQUIRED. An object containing configuration information for the flow types supported.
openIdConnectUrlstringopenIdConnectREQUIRED. OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the form of a URL.

This object MAY be extended with Specification Extensions.

Security Scheme Object Example
User/Password Authentication Sample
1
2
3
{
  "type": "userPassword"
}
type: userPassword
API Key Authentication Sample
1
2
3
4
{
  "type": "apiKey",
  "in": "user"
}
1
2
type: apiKey,
in: user
X.509 Authentication Sample
1
2
3
{
  "type": "X509"
}
type: X509
End-to-end Encryption Authentication Sample
1
2
3
{
  "type": "symmetricEncryption"
}
type: symmetricEncryption
Basic Authentication Sample
1
2
3
4
{
  "type": "http",
  "scheme": "basic"
}
1
2
type: http
scheme: basic
API Key Sample
1
2
3
4
5
{
  "type": "httpApiKey",
  "name": "api_key",
  "in": "header"
}
1
2
3
type: httpApiKey
name: api_key
in: header
JWT Bearer Sample
1
2
3
4
5
{
  "type": "http",
  "scheme": "bearer",
  "bearerFormat": "JWT"
}
1
2
3
type: http
scheme: bearer
bearerFormat: JWT
Implicit OAuth2 Sample
1
2
3
4
5
6
7
8
9
10
11
12
{
  "type": "oauth2",
  "flows": {
    "implicit": {
      "authorizationUrl": "https://example.com/api/oauth/dialog",
      "scopes": {
        "write:pets": "modify pets in your account",
        "read:pets": "read your pets"
      }
    }
  }
}
1
2
3
4
5
6
7
type: oauth2
flows:
  implicit:
    authorizationUrl: https://example.com/api/oauth/dialog
    scopes:
      write:pets: modify pets in your account
      read:pets: read your pets
SASL Sample
1
2
3
{
  "type": "scramSha512"
}
type: scramSha512

OAuth Flows Object

Allows configuration of the supported OAuth Flows.

Fixed Fields
Field NameTypeDescription
implicitOAuth Flow ObjectConfiguration for the OAuth Implicit flow
passwordOAuth Flow ObjectConfiguration for the OAuth Resource Owner Protected Credentials flow
clientCredentialsOAuth Flow ObjectConfiguration for the OAuth Client Credentials flow.
authorizationCodeOAuth Flow ObjectConfiguration for the OAuth Authorization Code flow.

This object MAY be extended with Specification Extensions.

OAuth Flow Object

Configuration details for a supported OAuth Flow

Fixed Fields
Field NameTypeApplies ToDescription
authorizationUrlstringoauth2 ("implicit", "authorizationCode")REQUIRED. The authorization URL to be used for this flow. This MUST be in the form of a URL.
tokenUrlstringoauth2 ("password", "clientCredentials", "authorizationCode")REQUIRED. The token URL to be used for this flow. This MUST be in the form of a URL.
refreshUrlstringoauth2The URL to be used for obtaining refresh tokens. This MUST be in the form of a URL.
scopesMap[string, string]oauth2REQUIRED. The available scopes for the OAuth2 security scheme. A map between the scope name and a short description for it.

This object MAY be extended with Specification Extensions.

OAuth Flow Object Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
  "type": "oauth2",
  "flows": {
    "implicit": {
      "authorizationUrl": "https://example.com/api/oauth/dialog",
      "scopes": {
        "write:pets": "modify pets in your account",
        "read:pets": "read your pets"
      }
    },
    "authorizationCode": {
      "authorizationUrl": "https://example.com/api/oauth/dialog",
      "tokenUrl": "https://example.com/api/oauth/token",
      "scopes": {
        "write:pets": "modify pets in your account",
        "read:pets": "read your pets"
      }
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
type: oauth2
flows:
  implicit:
    authorizationUrl: https://example.com/api/oauth/dialog
    scopes:
      write:pets: modify pets in your account
      read:pets: read your pets
  authorizationCode:
    authorizationUrl: https://example.com/api/oauth/dialog
    tokenUrl: https://example.com/api/oauth/token
    scopes:
      write:pets: modify pets in your account
      read:pets: read your pets

Security Requirement Object

Lists the required security schemes to execute this operation. The name used for each property MUST correspond to a security scheme declared in the Security Schemes under the Components Object.

When a list of Security Requirement Objects is defined on a Server object, only one of the Security Requirement Objects in the list needs to be satisfied to authorize the connection.

Patterned Fields
Field PatternTypeDescription
{name}[string]Each name MUST correspond to a security scheme which is declared in the Security Schemes under the Components Object. If the security scheme is of type "oauth2" or "openIdConnect", then the value is a list of scope names. Provide scopes that are required to establish successful connection with the server. If scopes are not needed, the list can be empty. For other security scheme types, the array MUST be empty.
Security Requirement Object Examples
User/Password Security Requirement
1
2
3
{
  "user_pass": []
}
user_pass: []
API Key Security Requirement
1
2
3
{
  "api_key": []
}
api_key: []
OAuth2 Security Requirement
1
2
3
4
5
6
{
  "petstore_auth": [
    "write:pets",
    "read:pets"
  ]
}
1
2
3
petstore_auth:
- write:pets
- read:pets

Correlation ID Object

An object that specifies an identifier at design time that can used for message tracing and correlation.

For specifying and computing the location of a Correlation ID, a runtime expression is used.

Fixed Fields
Field NameTypeDescription
descriptionstringAn optional description of the identifier. CommonMark syntax can be used for rich text representation.
locationstringREQUIRED. A runtime expression that specifies the location of the correlation ID.

This object can be extended with Specification Extensions.

Examples
1
2
3
4
{
  "description": "Default Correlation ID",
  "location": "$message.header#/correlationId"
}
1
2
description: Default Correlation ID
location: $message.header#/correlationId

Runtime Expression

A runtime expression allows values to be defined based on information that will be available within the message. This mechanism is used by Correlation ID Object.

The runtime expression is defined by the following ABNF syntax:

1
2
3
4
5
      expression = ( "$message" "." source )
      source = ( header-reference | payload-reference )
      header-reference = "header" ["#" fragment]
      payload-reference = "payload" ["#" fragment]
      fragment = a JSON Pointer [RFC 6901](https://tools.ietf.org/html/rfc6901)

The table below provides examples of runtime expressions and examples of their use in a value:

Examples
Source LocationExample expressionNotes
Message Header Property$message.header#/MQMD/CorrelIdCorrelation ID is set using the CorrelId value from the MQMD header.
Message Payload Property$message.payload#/messageIdCorrelation ID is set using the messageId value from the message payload.

Runtime expressions preserve the type of the referenced value.

Specification Extensions

While the AsyncAPI Specification tries to accommodate most use cases, additional data can be added to extend the specification at certain points.

The extensions properties are implemented as patterned fields that are always prefixed by "x-".

Field PatternTypeDescription
^x-[\w\d\-\_]+$AnyAllows extensions to the AsyncAPI Schema. The field name MUST begin with x-, for example, x-internal-id. The value can be null, a primitive, an array or an object. Can have any valid JSON format value.

The extensions may or may not be supported by the available tooling, but those may be extended as well to add requested support (if tools are internal or open-sourced).

Data Type Formats

Primitives have an optional modifier property: format. The AsyncAPI specification uses several known formats to more finely define the data type being used. However, the format property is an open string-valued property, and can have any value to support documentation needs. Formats such as "email", "uuid", etc., can be used even though they are not defined by this specification. Types that are not accompanied by a format property follow their definition from the JSON Schema. Tools that do not recognize a specific format MAY default back to the type alone, as if the format was not specified.

The formats defined by the AsyncAPI Specification are:

Common NametypeformatComments
integerintegerint32signed 32 bits
longintegerint64signed 64 bits
floatnumberfloat
doublenumberdouble
stringstring
bytestringbytebase64 encoded characters
binarystringbinaryany sequence of octets
booleanboolean
datestringdateAs defined by full-date - RFC3339
dateTimestringdate-timeAs defined by date-time - RFC3339
passwordstringpasswordUsed to hint UIs the input needs to be obscured.