From d4c87b916d88645791b60d0913e8b261adccd864 Mon Sep 17 00:00:00 2001
From: Sergio Moya <1083296+smoya@users.noreply.github.com>
Date: Thu, 13 Jan 2022 12:01:25 +0100
Subject: [PATCH] feat: allow servers and channels to be defined as components
---
examples/social-media/backend/asyncapi.yaml | 3 +-
examples/social-media/common/servers.yaml | 3 ++
examples/social-media/frontend/asyncapi.yaml | 3 +-
spec/asyncapi.md | 30 ++++++++++++++++++++
4 files changed, 35 insertions(+), 4 deletions(-)
create mode 100644 examples/social-media/common/servers.yaml
diff --git a/examples/social-media/backend/asyncapi.yaml b/examples/social-media/backend/asyncapi.yaml
index 1c4a60afa..cefc2f98c 100644
--- a/examples/social-media/backend/asyncapi.yaml
+++ b/examples/social-media/backend/asyncapi.yaml
@@ -6,8 +6,7 @@ info:
servers:
websiteWebSocketServer:
- url: ws://mycompany.com/ws
- protocol: ws
+ $ref: '../common/servers.yaml#/websiteWebSocketServer'
mosquitto:
url: mqtt://test.mosquitto.org
protocol: mqtt
diff --git a/examples/social-media/common/servers.yaml b/examples/social-media/common/servers.yaml
new file mode 100644
index 000000000..bb32c3802
--- /dev/null
+++ b/examples/social-media/common/servers.yaml
@@ -0,0 +1,3 @@
+websiteWebSocketServer:
+ url: ws://mycompany.com/ws
+ protocol: ws
\ No newline at end of file
diff --git a/examples/social-media/frontend/asyncapi.yaml b/examples/social-media/frontend/asyncapi.yaml
index 7462478fa..2837fb6ff 100644
--- a/examples/social-media/frontend/asyncapi.yaml
+++ b/examples/social-media/frontend/asyncapi.yaml
@@ -6,8 +6,7 @@ info:
servers:
websiteWebSocketServer:
- url: ws://mycompany.com/ws
- protocol: ws
+ $ref: '../common/servers.yaml#/websiteWebSocketServer'
channels:
like/comment:
diff --git a/spec/asyncapi.md b/spec/asyncapi.md
index 50d5f4a0f..17f9280c5 100644
--- a/spec/asyncapi.md
+++ b/spec/asyncapi.md
@@ -1437,6 +1437,8 @@ All objects defined within the components object will have no effect on the API
Field Name | Type | Description
---|:---|---
schemas | Map[`string`, [Schema Object](#schemaObject) \| [Reference Object](#referenceObject)] | An object to hold reusable [Schema Objects](#schemaObject).
+ servers | Map[`string`, [Server Object](#serverObject) \| [Reference Object](#referenceObject)] | An object to hold reusable [Server Objects](#serverObject).
+ channels | Map[`string`, [Channel Object](#channelItemObject) \| [Reference Object](#referenceObject)] | An object to hold reusable [Channel Objects](#channelItemObject).
messages | Map[`string`, [Message Object](#messageObject) \| [Reference Object](#referenceObject)] | An object to hold reusable [Message Objects](#messageObject).
securitySchemes| Map[`string`, [Security Scheme Object](#securitySchemeObject) \| [Reference Object](#referenceObject)] | An object to hold reusable [Security Scheme Objects](#securitySchemeObject).
parameters | Map[`string`, [Parameter Object](#parameterObject) \| [Reference Object](#referenceObject)] | An object to hold reusable [Parameter Objects](#parameterObject).
@@ -1493,6 +1495,23 @@ my.org.User
}
}
},
+ "servers": {
+ "development": {
+ "url": "development.gigantic-server.com",
+ "description": "Development server",
+ "protocol": "amqp",
+ "protocolVersion": "0.9.1"
+ }
+ },
+ "channels": {
+ "user/signedup": {
+ "subscribe": {
+ "message": {
+ "$ref": "#/components/messages/userSignUp"
+ }
+ }
+ }
+ },
"messages": {
"userSignUp": {
"summary": "Action to sign a user up.",
@@ -1578,6 +1597,17 @@ components:
format: int64
name:
type: string
+ servers:
+ development:
+ url: development.gigantic-server.com
+ description: Development server
+ protocol: amqp
+ protocolVersion: 0.9.1
+ channels:
+ user/signedup:
+ subscribe:
+ message:
+ $ref: "#/components/messages/userSignUp"
messages:
userSignUp:
summary: Action to sign a user up.