1 user/signedup:
2 subscribe:
3 $ref: "#/components/messages/userSignUp"user/signedup 频道。1 {
2 "field" : [...]
3 }$ref中的规范中的字段。asyncapi.json或asyncapi.yaml.| 字段名称 | 类型 | 描述 |
|---|---|---|
| asyncapi | AsyncAPI Version String | 必需的。 指定正在使用的 AsyncAPI 规范版本。工具规范和客户端 可以使用它来解释版本。结构应为major. minor. patch,其中patch版本必须与现有的 兼容major。minor工装。通常会引入补丁版本来解决文档中的错误,并且工具通常应该与相应的major. minor(1.0.*)。补丁版本将对应本文档的补丁。 |
| id | Identifier | AsyncAPI 文档正在定义的应用程序的标识符。 |
| info | Info Object | 必需的。提供有关 API 的元数据。如果需要 ,客户端可以使用元数据。 |
| servers | Servers Object | 提供服务器的连接详细信息。 |
| channels | Channels Object | 必需 API 的可用通道和消息。 |
| components | Components Object | 用于保存规范的各种模式的元素。 |
| tags | Tags Object | 规范使用的带有附加元数据的标签列表。列表中的每个标签名称必须是唯一的。 |
| externalDocs | External Documentation Object | 额外的外部文档。 |
major. minor. patch. patch 可以用连字符和额外的字母数字字符作为后缀。major。minor应用于指定 AsyncAPI 规范版本,并将被视为与该 指定的 AsyncAPI 规范兼容major。minor版本。补丁版本不会被工具考虑,不区分1.0.0和1.0.1。minor不应干扰为较低次要版本开发的工具的操作。因此,假设的1.1.0规范应该可用于为 . 设计的工具1.0.0。
1 {
2 "id": "urn:com:smartylighting:streetlights:server"
3 }id: 'urn:com:smartylighting:streetlights:server'
1 {
2 "id": "https://github.com/smartylighting/streetlights-server"
3 }id: 'https://github.com/smartylighting/streetlights-server'| 字段名称 | 类型 | 描述 |
|---|---|---|
| title | string | 必须的。应用程序的标题。 |
| version | string | 必需提供应用程序 API 的版本(不要与规范版本混淆)。 |
| description | string | 应用程序的简短描述。CommonMark 语法可用于富文本表示。 |
| termsOfService | string | API 服务条款的 URL。必须采用 URL 格式。 |
| contact | Contact Object | 公开的 API 的联系信息。 |
| license | License Object | 公开的 API 的 许可证信息。 |
1 {
2 "title": "AsyncAPI Sample App",
3 "description": "This is a sample server.",
4 "termsOfService": "http://asyncapi.org/terms/",
5 "contact": {
6 "name": "API Support",
7 "url": "http://www.asyncapi.org/support",
8 "email": "support@asyncapi.org"
9 },
10 "license": {
11 "name": "Apache 2.0",
12 "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
13 },
14 "version": "1.0.1"
15 }
1 title: AsyncAPI Sample App
2 description: This is a sample server.
3 termsOfService: http://asyncapi.org/terms/
4 contact:
5 name: API Support
6 url: http://www.asyncapi.org/support
7 email: support@asyncapi.org
8 license:
9 name: Apache 2.0
10 url: http://www.apache.org/licenses/LICENSE-2.0.html
11 version: 1.0.1| 字段名称 | 类型 | 描述 |
|---|---|---|
| name | string | 联系人/组织的识别名称。 |
| url | string | 指向联系信息的 URL。必须采用 URL 格式。 |
string | 联系人/组织的电子邮件地址。必须采用电子邮件地址的格式。 |
1 {
2 "name": "API Support",
3 "url": "http://www.example.com/support",
4 "email": "support@example.com"
5 }
1 name: API Support
2 url: http://www.example.com/support
3 email: support@example.com| 字段名称 | 类型 | 描述 |
|---|---|---|
| name | string | 必需的。用于 API 的许可证名称。 |
| url | string | 用于 API 的许可证的 URL。必须采用 URL 格式。 |
1 {
2 "name": "Apache 2.0",
3 "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
4 }
1 name: Apache 2.0
2 url: http://www.apache.org/licenses/LICENSE-2.0.html| 字段模式 | 类型 | 描述 |
|---|---|---|
^[A-Za-z0-9_-]+$ | Server Object | 这个应用程序可以连接到的服务器的定义。 |
1 {
2 "production": {
3 "url": "development.gigantic-server.com",
4 "description": "Development server",
5 "protocol": "kafka",
6 "protocolVersion": "1.0.0"
7 }
8 }
1 production:
2 url: development.gigantic-server.com
3 description: Development server
4 protocol: kafka
5 protocolVersion: '1.0.0'| 字段名称 | 类型 | 描述 |
|---|---|---|
| url | string | 必需的。目标主机的 URL。此 URL 支持服务器变量并且可以是相对的,以指示主机位置是相对于提供 AsyncAPI 文档的位置。{当在括号中命名变量时,将进行变量替换}。 |
| protocol | string | 必需的。此 URL 支持的连接协议。支持的协议包括但不限于:amqp amqps http https jms kafka kafka-secure mqtt secure-mqtt stomp stomps ws wss |
| protocolVersion | string | 用于连接的协议版本。例如: AMQP 0.9.1、 HTTP 2.0、 Kafka1.0.0等。 |
| description | string | 可选字符串,描述 URL 指定的主机。CommonMark 语法可以用于富文本表示。 |
| variables | Map[string, Server Variable Object] | 变量名称与其值之间的映射。该值用于替换服务器的 URL 模板。 |
| security | [Security Requirement Object] | 该服务器可以使用哪些安全机制的声明。值列表包括可以使用的替代安全要求对象。只需满足其中一个安全要求对象即可授权连接或操作。 |
| bindings | Server Bindings Object | 一个自由格式的映射,其中键描述协议的名称,值描述服务器的协议特定定义。 |
1 {
2 "url": "development.gigantic-server.com",
3 "description": "Development server",
4 "protocol": "kafka",
5 "protocolVersion": "1.0.0"
6 }
1 url: development.gigantic-server.com
2 description: Development server
3 protocol: kafka
4 protocolVersion: '1.0.0'servers:
1 {
2 "servers": {
3 "development": {
4 "url": "development.gigantic-server.com",
5 "description": "Development server",
6 "protocol": "amqp",
7 "protocolVersion": "0.9.1"
8 },
9 "staging": {
10 "url": "staging.gigantic-server.com",
11 "description": "Staging server",
12 "protocol": "amqp",
13 "protocolVersion": "0.9.1"
14 },
15 "production": {
16 "url": "api.gigantic-server.com",
17 "description": "Production server",
18 "protocol": "amqp",
19 "protocolVersion": "0.9.1"
20 }
21 }
22 }
1 servers:
2 development:
3 url: development.gigantic-server.com
4 description: Development server
5 protocol: amqp
6 protocolVersion: 0.9.1
7 staging:
8 url: staging.gigantic-server.com
9 description: Staging server
10 protocol: amqp
11 protocolVersion: 0.9.1
12 production:
13 url: api.gigantic-server.com
14 description: Production server
15 protocol: amqp
16 protocolVersion: 0.9.1
1 {
2 "servers": [
3 {
4 "url": "{username}.gigantic-server.com:{port}/{basePath}",
5 "description": "The production API server",
6 "protocol": "secure-mqtt",
7 "variables": {
8 "username": {
9 "default": "demo",
10 "description": "This value is assigned by the service provider, in this example `gigantic-server.com`"
11 },
12 "port": {
13 "enum": [
14 "8883",
15 "8884"
16 ],
17 "default": "8883"
18 },
19 "basePath": {
20 "default": "v2"
21 }
22 }
23 }
24 ]
25 }
1 servers:
2 - url: '{username}.gigantic-server.com:{port}/{basePath}'
3 description: The production API server
4 protocol: secure-mqtt
5 variables:
6 username:
7 # note! no enum here means it is an open value
8 default: demo
9 description: This value is assigned by the service provider, in this example `gigantic-server.com`
10 port:
11 enum:
12 - '8883'
13 - '8884'
14 default: '8883'
15 basePath:
16 # open meaning there is the opportunity to use special base paths as assigned by the provider, default is `v2`
17 default: v2| 字段名称 | 类型 | 描述 |
|---|---|---|
| enum | [string] | 如果替换选项来自有限集合,则要使用的字符串值的枚举。 |
| default | string | 如果未提供替代值,则用于替换和发送的默认值。 |
| description | string | 服务器变量的可选描述。CommonMark 语法可以用于富文本表示。 |
| examples | [string] | 服务器变量的示例数组。 |
application/json)。当省略 contentType 属性时,模式解析器必须使用此值。
1 {
2 "defaultContentType": "application/json"
3 }defaultContentType: application/json| 字段模式 | 类型 | 描述 |
|---|---|---|
| {channel} | Channel Item Object | 单个通道的相对路径。字段名称必须采用RFC 6570 URI 模板的形式。不得使用查询参数和片段,而是使用绑定来定义它们。 |
1 {
2 "user/signedup": {
3 "subscribe": {
4 "$ref": "#/components/messages/userSignedUp"
5 }
6 }
7 }
1 user/signedup:
2 subscribe:
3 $ref: "#/components/messages/userSignedUp"| 字段名称 | 类型 | 描述 |
|---|---|---|
| $ref | string | 允许对此频道项进行外部定义。引用的结构必须采用 Channel Item Object 的格式。如果引用的定义与此频道项的定义之间存在冲突,则行为为undefined。 |
| description | string | 此频道项目的可选描述。CommonMark 语法 可用于富文本表示。 |
| subscribe | Operation Object | SUBSCRIBE 操作的定义。 |
| publish | Operation Object | 发布操作的定义。 |
| parameters | Parameters Object | 通道名称中包含的参数映射。它应该仅在使用带有表达式的通道时出现(如 RFC 6570 第 2.2 节 所定义)。 |
| bindings | Channel Bindings Object | 一个自由格式的映射,其中键描述协议的名称,值描述通道的协议特定定义。 |
1 {
2 "description": "This channel is used to exchange messages about users signing up",
3 "subscribe": {
4 "summary": "A user signed up.",
5 "message": {
6 "description": "A longer description of the message",
7 "payload": {
8 "type": "object",
9 "properties": {
10 "user": {
11 "$ref": "#/components/schemas/user"
12 },
13 "signup": {
14 "$ref": "#/components/schemas/signup"
15 }
16 }
17 }
18 }
19 },
20 "bindings": {
21 "amqp": {
22 "is": "queue",
23 "queue": {
24 "exclusive": true
25 }
26 }
27 }
28 }
1 description: This channel is used to exchange messages about users signing up
2 subscribe:
3 summary: A user signed up.
4 message:
5 description: A longer description of the message
6 payload:
7 type: object
8 properties:
9 user:
10 $ref: "#/components/schemas/user"
11 signup:
12 bindings:
13 amqp:
14 is: queue
15 queue:
16 exclusive: trueoneOf为每个操作指定多条消息:
1 {
2 "subscribe": {
3 "message": {
4 "oneOf": [
5 { "$ref": "#/components/messages/signup" },
6 { "$ref": "#/components/messages/login" }
7 ]
8 }
9 }
10 }
1 subscribe:
2 message:
3 oneOf:
4 - $ref: '#/components/messages/signup'
5 - $ref: '#/components/messages/login'| 字段名称 | 类型 | 描述 |
|---|---|---|
| operationId | string | 用于标识操作的唯一字符串。在 API 中描述的所有操作中,id 必须是唯一的。operationId 值区分大小写。工具和库可以使用 operationId 来唯一标识一个操作,因此,建议遵循通用的编程命名约定。 |
| summary | string | 操作内容的简短摘要。 |
| description | string | 对操作的详细解释。CommonMark 语法可用于富文本表示。 |
| tags | [Tag Object] | API 文档控制的标签列表。标签可用于操作的逻辑分组。 |
| externalDocs | External Documentation Object | 此操作的附加外部文档。 |
| bindings | Map[string, Operation Bindings Object] | 一个自由格式的映射,其中键描述协议的名称,值描述操作的协议特定定义。 |
| traits | [Operation Trait Object] | 应用于操作对象的特征列表。特征必须按照此处定义的相同顺序使用JSON 合并补丁算法合并到操作对象中。 |
| message | Message Object | 将在此频道上发布或接收的消息的定义。oneOf此处允许指定多个消息,但是,消息必须仅对引用的消息对象之一有效。 |
1 {
2 "operationId": "registerUser",
3 "summary": "Action to sign a user up.",
4 "description": "A longer description",
5 "tags": [
6 { "name": "user" },
7 { "name": "signup" },
8 { "name": "register" }
9 ],
10 "message": {
11 "headers": {
12 "type": "object",
13 "properties": {
14 "applicationInstanceId": {
15 "description": "Unique identifier for a given instance of the publishing application",
16 "type": "string"
17 }
18 }
19 },
20 "payload": {
21 "type": "object",
22 "properties": {
23 "user": {
24 "$ref": "#/components/schemas/userCreate"
25 },
26 "signup": {
27 "$ref": "#/components/schemas/signup"
28 }
29 }
30 }
31 },
32 "bindings": {
33 "amqp": {
34 "ack": false
35 },
36 },
37 "traits": [
38 { "$ref": "#/components/operationTraits/kafka" }
39 ]
40 }
1 operationId: registerUser
2 summary: Action to sign a user up.
3 description: A longer description
4 tags:
5 - name: user
6 - name: signup
7 - name: register
8 message:
9 headers:
10 type: object
11 properties:
12 applicationInstanceId:
13 description: Unique identifier for a given instance of the publishing application
14 type: string
15 payload:
16 type: object
17 properties:
18 user:
19 $ref: "#/components/schemas/userCreate"
20 signup:
21 $ref: "#/components/schemas/signup"
22 bindings:
23 amqp:
24 ack: false
25 traits:
26 - $ref: "#/components/operationTraits/kafka"message和traits。| 字段名称 | 类型 | 描述 |
|---|---|---|
| operationId | string | 用于标识操作的唯一字符串。在 API 中描述的所有操作中,id 必须是唯一的。operationId 值区分大小写。工具和库可以使用 operationId 来唯一标识一个操作,因此,建议遵循通用的编程命名约定。 |
| summary | string | 操作内容的简短摘要。 |
| description | string | 对操作的详细解释。CommonMark 语法可用于富文本表示。 |
| tags | Tags Object | API 文档控制的标签列表。标签可用于操作的逻辑分组。 |
| externalDocs | External Documentation Object | 此操作的附加外部文档。 |
| bindings | Operation Bindings Object | 一个自由格式的映射,其中键描述协议的名称,值描述操作的协议特定定义。 |
1 {
2 "bindings": {
3 "amqp": {
4 "ack": false
5 }
6 }
7 }
1 bindings:
2 amqp:
3 ack: false| 字段模式 | 类型 | 描述 |
|---|---|---|
^[A-Za-z0-9_-]+$ | 参数对象 / 参考对象 | 键代表参数的名称。它必须与父通道名称中使用的参数名称相匹配。 |
1 {
2 "user/{userId}/signup": {
3 "parameters": {
4 "userId": {
5 "description": "Id of the user.",
6 "schema": {
7 "type": "string"
8 }
9 }
10 },
11 "subscribe": {
12 "$ref": "#/components/messages/userSignedUp"
13 }
14 }
15 }
1 user/{userId}/signup:
2 parameters:
3 userId:
4 description: Id of the user.
5 schema:
6 type: string
7 subscribe:
8 $ref: "#/components/messages/userSignedUp"| 字段名称 | 类型 | 描述 |
|---|---|---|
| description | string | 参数的详细解释。CommonMark 语法可用于富文本表示。 |
| schema | Schema Object | 参数的定义。 |
| location | string | 指定参数值位置的运行时表达式。即使存在目标字段的定义,也不得使用它来验证此参数,而schema必须使用属性。 |
1 {
2 "user/{userId}/signup": {
3 "parameters": {
4 "userId": {
5 "description": "Id of the user.",
6 "schema": {
7 "type": "string"
8 },
9 "location": "$message.payload#/user/id"
10 }
11 },
12 "subscribe": {
13 "$ref": "#/components/messages/userSignedUp"
14 }
15 }
16 }
1 user/{userId}/signup:
2 parameters:
3 userId:
4 description: Id of the user.
5 schema:
6 type: string
7 location: $message.payload#/user/id
8 subscribe:
9 $ref: "#/components/messages/userSignedUp"| 字段名称 | 类型 | 描述 |
|---|---|---|
http | HTTP 服务器绑定 | HTTP 服务器的特定于协议的信息。 |
ws | WebSockets 服务器绑定 | WebSockets 服务器的特定于协议的信息。 |
kafka | Kafka 服务器绑定 | Kafka 服务器的特定于协议的信息。 |
amqp | AMQP 服务器绑定 | AMQP 0-9-1 服务器的协议特定信息。 |
amqp1 | AMQP 1.0 服务器绑定 | AMQP 1.0 服务器的特定于协议的信息。 |
mqtt | MQTT 服务器绑定 | MQTT 服务器的特定于协议的信息。 |
mqtt5 | MQTT 5 服务器绑定 | MQTT 5 服务器的特定于协议的信息。 |
nats | NATS 服务器绑定 | NATS 服务器的协议特定信息。 |
jms | JMS 服务器绑定 | JMS 服务器的特定于协议的信息。 |
sns | SNS 服务器绑定 | SNS 服务器的特定于协议的信息。 |
sqs | SQS 服务器绑定 | SQS 服务器的特定于协议的信息。 |
stomp | STOMP 服务器绑定 | STOMP 服务器的特定于协议的信息。 |
redis | Redis 服务器绑定 | Redis 服务器的特定于协议的信息。 |
| 字段名称 | 类型 | 描述 |
|---|---|---|
http | HTTP 通道绑定 | HTTP 通道的特定于协议的信息。 |
ws | WebSockets 通道绑定 | WebSockets 通道的特定于协议的信息。 |
kafka | Kafka 通道绑定 | Kafka 通道的特定于协议的信息。 |
amqp | AMQP 通道绑定 | AMQP 0-9-1 通道的特定于协议的信息。 |
amqp1 | AMQP 1.0 通道绑定 | AMQP 1.0 通道的特定于协议的信息。 |
mqtt | MQTT 通道绑定 | MQTT 通道的特定于协议的信息。 |
mqtt5 | MQTT 5 通道绑定 | MQTT 5 通道的特定于协议的信息。 |
nats | NATS 通道绑定 | NATS 通道的特定于协议的信息。 |
jms | JMS 通道绑定 | JMS 通道的特定于协议的信息。 |
sns | SNS 频道绑定 | SNS 频道的特定于协议的信息。 |
sqs | SQS 通道绑定 | SQS 通道的特定于协议的信息。 |
stomp | STOMP 通道绑定 | STOMP 通道的特定于协议的信息。 |
redis | Redis 通道绑定 | Redis 通道的特定于协议的信息。 |
| 字段名称 | 类型 | 描述 |
|---|---|---|
http | HTTP 操作绑定 | HTTP 操作的特定于协议的信息。 |
ws | WebSockets 操作绑定 | WebSockets 操作的特定于协议的信息。 |
kafka | Kafka 操作绑定 | Kafka 操作的特定于协议的信息。 |
amqp | AMQP 操作绑定 | AMQP 0-9-1 操作的特定于协议的信息。 |
amqp1 | AMQP 1.0 操作绑定 | AMQP 1.0 操作的特定于协议的信息。 |
mqtt | MQTT 操作绑定 | MQTT 操作的特定于协议的信息。 |
mqtt5 | MQTT 5 操作绑定 | MQTT 5 操作的特定于协议的信息。 |
nats | NATS 操作绑定 | NATS 操作的协议特定信息。 |
jms | JMS 操作绑定 | JMS 操作的特定于协议的信息。 |
sns | SNS运营绑定 | SNS 操作的特定于协议的信息。 |
sqs | SQS操作绑定 | SQS 操作的特定于协议的信息。 |
stomp | STOMP操作绑定 | STOMP 操作的特定于协议的信息。 |
redis | Redis操作绑定 | Redis 操作的特定于协议的信息。 |
| 字段名称 | 类型 | 描述 |
|---|---|---|
http | HTTP 消息绑定 | HTTP 消息(即请求或响应)的协议特定信息。 |
ws | WebSockets 消息绑定 | WebSockets 消息的特定于协议的信息。 |
kafka | Kafka 消息绑定 | Kafka 消息的特定于协议的信息。 |
amqp | AMQP 消息绑定 | AMQP 0-9-1 消息的特定于协议的信息。 |
amqp1 | AMQP 1.0 消息绑定 | AMQP 1.0 消息的特定于协议的信息。 |
mqtt | MQTT 消息绑定 | MQTT 消息的特定于协议的信息。 |
mqtt5 | MQTT 5 消息绑定 | MQTT 5 消息的特定于协议的信息。 |
nats | NATS 消息绑定 | NATS 消息的协议特定信息。 |
jms | JMS 消息绑定 | JMS 消息的特定于协议的信息。 |
sns | SNS消息绑定 | SNS 消息的特定于协议的信息。 |
sqs | SQS 消息绑定 | SQS 消息的特定于协议的信息。 |
stomp | STOMP 消息绑定 | STOMP 消息的特定于协议的信息。 |
redis | Redis 消息绑定 | Redis 消息的特定于协议的信息。 |
| 字段名称 | 类型 | 描述 |
|---|---|---|
| headers | Schema Object / Reference Object | 应用程序标头的架构定义。模式必须是“对象”类型。它不得定义协议标头。 |
| payload | any | 消息负载的定义。它可以是任何类型,但默认为Schema object。 |
| correlationId | Correlation ID Object / Reference Object | 用于消息跟踪或匹配的关联 ID 的定义。 |
| schemaFormat | string | 一个字符串,包含用于定义消息负载的架构格式的名称。如果省略,实现应将有效负载解析为Schema object。查看支持的架构格式表以获取更多信息。允许自定义值,但它们的实现是可选的。自定义值不得引用表中列出的模式格式之一。 |
| contentType | string | 编码/解码消息负载时使用的内容类型。该值必须是特定的媒体类型(例如application/json)。省略时,该值必须是在defaultContentType字段上指定的值。 |
| name | string | 消息的机器友好名称。 |
| title | string | 消息的人性化标题。 |
| summary | string | 消息内容的简短摘要。 |
| description | string | 消息的详细解释。CommonMark 语法可用于富文本表示。 |
| tags | Tags Object | API 文档控制的标签列表。标签可用于消息的逻辑分组。 |
| externalDocs | External Documentation Object | 此消息的其他外部文档。 |
| bindings | Message Bindings Object | 一个自由格式的映射,其中键描述协议的名称,值描述消息的协议特定定义。 |
| examples | [Map[string, any]] | 包含有效消息对象示例的数组。 |
| 特质 | [Message Trait Object] | 应用于消息对象的特征列表。特征必须按照此处定义的相同顺序使用JSON 合并补丁算法合并到消息对象中。结果对象必须是一个有效的消息对象。 |
| 姓名 | 允许值 | 笔记 |
|---|---|---|
| AsyncAPI 2.0.0 架构对象 | application/vnd.aai.asyncapi;version=2.0.0, application/vnd.aai.asyncapi+json;version=2.0.0,application/vnd.aai.asyncapi+yaml;version=2.0.0 | schemaFormat当没有提供a 时,这是默认值。 |
| OpenAPI 3.0.0 架构对象 | application/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 | |
| JSON 架构草案 07 | application/schema+json;version=draft-07,application/schema+yaml;version=draft-07 | |
| Avro 1.9.0 架构 | application/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 |
1 {
2 "name": "UserSignup",
3 "title": "User signup",
4 "summary": "Action to sign a user up.",
5 "description": "A longer description",
6 "contentType": "application/json",
7 "tags": [
8 { "name": "user" },
9 { "name": "signup" },
10 { "name": "register" }
11 ],
12 "headers": {
13 "type": "object",
14 "properties": {
15 "correlationId": {
16 "description": "Correlation ID set by application",
17 "type": "string"
18 },
19 "applicationInstanceId": {
20 "description": "Unique identifier for a given instance of the publishing application",
21 "type": "string"
22 }
23 }
24 },
25 "payload": {
26 "type": "object",
27 "properties": {
28 "user": {
29 "$ref": "#/components/schemas/userCreate"
30 },
31 "signup": {
32 "$ref": "#/components/schemas/signup"
33 }
34 }
35 },
36 "correlationId": {
37 "description": "Default Correlation ID",
38 "location": "$message.header#/correlationId"
39 },
40 "traits": [
41 { "$ref": "#/components/messageTraits/commonHeaders" }
42 ]
43 }
1 name: UserSignup
2 title: User signup
3 summary: Action to sign a user up.
4 description: A longer description
5 contentType: application/json
6 tags:
7 - name: user
8 - name: signup
9 - name: register
10 headers:
11 type: object
12 properties:
13 correlationId:
14 description: Correlation ID set by application
15 type: string
16 applicationInstanceId:
17 description: Unique identifier for a given instance of the publishing application
18 type: string
19 payload:
20 type: object
21 properties:
22 user:
23 $ref: "#/components/schemas/userCreate"
24 signup:
25 $ref: "#/components/schemas/signup"
26 correlationId:
27 description: Default Correlation ID
28 location: $message.header#/correlationId
29 traits:
30 - $ref: "#/components/messageTraits/commonHeaders"
1 {
2 "name": "UserSignup",
3 "title": "User signup",
4 "summary": "Action to sign a user up.",
5 "description": "A longer description",
6 "tags": [
7 { "name": "user" },
8 { "name": "signup" },
9 { "name": "register" }
10 ],
11 "schemaFormat": "application/vnd.apache.avro+json;version=1.9.0",
12 "payload": {
13 "$ref": "path/to/user-create.avsc#/UserCreate"
14 }
15 }
1 name: UserSignup
2 title: User signup
3 summary: Action to sign a user up.
4 description: A longer description
5 tags:
6 - name: user
7 - name: signup
8 - name: register
9 schemaFormat: 'application/vnd.apache.avro+yaml;version=1.9.0'
10 payload:
11 $ref: 'path/to/user-create.avsc/#UserCreate'payload和traits。| 字段名称 | 类型 | 描述 |
|---|---|---|
| headers | Schema Object / Reference Object | 应用程序标头的架构定义。模式必须是“对象”类型。它不得定义协议标头。 |
| correlationId | Correlation ID Object / Reference Object | 用于消息跟踪或匹配的关联 ID 的定义。 |
| schemaFormat | string | 包含用于定义消息负载的模式格式/语言名称的字符串。如果省略,实现应将有效负载解析为Schema object。 |
| contentType | string | 编码/解码消息负载时使用的内容类型。该值必须是特定的媒体类型(例如application/json)。省略时,该值必须是在defaultContentType字段上指定的值。 |
| name | string | 消息的机器友好名称。 |
| title | string | 消息的人性化标题。 |
| summary | string | 消息内容的简短摘要。 |
| description | string | 消息的详细解释。CommonMark 语法可用于富文本表示。 |
| tags | Tags Object | API 文档控制的标签列表。标签可用于消息的逻辑分组。 |
| externalDocs | External Documentation Object | 此消息的其他外部文档。 |
| bindings | Map[ string,消息绑定对象] | 一个自由格式的映射,其中键描述协议的名称,值描述消息的协议特定定义。 |
| examples | [Map[ string, any] ] | 包含有效消息对象示例的数组。 |
1 {
2 "schemaFormat": "application/vnd.apache.avro+json;version=1.9.0",
3 "contentType": "application/json"
4 }
1 schemaFormat: 'application/vnd.apache.avro+yaml;version=1.9.0'
2 contentType: application/json| 字段名称 | 类型 | 描述 |
|---|---|---|
| name | string | 必需的。 标记的名称。 |
| description | string | 标签的简短描述。CommonMark 语法可 用于富文本表示。 |
| externalDocs | External Documentation Object | 此标签的附加外部文档。 |
1 {
2 "name": "user",
3 "description": "User-related messages"
4 }
1 name: user
2 description: User-related messages| 字段名称 | 类型 | 描述 |
|---|---|---|
| description | string | 目标文档的简短描述。CommonMark 语法可用于富文本表示。 |
| url | string | 必需的。 目标文档的 URL。值必须采用 URL 格式。 |
1 {
2 "description": "Find more info here",
3 "url": "https://example.com"
4 }
1 description: Find more info here
2 url: https://example.com| 字段名称 | 类型 | 描述 |
|---|---|---|
| $ref | string | 必需的。 参考字符串。 |
1 {
2 "$ref": "#/components/schemas/Pet"
3 } $ref: '#/components/schemas/Pet'| 字段名称 | 类型 | 描述 |
|---|---|---|
| schemas | Map[string, Schema Object / Reference Object] | 一个对象来保存可重用的Schema Objects。 |
| messages | Map[string, Message Object / Reference Object] | 一个对象来保存可重用的消息对象。. |
| securitySchemes | Map[string, Security Scheme Object / Reference Object] | 一个对象来保存可重用的安全方案对象。 |
| parameters | Map[string, Parameter Object / Reference Object] | 一个对象来保存可重用的参数对象。 |
| correlationIds | Map[string, Correlation ID Object] | 一个对象来保存可重用的相关 ID 对象。 |
| operationTraits | Map[string, Operation Trait Object] | 一个对象来保存可重用的Operation Trait Objects。 |
| messageTraits | Map[string, Message Trait Object] | 一个对象来保存可重用的Message Trait Objects。 |
| serverBindings | Map[string, Server Binding Object] | 一个对象来保存可重用的服务器绑定对象。 |
| channelBindings | Map[string, Channel Binding Object] | 一个对象来保存可重用的Channel Binding Objects。 |
| operationBindings | Map[string, Operation Binding Object] | 一个对象来保存可重用的操作绑定对象。 |
| messageBindings | Map[string, Message Binding Object] | 一个对象来保存可重用的消息绑定对象。 |
^[a-zA-Z0-9.-_]+$。
1 User
2 User_1
3 User_Name
4 user-name
5 my.org.User
1 "components": {
2 "schemas": {
3 "Category": {
4 "type": "object",
5 "properties": {
6 "id": {
7 "type": "integer",
8 "format": "int64"
9 },
10 "name": {
11 "type": "string"
12 }
13 }
14 },
15 "Tag": {
16 "type": "object",
17 "properties": {
18 "id": {
19 "type": "integer",
20 "format": "int64"
21 },
22 "name": {
23 "type": "string"
24 }
25 }
26 }
27 },
28 "messages": {
29 "userSignUp": {
30 "summary": "Action to sign a user up.",
31 "description": "Multiline description of what this action does.\nHere you have another line.\n",
32 "tags": [
33 {
34 "name": "user"
35 },
36 {
37 "name": "signup"
38 }
39 ],
40 "headers": {
41 "type": "object",
42 "properties": {
43 "applicationInstanceId": {
44 "description": "Unique identifier for a given instance of the publishing application",
45 "type": "string"
46 }
47 }
48 },
49 "payload": {
50 "type": "object",
51 "properties": {
52 "user": {
53 "$ref": "#/components/schemas/userCreate"
54 },
55 "signup": {
56 "$ref": "#/components/schemas/signup"
57 }
58 }
59 }
60 }
61 },
62 "parameters": {
63 "userId": {
64 "name": "userId",
65 "description": "Id of the user.",
66 "schema": {
67 "type": "string"
68 }
69 }
70 },
71 "correlationIds": {
72 "default": {
73 "description": "Default Correlation ID",
74 "location": "$message.header#/correlationId"
75 }
76 },
77 "messageTraits": {
78 "commonHeaders": {
79 "headers": {
80 "type": "object",
81 "properties": {
82 "my-app-header": {
83 "type": "integer",
84 "minimum": 0,
85 "maximum": 100
86 }
87 }
88 }
89 }
90 }
91 }
1 components:
2 schemas:
3 Category:
4 type: object
5 properties:
6 id:
7 type: integer
8 format: int64
9 name:
10 type: string
11 Tag:
12 type: object
13 properties:
14 id:
15 type: integer
16 format: int64
17 name:
18 type: string
19 messages:
20 userSignUp:
21 summary: Action to sign a user up.
22 description: |
23 Multiline description of what this action does.
24 Here you have another line.
25 tags:
26 - name: user
27 - name: signup
28 headers:
29 type: object
30 properties:
31 applicationInstanceId:
32 description: Unique identifier for a given instance of the publishing application
33 type: string
34 payload:
35 type: object
36 properties:
37 user:
38 $ref: "#/components/schemas/userCreate"
39 signup:
40 $ref: "#/components/schemas/signup"
41 parameters:
42 userId:
43 - name: userId
44 description: Id of the user.
45 schema:
46 type: string
47 correlationIds:
48 default:
49 description: Default Correlation ID
50 location: $message.header#/correlationId
51 messageTraits:
52 commonHeaders:
53 headers:
54 type: object
55 properties:
56 my-app-header:
57 type: integer
58 minimum: 0
59 maximum: 100typeis string, then defaultcan be "foo"but cannot be 1。| 字段名称 | 类型 | 描述 |
|---|---|---|
| discriminator | string | 添加对多态性的支持。鉴别器是用于区分继承此模式的其他模式的模式属性名称。使用的属性名称必须在此模式中定义,并且必须在required属性列表中。使用时,该值必须是该模式或继承它的任何模式的名称。有关详细信息,请参阅组合和继承。 |
| externalDocs | External Documentation Object | 此架构的其他外部文档。 |
| deprecated | boolean | 指定模式已弃用并且应该停止使用。默认值为false。 |
allOfJSON Schema 的属性组合和扩展模型定义,实际上提供了模型组合。 allOf接收一组对象定义,这些定义独立验证但一起组成一个对象。discriminator字段的支持。使用时,discriminator将是属性的名称,用于决定使用哪个模式定义来验证模型的结构。因此,该discriminator字段必须是必填字段。有两种方法可以为继承实例定义鉴别器的值。
1 {
2 "type": "string",
3 "format": "email"
4 }
1 type: string
2 format: email
1 {
2 "type": "object",
3 "required": [
4 "name"
5 ],
6 "properties": {
7 "name": {
8 "type": "string"
9 },
10 "address": {
11 "$ref": "#/components/schemas/Address"
12 },
13 "age": {
14 "type": "integer",
15 "format": "int32",
16 "minimum": 0
17 }
18 }
19 }
1 type: object
2 required:
3 - name
4 properties:
5 name:
6 type: string
7 address:
8 $ref: '#/components/schemas/Address'
9 age:
10 type: integer
11 format: int32
12 minimum: 0
1 {
2 "type": "object",
3 "additionalProperties": {
4 "type": "string"
5 }
6 }
1 type: object
2 additionalProperties:
3 type: string
1 {
2 "type": "object",
3 "additionalProperties": {
4 "$ref": "#/components/schemas/ComplexModel"
5 }
6 }
1 type: object
2 additionalProperties:
3 $ref: '#/components/schemas/ComplexModel'
1 {
2 "type": "object",
3 "properties": {
4 "id": {
5 "type": "integer",
6 "format": "int64"
7 },
8 "name": {
9 "type": "string"
10 }
11 },
12 "required": [
13 "name"
14 ],
15 "example": {
16 "name": "Puma",
17 "id": 1
18 }
19 }
1 type: object
2 properties:
3 id:
4 type: integer
5 format: int64
6 name:
7 type: string
8 required:
9 - name
10 example:
11 name: Puma
12 id: 1
1 {
2 "schemas": {
3 "ErrorModel": {
4 "type": "object",
5 "required": [
6 "message",
7 "code"
8 ],
9 "properties": {
10 "message": {
11 "type": "string"
12 },
13 "code": {
14 "type": "integer",
15 "minimum": 100,
16 "maximum": 600
17 }
18 }
19 },
20 "ExtendedErrorModel": {
21 "allOf": [
22 {
23 "$ref": "#/components/schemas/ErrorModel"
24 },
25 {
26 "type": "object",
27 "required": [
28 "rootCause"
29 ],
30 "properties": {
31 "rootCause": {
32 "type": "string"
33 }
34 }
35 }
36 ]
37 }
38 }
39 }
1 schemas:
2 ErrorModel:
3 type: object
4 required:
5 - message
6 - code
7 properties:
8 message:
9 type: string
10 code:
11 type: integer
12 minimum: 100
13 maximum: 600
14 ExtendedErrorModel:
15 allOf:
16 - $ref: '#/components/schemas/ErrorModel'
17 - type: object
18 required:
19 - rootCause
20 properties:
21 rootCause:
22 type: string
1 {
2 "schemas": {
3 "Pet": {
4 "type": "object",
5 "discriminator": "petType",
6 "properties": {
7 "name": {
8 "type": "string"
9 },
10 "petType": {
11 "type": "string"
12 }
13 },
14 "required": [
15 "name",
16 "petType"
17 ]
18 },
19 "Cat": {
20 "description": "A representation of a cat. Note that `Cat` will be used as the discriminator value.",
21 "allOf": [
22 {
23 "$ref": "#/components/schemas/Pet"
24 },
25 {
26 "type": "object",
27 "properties": {
28 "huntingSkill": {
29 "type": "string",
30 "description": "The measured skill for hunting",
31 "enum": [
32 "clueless",
33 "lazy",
34 "adventurous",
35 "aggressive"
36 ]
37 }
38 },
39 "required": [
40 "huntingSkill"
41 ]
42 }
43 ]
44 },
45 "Dog": {
46 "description": "A representation of a dog. Note that `Dog` will be used as the discriminator value.",
47 "allOf": [
48 {
49 "$ref": "#/components/schemas/Pet"
50 },
51 {
52 "type": "object",
53 "properties": {
54 "packSize": {
55 "type": "integer",
56 "format": "int32",
57 "description": "the size of the pack the dog is from",
58 "minimum": 0
59 }
60 },
61 "required": [
62 "packSize"
63 ]
64 }
65 ]
66 }
67 }
68 }
1 schemas:
2 Pet:
3 type: object
4 discriminator: petType
5 properties:
6 name:
7 type: string
8 petType:
9 type: string
10 required:
11 - name
12 - petType
13 Cat: ## "Cat" will be used as the discriminator value
14 description: A representation of a cat
15 allOf:
16 - $ref: '#/components/schemas/Pet'
17 - type: object
18 properties:
19 huntingSkill:
20 type: string
21 description: The measured skill for hunting
22 enum:
23 - clueless
24 - lazy
25 - adventurous
26 - aggressive
27 required:
28 - huntingSkill
29 Dog: ## "Dog" will be used as the discriminator value
30 description: A representation of a dog
31 allOf:
32 - $ref: '#/components/schemas/Pet'
33 - type: object
34 properties:
35 packSize:
36 type: integer
37 format: int32
38 description: the size of the pack the dog is from
39 minimum: 0
40 required:
41 - packSize| 字段名称 | 类型 | 适用于 | 描述 |
|---|---|---|---|
| type | string | 任何 | 必需的。安全方案的类型。有效值为"userPassword", "apiKey", "X509", "symmetricEncryption", "asymmetricEncryption", "httpApiKey", "http",oauth2和openIdConnect。 |
| description | string | 任何 | 安全方案的简短描述。CommonMark 语法可以用于富文本表示。 |
| name | string | httpApiKey | 必需的。要使用的标头、查询或 cookie 参数的名称。 |
| in | string | apiKey / httpApiKey | 必需的。API 密钥的位置。有效值为"user"and "password"for apiKeyand"query"或for 。"header"``"cookie"``httpApiKey |
| scheme | string | http | 必需的。在 RFC7235 中定义的授权标头中使用的 HTTP 授权方案的名称。 |
| bearerFormat | string | http( "bearer") | 提示客户端确定不记名令牌的格式。不记名令牌通常由授权服务器生成,因此此信息主要用于文档目的。 |
| flows | OAuth 流对象 | oauth2 | 必需的。包含支持的流类型的配置信息的对象。 |
| openIdConnectUrl | string | openIdConnect | 必需的。用于发现 OAuth2 配置值的 OpenId Connect URL。这必须是 URL 的形式。 |
1 {
2 "type": "userPassword"
3 }type: userPassword
1 {
2 "type": "apiKey",
3 "in": "user"
4 }
1 type: apiKey,
2 in: user
1 {
2 "type": "X509"
3 }type: X509
1 {
2 "type": "symmetricEncryption"
3 }type: symmetricEncryption
1 {
2 "type": "http",
3 "scheme": "basic"
4 }
1 type: http
2 scheme: basic
1 {
2 "type": "httpApiKey",
3 "name": "api_key",
4 "in": "header"
5 }
1 type: httpApiKey
2 name: api_key
3 in: header
1 {
2 "type": "http",
3 "scheme": "bearer",
4 "bearerFormat": "JWT",
5 }
1 type: http
2 scheme: bearer
3 bearerFormat: JWT
1 {
2 "type": "oauth2",
3 "flows": {
4 "implicit": {
5 "authorizationUrl": "https://example.com/api/oauth/dialog",
6 "scopes": {
7 "write:pets": "modify pets in your account",
8 "read:pets": "read your pets"
9 }
10 }
11 }
12 }
1 type: oauth2
2 flows:
3 implicit:
4 authorizationUrl: https://example.com/api/oauth/dialog
5 scopes:
6 write:pets: modify pets in your account
7 read:pets: read your pets| 字段名称 | 类型 | 描述 |
|---|---|---|
| implicit | OAuth 流对象 | OAuth 隐式流程的配置 |
| password | OAuth 流对象 | OAuth 资源所有者受保护凭证流程的配置 |
| clientCredentials | OAuth 流对象 | OAuth 客户端凭证流的配置。 |
| authorizationCode | OAuth 流对象 | OAuth 授权代码流的配置。 |
| 字段名称 | 类型 | 适用于 | 描述 |
|---|---|---|---|
| authorizationUrl | string | oauth2( "implicit", "authorizationCode") | 必需的。用于此流的授权 URL。这必须是 URL 的形式。 |
| tokenUrl | string | oauth2( "password", "clientCredentials", "authorizationCode") | 必需的。用于此流的令牌 URL。这必须是 URL 的形式。 |
| refreshUrl | string | oauth2 | 用于获取刷新令牌的 URL。这必须是 URL 的形式。 |
| scopes | Map[ string, string] | oauth2 | 必需的。OAuth2 安全方案的可用范围。作用域名称和它的简短描述之间的映射。 |
1 {
2 "type": "oauth2",
3 "flows": {
4 "implicit": {
5 "authorizationUrl": "https://example.com/api/oauth/dialog",
6 "scopes": {
7 "write:pets": "modify pets in your account",
8 "read:pets": "read your pets"
9 }
10 },
11 "authorizationCode": {
12 "authorizationUrl": "https://example.com/api/oauth/dialog",
13 "tokenUrl": "https://example.com/api/oauth/token",
14 "scopes": {
15 "write:pets": "modify pets in your account",
16 "read:pets": "read your pets"
17 }
18 }
19 }
20 }
1 type: oauth2
2 flows:
3 implicit:
4 authorizationUrl: https://example.com/api/oauth/dialog
5 scopes:
6 write:pets: modify pets in your account
7 read:pets: read your pets
8 authorizationCode:
9 authorizationUrl: https://example.com/api/oauth/dialog
10 tokenUrl: https://example.com/api/oauth/token
11 scopes:
12 write:pets: modify pets in your account
13 read:pets: read your pets| 字段模式 | 类型 | 描述 |
|---|---|---|
| name | [ string] | 每个名称必须对应于在组件对象下的安全方案中声明的安全方案。如果安全方案的类型为或,则该值是执行所需范围名称的列表。对于其他安全方案类型,该数组必须为空。"oauth2"``"openIdConnect" |
1
2
3
{
"user_pass": []
}user_pass: []1
2
3
{
"api_key": []
}api_key: []
1 {
2 "petstore_auth": [
3 "write:pets",
4 "read:pets"
5 ]
6 }
1 petstore_auth:
2 - write:pets
3 - read:pets| 字段名称 | 类型 | 描述 |
|---|---|---|
| description | string | 标识符的可选描述。CommonMark 语法可用于富文本表示。 |
| location | string | 必需的。 指定相关 ID 位置的运行时表达式。 |
1 {
2 "description": "Default Correlation ID",
3 "location": "$message.header#/correlationId"
4 }
1 description: Default Correlation ID
2 location: $message.header#/correlationId
1 expression = ( "$message" "." source )
2 source = ( header-reference | payload-reference )
3 header-reference = "header." ["#" fragment]
4 payload-reference = "payload." ["#" fragment]
5 fragment = a JSON Pointer [RFC 6901](https://tools.ietf.org/html/rfc6901)| 源位置 | 示例表达式 | 笔记 |
|---|---|---|
| Message Header Property | $message.header#/MQMD/CorrelId | CorrelId使用标头中的值设置关联 ID MQMD。 |
| Message Payload Property | $message.payload#/messageId | 关联 ID 是使用messageId消息有效负载中的值设置的。 |
"x-"。| 字段模式 | 类型 | 描述 |
|---|---|---|
^x-[\w\d-_]+$ | 任何 | 允许扩展 AsyncAPI 模式。字段名必须以 开头x-,例如x-internal-id. 该值可以是null、基元、数组或对象。可以具有任何有效的 JSON 格式值。 |
format. AsyncAPI 规范使用多种已知格式来更精细地定义所使用的数据类型。但是,该format属性是一个开放string值属性,可以具有支持文档需求的任何值。可以使用 、 等格式"email","uuid"即使它们未由本规范定义。不附带format属性的类型遵循它们在 JSON 架构中的定义。不识别特定的工具format可以默认返回type单独的,就好像format没有指定一样。| 通用名称 | TYPE | FORMAT | 评论 |
|---|---|---|---|
| integer | integer | int32 | 带符号的 32 位 |
| long | integer | int64 | 有符号的 64 位 |
| float | number | float | |
| double | number | double | |
| string | string | ||
| byte | string | byte | base64编码的字符 |
| binary | string | binary | 任何八位字节序列 |
| boolean | boolean | ||
| date | string | date | 由full-date- RFC3339定义 |
| dateTime | string | date-time | 由date-time- RFC3339定义 |
| password | string | password | 用于提示 UI 需要隐藏输入。 |