From d8e3bd7748bb68b3a01963f4e8ba298dd9becc19 Mon Sep 17 00:00:00 2001 From: souvik Date: Wed, 1 May 2024 17:15:47 +0530 Subject: [PATCH] feat: spec v3 support (update examples to v3.0.0) (#549) Co-authored-by: Khuda Dad Nomani --- examples/anime-http/README.md | 29 +++++++ examples/anime-http/client/asyncapi.yaml | 5 -- examples/anime-http/server/asyncapi.yaml | 11 +-- .../functions/trendingAnimeController.ts | 10 ++- .../crypto-websockets/server/asyncapi.yaml | 2 +- .../flight-management/backend/asyncapi.yaml | 46 +++++++---- examples/kafka-test/asyncapi.yaml | 36 ++++++--- examples/shrek-websockets/asyncapi.yaml | 78 ++++++++++--------- ...ubChatMessage.js => receiveChatMessage.js} | 0 .../notifications-service/asyncapi.yaml | 21 +++-- .../websocket-server/asyncapi.yaml | 52 ++++++++----- 11 files changed, 188 insertions(+), 102 deletions(-) create mode 100644 examples/anime-http/README.md rename examples/shrek-websockets/functions/{pubChatMessage.js => receiveChatMessage.js} (100%) diff --git a/examples/anime-http/README.md b/examples/anime-http/README.md new file mode 100644 index 000000000..66f7310ec --- /dev/null +++ b/examples/anime-http/README.md @@ -0,0 +1,29 @@ +# Anime-HTTP + +This application is a dummy application showcasing the use of HTTP adapter in Glee. This application makes and `GET` call to a third-party REST API to fetch the list of famous Anime. + + +## Prerequisites + +- Node.js (version 12 or higher) + +## How to run the Application + +The application is divided into a `server` and a `client` which needs to be run simultaneously. + +**To run Server** + +```sh +cd server +npm run dev +``` + +**To run Client** + +```sh +cd client +npm run dev +``` + + +The Server needs to run first and then the client application. The server fetches the data from the third-party REST API when the client makes a `GET` API call to the server. \ No newline at end of file diff --git a/examples/anime-http/client/asyncapi.yaml b/examples/anime-http/client/asyncapi.yaml index 33f2eed39..56c7465be 100644 --- a/examples/anime-http/client/asyncapi.yaml +++ b/examples/anime-http/client/asyncapi.yaml @@ -69,11 +69,6 @@ operations: $ref: '#/channels/trendingAnime' messages: - $ref: '#/components/messages/trendingAnimeMessage' - reply: - channel: - $ref: '#/channels/trendingAnime' - messages: - - $ref: '#/components/messages/trendingAnimeReply' components: messages: testMessage: diff --git a/examples/anime-http/server/asyncapi.yaml b/examples/anime-http/server/asyncapi.yaml index 65e2af90b..c91c9f534 100644 --- a/examples/anime-http/server/asyncapi.yaml +++ b/examples/anime-http/server/asyncapi.yaml @@ -39,11 +39,12 @@ operations: $ref: '#/channels/trendingAnime' messages: - $ref: '#/components/messages/trendingAnime' - reply: - channel: - $ref: "#/channels/trendingAnime" - messages: - - $ref: '#/components/messages/trendingAnimeReply' + trendingAnimeReply: + action: send + channel: + $ref: '#/channels/trendingAnime' + messages: + - $ref: '#/components/messages/trendingAnime' components: messages: trendingAnime: diff --git a/examples/anime-http/server/functions/trendingAnimeController.ts b/examples/anime-http/server/functions/trendingAnimeController.ts index 82bb78993..381a24eb3 100644 --- a/examples/anime-http/server/functions/trendingAnimeController.ts +++ b/examples/anime-http/server/functions/trendingAnimeController.ts @@ -2,11 +2,13 @@ export default async function (event) { const replyPayload = event.payload const replyQuery = event.query return { - reply: [ + send: [ { payload: replyPayload, - query: replyQuery - }, - ], + query: replyQuery, + channel: 'trendingAnime' + } + + ] } } diff --git a/examples/crypto-websockets/server/asyncapi.yaml b/examples/crypto-websockets/server/asyncapi.yaml index 41848db70..730aa152d 100644 --- a/examples/crypto-websockets/server/asyncapi.yaml +++ b/examples/crypto-websockets/server/asyncapi.yaml @@ -32,7 +32,7 @@ channels: token: type: string operations: - /price.subscribe: + sendPrice: action: send channel: $ref: '#/channels/price' diff --git a/examples/flight-management/backend/asyncapi.yaml b/examples/flight-management/backend/asyncapi.yaml index 0443434bc..56be5e650 100644 --- a/examples/flight-management/backend/asyncapi.yaml +++ b/examples/flight-management/backend/asyncapi.yaml @@ -1,22 +1,28 @@ -asyncapi: 2.4.0 +asyncapi: 3.0.0 info: title: Flight Board version: 0.0.1 - description: Flight Board offers real time flight info on all of the screens at an airport. This AsyncAPI file is only for the real time communication. We are using Glee to manage the WebSocket server as well as the REST API server, which is being created with Express.js. - + description: >- + Flight Board offers real time flight info on all of the screens at an + airport. This AsyncAPI file is only for the real time communication. We are + using Glee to manage the WebSocket server as well as the REST API server, + which is being created with Express.js. servers: websockets: - url: ws://localhost:3000 + host: 'localhost:3000' protocol: ws - description: This Websocket server is available without authorization. It receives the changes that are made by different sources and updates the database and Flight Boards. + description: >- + This Websocket server is available without authorization. It receives the + changes that are made by different sources and updates the database and + Flight Boards. channels: - /: - publish: - operationId: sendMessage - message: - oneOf: - - $ref: '#/components/messages/updateFlight' - - $ref: '#/components/messages/getFlights' + index: + address: / + messages: + updateFlight: + $ref: '#/components/messages/updateFlight' + getFlights: + $ref: '#/components/messages/getFlights' bindings: ws: query: @@ -24,10 +30,20 @@ channels: properties: airport: type: string +operations: + sendMessage: + action: receive + channel: + $ref: '#/channels/index' + messages: + - $ref: '#/components/messages/updateFlight' + - $ref: '#/components/messages/getFlights' components: messages: getFlights: - summary: This message should be published when a board wants to receive all of the flights that depart or arrive at that airport. + summary: >- + This message should be published when a board wants to receive all of + the flights that depart or arrive at that airport. payload: type: object additionalProperties: false @@ -52,4 +68,6 @@ components: eventName: type: string description: The name of the event. - enum: ['allFlights', 'updateFlight'] + enum: + - allFlights + - updateFlight diff --git a/examples/kafka-test/asyncapi.yaml b/examples/kafka-test/asyncapi.yaml index 2c83e7de7..11ef1153b 100644 --- a/examples/kafka-test/asyncapi.yaml +++ b/examples/kafka-test/asyncapi.yaml @@ -1,23 +1,37 @@ -asyncapi: 2.4.0 +asyncapi: 3.0.0 info: title: Kafka test version: '1' servers: mykafka: - url: kafka://pkc-6ojv2.us-west4.gcp.confluent.cloud:9092 + host: 'pkc-6ojv2.us-west4.gcp.confluent.cloud:9092' protocol: kafka-secure security: - - saslScramExample: [] + - $ref: '#/components/securitySchemes/saslScramExample' channels: test: - publish: - operationId: onTest - message: + address: test + messages: + testMessage: $ref: '#/components/messages/testMessage' produce: - subscribe: - message: + address: produce + messages: + testMessage: $ref: '#/components/messages/testMessage' +operations: + onTest: + action: receive + channel: + $ref: '#/channels/test' + messages: + - $ref: '#/components/messages/testMessage' + sendMessage: + action: send + channel: + $ref: '#/channels/produce' + messages: + - $ref: '#/components/messages/testMessage' components: messages: testMessage: @@ -25,7 +39,7 @@ components: type: object properties: test: - type: string + type: string securitySchemes: - saslScramExample: - type: scramSha256 + saslScramExample: + type: scramSha256 diff --git a/examples/shrek-websockets/asyncapi.yaml b/examples/shrek-websockets/asyncapi.yaml index 2c0d65320..10130abd7 100644 --- a/examples/shrek-websockets/asyncapi.yaml +++ b/examples/shrek-websockets/asyncapi.yaml @@ -1,50 +1,56 @@ -asyncapi: 2.0.0 - -# -# Overal information for users of the application -# +asyncapi: 3.0.0 info: title: Shrek App - version: '1.0.0' - description: | - Purpose of this app is to have some fun with AsyncAPI and WebSocket and define an interface for ... Shrek. + version: 1.0.0 + description: > + Purpose of this app is to have some fun with AsyncAPI and WebSocket and + define an interface for ... Shrek. + ![](https://media.giphy.com/media/10Ug6rDDuG3YoU/giphy-downsized.gif) - You can use this API to chat with Shrek bot or to get updates about artifical travels to different locations. -# -# Details on how to connect to the application -# + + You can use this API to chat with Shrek bot or to get updates about + artifical travels to different locations. servers: swamp: - url: ws://localhost + host: localhost protocol: ws - -# -# Details about all the channels that you can listen to or send to messages -# channels: - /chat: - subscribe: - summary: Client can receive chat messages. - operationId: subChatMessage - message: + chat: + address: /chat + messages: + receiveChatMessage: $ref: '#/components/messages/chatMessage' - publish: - summary: Client can send chat messages. - operationId: pubChatMessage - message: + sendChatMessage: $ref: '#/components/messages/chatMessage' - /travel/status: - subscribe: - summary: Client can receive travel info status. - operationId: subTravelInfo - message: + travelStatus: + address: /travel/status + messages: + subTravelInfo: $ref: '#/components/messages/travelInfo' - -# -# All reusable parts for readability and staying DRY -# +operations: + recieveChatMessage: + action: receive + channel: + $ref: '#/channels/chat' + summary: Client can send chat messages. + messages: + - $ref: '#/components/messages/chatMessage' + sendChatMessage: + action: send + channel: + $ref: '#/channels/chat' + summary: Client can receive chat messages. + messages: + - $ref: '#/components/messages/chatMessage' + sendTravelInfo: + action: send + channel: + $ref: '#/channels/travelStatus' + summary: Client can receive travel info status. + messages: + - $ref: '#/components/messages/travelInfo' components: messages: chatMessage: @@ -69,4 +75,4 @@ components: type: string arrival: description: Time left to get there. - type: string \ No newline at end of file + type: string diff --git a/examples/shrek-websockets/functions/pubChatMessage.js b/examples/shrek-websockets/functions/receiveChatMessage.js similarity index 100% rename from examples/shrek-websockets/functions/pubChatMessage.js rename to examples/shrek-websockets/functions/receiveChatMessage.js diff --git a/examples/social-network/notifications-service/asyncapi.yaml b/examples/social-network/notifications-service/asyncapi.yaml index eccb914c4..d6ea01935 100644 --- a/examples/social-network/notifications-service/asyncapi.yaml +++ b/examples/social-network/notifications-service/asyncapi.yaml @@ -1,19 +1,24 @@ -asyncapi: 2.2.0 +asyncapi: 3.0.0 info: title: Notifications Service version: 0.1.0 - servers: mosquitto: - url: mqtt://test.mosquitto.org + host: test.mosquitto.org protocol: mqtt bindings: mqtt: clientId: notifications-service - channels: - post/liked: - publish: - operationId: onPostLiked - message: + postLiked: + address: post/liked + messages: + onPostLikedMmessage: $ref: '../websocket-server/asyncapi.yaml#/components/messages/notifyPostLiked' +operations: + onPostLiked: + action: receive + channel: + $ref: '#/channels/postLiked' + messages: + - $ref: '#/channels/post~1liked/messages/onPostLikedMessage' diff --git a/examples/social-network/websocket-server/asyncapi.yaml b/examples/social-network/websocket-server/asyncapi.yaml index c09bba93b..cf0b21ab8 100644 --- a/examples/social-network/websocket-server/asyncapi.yaml +++ b/examples/social-network/websocket-server/asyncapi.yaml @@ -1,37 +1,53 @@ -asyncapi: 2.2.0 +asyncapi: 3.0.0 info: title: The Social Network version: 0.1.0 - servers: websockets: - url: ws://0.0.0.0:3001 + host: '0.0.0.0:3001' protocol: ws mosquitto: - url: mqtt://test.mosquitto.org + host: test.mosquitto.org protocol: mqtt bindings: mqtt: clientId: the-social-network - channels: - /: - publish: - operationId: onLikeDislike - message: + index: + address: / + messages: + likeOrDislike: $ref: '#/components/messages/likeOrDislike' - subscribe: - message: + likeCountUpdated: $ref: '#/components/messages/likeCountUpdated' servers: - - websockets - post/liked: - subscribe: - message: + - $ref: '#/servers/websockets' + postLiked: + address: post/liked + messages: + notifyPostLiked: $ref: '#/components/messages/notifyPostLiked' servers: - - mosquitto - + - $ref: '#/servers/mosquitto' +operations: + onLikeDislike: + action: receive + channel: + $ref: '#/channels/index' + messages: + - $ref: '#/components/messages/likeOrDislike' + onLikeCounted: + action: send + channel: + $ref: '#/channels/index' + messages: + - $ref: '#/components/messages/likeCountUpdated' + notifyPostLiked: + action: send + channel: + $ref: '#/channels/postLiked' + messages: + - $ref: '#/components/messages/notifyPostLiked' components: messages: likeOrDislike: @@ -92,4 +108,4 @@ components: description: The id of the post that has been liked. userId: type: integer - description: The user who liked the post. \ No newline at end of file + description: The user who liked the post.