From c6f769e192004e8de09f8e32a96dac09fe7a6511 Mon Sep 17 00:00:00 2001 From: Pavel Bodiachevskii Date: Sun, 25 Feb 2024 15:20:57 +0400 Subject: [PATCH] test(2.6.0): check correctness of realisation by reading AsyncAPI example - Gitter Streaming API Example https://github.com/asyncapi/jasyncapi/issues/165 --- .../examples/v2/_6_0/GitterStreaming.kt | 295 ++++++++++++++++++ .../examples/v2.6.0/gitter-streaming.yml | 169 ++++++++++ 2 files changed, 464 insertions(+) create mode 100644 asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_6_0/GitterStreaming.kt create mode 100644 asyncapi-core/src/test/resources/examples/v2.6.0/gitter-streaming.yml diff --git a/asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_6_0/GitterStreaming.kt b/asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_6_0/GitterStreaming.kt new file mode 100644 index 00000000..97849dce --- /dev/null +++ b/asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_6_0/GitterStreaming.kt @@ -0,0 +1,295 @@ +package com.asyncapi.examples.v2._6_0 + +import com.asyncapi.v2.Reference +import com.asyncapi.v2._6_0.model.channel.ChannelItem +import com.asyncapi.v2._6_0.model.channel.Parameter +import com.asyncapi.v2._6_0.model.channel.message.Message +import com.asyncapi.v2._6_0.model.channel.message.OneOfMessages +import com.asyncapi.v2._6_0.model.channel.operation.Operation +import com.asyncapi.v2._6_0.model.component.Components +import com.asyncapi.v2._6_0.model.info.Info +import com.asyncapi.v2._6_0.model.server.Server +import com.asyncapi.v2.binding.message.http.HTTPMessageBinding +import com.asyncapi.v2.binding.operation.http.HTTPOperationBinding +import com.asyncapi.v2.binding.operation.http.HTTPOperationType +import com.asyncapi.v2.schema.Schema +import com.asyncapi.v2.security_scheme.http.HttpSecurityScheme + +class GitterStreaming: AbstractExampleValidationTest() { + + override fun specificationLocation(): String = "/examples/v2.6.0/gitter-streaming.yml" + + override fun expectedId(): String = "tag:stream.gitter.im,2022:api" + + override fun expectedInfo(): Info { + return Info.builder() + .title("Gitter Streaming API") + .version("1.0.0") + .build() + } + + override fun expectedServers(): Map { + return mapOf( + Pair("production", Server.builder() + .url("https://stream.gitter.im/v1") + .protocol("https") + .protocolVersion("1.1") + .security(listOf( + mapOf(Pair("httpBearerToken", emptyList())), + )) + .build() + ) + ) + } + + override fun expectedChannels(): Map { + return mapOf( + Pair("/rooms/{roomId}/{resource}", ChannelItem.builder() + .parameters(mapOf( + Pair("roomId", Parameter.builder() + .description("Id of the Gitter room.") + .schema(Schema.builder() + .type("string") + .examples(listOf("53307860c3599d1de448e19d")) + .build() + ) + .build() + ), + Pair("resource", Parameter.builder() + .description("The resource to consume.") + .schema(Schema.builder() + .type("string") + .enumValue(listOf("chatMessages", "events")) + .build() + ) + .build() + ) + )) + .subscribe(Operation.builder() + .bindings(mapOf( + Pair("http", HTTPOperationBinding.builder() + .type(HTTPOperationType.RESPONSE) + .build() + ) + )) + .message(OneOfMessages(listOf( + Reference("#/components/messages/chatMessage"), + Reference("#/components/messages/heartbeat") + ))) + .build() + ) + .build() + ) + ) + } + + override fun expectedComponents(): Components? { + return Components.builder() + .securitySchemes(mapOf( + Pair("httpBearerToken", HttpSecurityScheme( + null, + "bearer", + null, + )) + )) + .messages(mapOf( + Pair("chatMessage", Message.builder() + .schemaFormat("application/schema+yaml;version=draft-07") + .summary("A message represents an individual chat message sent to a room. They are a sub-resource of a room.") + .payload(Schema.builder() + .type("object") + .properties(mapOf( + Pair("id", Schema.builder() + .type("string") + .description("ID of the message.") + .build() + ), + Pair("text", Schema.builder() + .type("string") + .description("Original message in plain-text/markdown.") + .build() + ), + Pair("html", Schema.builder() + .type("string") + .description("HTML formatted message.") + .build() + ), + Pair("sent", Schema.builder() + .type("string") + .format("date-time") + .description("ISO formatted date of the message.") + .build() + ), + Pair("fromUser", Schema.builder() + .type("object") + .description("User that sent the message.") + .properties(mapOf( + Pair("id", Schema.builder() + .type("string") + .description("Gitter User ID.") + .build() + ), + Pair("username", Schema.builder() + .type("string") + .description("Gitter/GitHub username.") + .build() + ), + Pair("displayName", Schema.builder() + .type("string") + .description("Gitter/GitHub user real name.") + .build() + ), + Pair("url", Schema.builder() + .type("string") + .description("Path to the user on Gitter.") + .build() + ), + Pair("avatarUrl", Schema.builder() + .type("string") + .format("uri") + .description("User avatar URI.") + .build() + ), + Pair("avatarUrlSmall", Schema.builder() + .type("string") + .format("uri") + .description("User avatar URI (small).") + .build() + ), + Pair("avatarUrlMedium", Schema.builder() + .type("string") + .format("uri") + .description("User avatar URI (medium).") + .build() + ), + Pair("v", Schema.builder() + .type("number") + .description("Version.") + .build() + ), + Pair("gv", Schema.builder() + .type("string") + .description("Stands for \"Gravatar version\" and is used for cache busting.") + .build() + ) + )) + .build() + ), + Pair("unread", Schema.builder() + .type("boolean") + .description("Boolean that indicates if the current user has read the message.") + .build() + ), + Pair("readBy", Schema.builder() + .type("number") + .description("Number of users that have read the message.") + .build() + ), + Pair("urls", Schema.builder() + .type("array") + .description("List of URLs present in the message.") + .items(Schema.builder() + .type("string") + .format("uri") + .build()) + .build() + ), + Pair("mentions", Schema.builder() + .type("array") + .description("List of @Mentions in the message.") + .items(Schema.builder() + .type("object") + .properties(mapOf( + Pair("screenName", Schema.builder() + .type("string") + .build() + ), + Pair("userId", Schema.builder() + .type("string") + .build() + ), + Pair("userIds", Schema.builder() + .type("array") + .items(Schema.builder() + .type("string") + .build()) + .build() + ) + )) + .build()) + .build() + ), + Pair("issues", Schema.builder() + .type("array") + .description("List of #Issues referenced in the message.") + .items(Schema.builder() + .type("object") + .properties(mapOf( + Pair("number", Schema.builder().type("string").build()) + )) + .build()) + .build() + ), + Pair("meta", Schema.builder() + .type("array") + .description("Metadata. This is currently not used for anything.") + .items(Schema.builder().build()) + .build() + ), + Pair("v", Schema.builder() + .type("number") + .description("Version.") + .build() + ), + Pair("gv", Schema.builder() + .type("string") + .description("Stands for \"Gravatar version\" and is used for cache busting.") + .build() + ), + )) + .build() + ) + .bindings(mapOf( + Pair("http", Reference("#/components/messageBindings/streamingHeaders")) + )) + .build() + ), + Pair("heartbeat", Message.builder() + .schemaFormat("application/schema+yaml;version=draft-07") + .summary("Its purpose is to keep the connection alive.") + .payload(Schema.builder() + .type("string") + .enumValue(listOf("\r\n")) + .build() + ) + .bindings(mapOf( + Pair("http", Reference("#/components/messageBindings/streamingHeaders")) + )) + .build() + ), + )) + .messageBindings(mapOf( + Pair("http", HTTPMessageBinding.builder() + .headers(Schema.builder() + .type("object") + .properties(mapOf( + Pair("Transfer-Encoding", Schema.builder() + .type("string") + .constValue("chunked") + .build() + ), + Pair("Trailer", Schema.builder() + .type("string") + .constValue("\\r\\n") + .build() + ) + )) + .build() + ) + .build() + ) + )) + .build() + } + +} \ No newline at end of file diff --git a/asyncapi-core/src/test/resources/examples/v2.6.0/gitter-streaming.yml b/asyncapi-core/src/test/resources/examples/v2.6.0/gitter-streaming.yml new file mode 100644 index 00000000..335286be --- /dev/null +++ b/asyncapi-core/src/test/resources/examples/v2.6.0/gitter-streaming.yml @@ -0,0 +1,169 @@ +asyncapi: "2.6.0" +id: 'tag:stream.gitter.im,2022:api' +info: + title: Gitter Streaming API + version: '1.0.0' + +servers: + production: + url: https://stream.gitter.im/v1 + protocol: https + protocolVersion: '1.1' + security: + - httpBearerToken: [] + +channels: + /rooms/{roomId}/{resource}: + parameters: + roomId: + description: Id of the Gitter room. + schema: + type: string + examples: + - 53307860c3599d1de448e19d + resource: + description: The resource to consume. + schema: + type: string + enum: + - chatMessages + - events + subscribe: + bindings: + http: + type: response + message: + oneOf: + - $ref: '#/components/messages/chatMessage' + - $ref: '#/components/messages/heartbeat' + +components: + securitySchemes: + httpBearerToken: + type: http + scheme: bearer + messages: + chatMessage: + schemaFormat: 'application/schema+yaml;version=draft-07' + summary: >- + A message represents an individual chat message sent to a room. + They are a sub-resource of a room. + payload: + type: object + properties: + id: + type: string + description: ID of the message. + text: + type: string + description: Original message in plain-text/markdown. + html: + type: string + description: HTML formatted message. + sent: + type: string + format: date-time + description: ISO formatted date of the message. + fromUser: + type: object + description: User that sent the message. + properties: + id: + type: string + description: Gitter User ID. + username: + type: string + description: Gitter/GitHub username. + displayName: + type: string + description: Gitter/GitHub user real name. + url: + type: string + description: Path to the user on Gitter. + avatarUrl: + type: string + format: uri + description: User avatar URI. + avatarUrlSmall: + type: string + format: uri + description: User avatar URI (small). + avatarUrlMedium: + type: string + format: uri + description: User avatar URI (medium). + v: + type: number + description: Version. + gv: + type: string + description: Stands for "Gravatar version" and is used for cache busting. + unread: + type: boolean + description: Boolean that indicates if the current user has read the message. + readBy: + type: number + description: Number of users that have read the message. + urls: + type: array + description: List of URLs present in the message. + items: + type: string + format: uri + mentions: + type: array + description: List of @Mentions in the message. + items: + type: object + properties: + screenName: + type: string + userId: + type: string + userIds: + type: array + items: + type: string + issues: + type: array + description: 'List of #Issues referenced in the message.' + items: + type: object + properties: + number: + type: string + meta: + type: array + description: Metadata. This is currently not used for anything. + items: {} + v: + type: number + description: Version. + gv: + type: string + description: Stands for "Gravatar version" and is used for cache busting. + bindings: + http: + $ref: '#/components/messageBindings/streamingHeaders' + + heartbeat: + schemaFormat: 'application/schema+yaml;version=draft-07' + summary: Its purpose is to keep the connection alive. + payload: + type: string + enum: ["\r\n"] + bindings: + http: + $ref: '#/components/messageBindings/streamingHeaders' + + messageBindings: + http: + headers: + type: object + properties: + 'Transfer-Encoding': + type: string + const: 'chunked' + Trailer: + type: string + const: '\r\n' \ No newline at end of file