From 1f59be497a235453c2c5fb7b7ffd27184005272d Mon Sep 17 00:00:00 2001 From: Pavel Bodiachevskii Date: Fri, 1 Mar 2024 01:10:56 +0400 Subject: [PATCH] fix(2.6.0): check correctness of realisation by reading AsyncAPI example - Application Headers Example https://github.com/asyncapi/jasyncapi/issues/187 --- .../examples/v2/_0_0/ApplicationHeaders.kt | 149 ++++++++++++++++++ .../examples/v2.0.0/application-headers.yml | 83 ++++++++++ 2 files changed, 232 insertions(+) create mode 100644 asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_0_0/ApplicationHeaders.kt create mode 100644 asyncapi-core/src/test/resources/examples/v2.0.0/application-headers.yml diff --git a/asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_0_0/ApplicationHeaders.kt b/asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_0_0/ApplicationHeaders.kt new file mode 100644 index 00000000..0655c2dc --- /dev/null +++ b/asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_0_0/ApplicationHeaders.kt @@ -0,0 +1,149 @@ +package com.asyncapi.examples.v2._0_0 + +import com.asyncapi.v2.Reference +import com.asyncapi.v2._0_0.model.channel.ChannelItem +import com.asyncapi.v2._0_0.model.channel.Parameter +import com.asyncapi.v2._0_0.model.channel.message.CorrelationId +import com.asyncapi.v2._0_0.model.channel.message.Message +import com.asyncapi.v2._0_0.model.channel.operation.Operation +import com.asyncapi.v2._0_0.model.component.Components +import com.asyncapi.v2._0_0.model.info.Info +import com.asyncapi.v2._0_0.model.info.License +import com.asyncapi.v2._0_0.model.server.Server +import com.asyncapi.v2._0_0.model.server.ServerVariable +import com.asyncapi.v2.schema.Schema +import java.math.BigDecimal + +class ApplicationHeaders: AbstractExampleValidationTest() { + + override fun specificationLocation(): String = "/examples/v2.0.0/application-headers.yml" + + override fun expectedDefaultContentType(): String = "application/json" + + override fun expectedInfo(): Info { + return Info.builder() + .title("Application Headers example") + .version("1.0.0") + .description("A cut of the Streetlights API to test application header changes supporting") + .license(License( + "Apache 2.0", + "https://www.apache.org/licenses/LICENSE-2.0" + )) + .build() + } + + override fun expectedServers(): Map { + return mapOf( + Pair("production", Server.builder() + .url("test.mosquitto.org:{port}") + .protocol("mqtt") + .description("Test broker") + .variables(mapOf( + Pair("port", ServerVariable.builder() + .description("Secure connection (TLS) is available through port 8883.") + .defaultValue("1883") + .enumValues(listOf("1883", "8883")) + .build() + ) + )) + .build() + ) + ) + } + + override fun expectedChannels(): Map { + return mapOf( + Pair("smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured", ChannelItem.builder() + .parameters(mapOf( + Pair("streetlightId", Reference("#/components/parameters/streetlightId")) + )) + .publish(Operation.builder() + .summary("Inform about environmental lighting conditions of a particular streetlight.") + .operationId("receiveLightMeasurement") + .message(Reference("#/components/messages/lightMeasured")) + .build() + ) + .build() + ) + ) + } + + override fun expectedComponents(): Components? { + return Components.builder() + .messages(mapOf( + Pair("lightMeasured", Message.builder() + .name("lightMeasured") + .title("Light measured") + .summary("Inform about environmental lighting conditions of a particular streetlight.") + .correlationId(CorrelationId( + null, + "\$message.header#/MQMD/CorrelId" + )) + .contentType("application/json") + .headers(Schema.builder() + .type("object") + .properties(mapOf( + Pair("MQMD", Schema.builder() + .type("object") + .properties(mapOf( + Pair("CorrelId", Schema.builder() + .type("string") + .minLength(24) + .maxLength(24) + .format("binary") + .build() + ) + )) + .build() + ), + Pair("applicationInstanceId", Schema.builder() + .ref("#/components/schemas/applicationInstanceId") + .build() + ) + )) + .build() + ) + .payload(Schema.builder().ref("#/components/schemas/lightMeasuredPayload").build()) + .build() + ) + )) + .schemas(mapOf( + Pair("lightMeasuredPayload", Schema.builder() + .type("object") + .properties(mapOf( + Pair("lumens", Schema.builder() + .type("integer") + .minimum(BigDecimal.ZERO) + .description("Light intensity measured in lumens.") + .build() + ), + Pair("sentAt", Schema.builder() + .ref("#/components/schemas/sentAt") + .build() + ) + )) + .build() + ), + Pair("sentAt", Schema.builder() + .type("string") + .format("date-time") + .description("Date and time when the message was sent.") + .build() + ), + Pair("applicationInstanceId", Schema.builder() + .type("string") + .description("Unique identifier for a given instance of the publishing application") + .build() + ) + )) + .parameters(mapOf( + Pair("streetlightId", Parameter.builder() + .description("The ID of the streetlight.") + .schema(Schema.builder().type("string").build()) + .build() + ) + )) + .build() + } + +} \ No newline at end of file diff --git a/asyncapi-core/src/test/resources/examples/v2.0.0/application-headers.yml b/asyncapi-core/src/test/resources/examples/v2.0.0/application-headers.yml new file mode 100644 index 00000000..9d373776 --- /dev/null +++ b/asyncapi-core/src/test/resources/examples/v2.0.0/application-headers.yml @@ -0,0 +1,83 @@ +asyncapi: 2.0.0 +info: + title: Application Headers example + version: '1.0.0' + description: A cut of the Streetlights API to test application header changes supporting #112 + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0 + +servers: + production: + url: test.mosquitto.org:{port} + protocol: mqtt + description: Test broker + variables: + port: + description: Secure connection (TLS) is available through port 8883. + default: '1883' + enum: + - '1883' + - '8883' + +defaultContentType: application/json + +channels: + smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured: + parameters: + streetlightId: + $ref: '#/components/parameters/streetlightId' + publish: + summary: Inform about environmental lighting conditions of a particular streetlight. + operationId: receiveLightMeasurement + message: + $ref: '#/components/messages/lightMeasured' + +components: + messages: + lightMeasured: + name: lightMeasured + title: Light measured + summary: Inform about environmental lighting conditions of a particular streetlight. + correlationId: + location: "$message.header#/MQMD/CorrelId" + contentType: application/json + headers: + type: object + properties: + MQMD: + type: object + properties: + CorrelId: + type: string + minLength: 24 + maxLength: 24 + format: binary + applicationInstanceId: + $ref: "#/components/schemas/applicationInstanceId" + payload: + $ref: "#/components/schemas/lightMeasuredPayload" + + schemas: + lightMeasuredPayload: + type: object + properties: + lumens: + type: integer + minimum: 0 + description: Light intensity measured in lumens. + sentAt: + $ref: "#/components/schemas/sentAt" + sentAt: + type: string + format: date-time + description: Date and time when the message was sent. + applicationInstanceId: + description: Unique identifier for a given instance of the publishing application + type: string + + parameters: + streetlightId: + description: The ID of the streetlight. + schema: + type: string \ No newline at end of file