Async API 规范
异步 API 规范
免责声明
版本 2.0.0
介绍
1 user/signedup:
2 subscribe:
3 $ref: "#/components/messages/userSignUp"
user/signedup
频道。定义
应用
制作人
消费者
信息
渠道
协议
规格
格式
1 {
2 "field" : [...]
3 }
文件结构
$ref
中的规范中的字段。asyncapi.json
或asyncapi.yaml
.图式
异步 API 对象
固定字段
字段名称 | 类型 | 描述 |
---|---|---|
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 | 额外的外部文档。 |
AsyncAPI 版本字符串
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: true
oneOf
为每个操作指定多条消息:
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] | 一个对象来保存可重用的安全方案对象 |