diff --git a/asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_6_0/StreetlightsKafka.kt b/asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_6_0/StreetlightsKafka.kt new file mode 100644 index 00000000..ede0887b --- /dev/null +++ b/asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_6_0/StreetlightsKafka.kt @@ -0,0 +1,289 @@ +package com.asyncapi.examples.v2._6_0 + +import com.asyncapi.v2.Reference +import com.asyncapi.v2._6_0.model.Tag +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.MessageTrait +import com.asyncapi.v2._6_0.model.channel.operation.Operation +import com.asyncapi.v2._6_0.model.channel.operation.OperationTrait +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.info.License +import com.asyncapi.v2._6_0.model.server.Server +import com.asyncapi.v2.binding.operation.kafka.KafkaOperationBinding +import com.asyncapi.v2.schema.Schema +import com.asyncapi.v2.security_scheme.SecurityScheme +import java.math.BigDecimal + +class StreetlightsKafka: AbstractExampleValidationTest() { + + override fun specificationLocation(): String = "/examples/v2.6.0/streetlights-kafka.yml" + + override fun expectedDefaultContentType(): String = "application/json" + + override fun expectedInfo(): Info { + return Info( + "Streetlights Kafka API", + "1.0.0", + "The Smartylighting Streetlights API allows you to remotely manage the city lights.\n\n" + + "### Check out its awesome features:\n\n" + + "* Turn a specific streetlight on/off \uD83C\uDF03\n" + + "* Dim a specific streetlight \uD83D\uDE0E\n" + + "* Receive real-time information about environmental lighting conditions \uD83D\uDCC8\n", + null, + null, + License("Apache 2.0", "https://www.apache.org/licenses/LICENSE-2.0"), + ) + } + + override fun expectedServers(): Map { + return mapOf( + Pair("scram-connections", Server.builder() + .url("test.mykafkacluster.org:18092") + .protocol("kafka-secure") + .description("Test broker secured with scramSha256") + .security(listOf( + mapOf(Pair("saslScram", emptyList())) + )) + .tags(listOf( + Tag.builder() + .name("env:test-scram") + .description("This environment is meant for running internal tests through scramSha256") + .build(), + Tag.builder() + .name("kind:remote") + .description("This server is a remote server. Not exposed by the application") + .build(), + Tag.builder() + .name("visibility:private") + .description("This resource is private and only available to certain users") + .build() + )) + .build() + ), + Pair("mtls-connections", Server.builder() + .url("test.mykafkacluster.org:28092") + .protocol("kafka-secure") + .description("Test broker secured with X509") + .security(listOf( + mapOf(Pair("certs", emptyList())) + )) + .tags(listOf( + Tag.builder() + .name("env:test-mtls") + .description("This environment is meant for running internal tests through mtls") + .build(), + Tag.builder() + .name("kind:remote") + .description("This server is a remote server. Not exposed by the application") + .build(), + Tag.builder() + .name("visibility:private") + .description("This resource is private and only available to certain users") + .build() + )) + .build() + ) + ) + } + + override fun expectedChannels(): Map { + return mapOf( + Pair("smartylighting.streetlights.1.0.event.{streetlightId}.lighting.measured", + ChannelItem.builder() + .description("The topic on which measured values may be produced and consumed.") + .parameters(mapOf(Pair("streetlightId", Reference("#/components/parameters/streetlightId")))) + .publish(Operation.builder() + .operationId("receiveLightMeasurement") + .summary("Inform about environmental lighting conditions of a particular streetlight.") + .traits(listOf(Reference("#/components/operationTraits/kafka"))) + .message(Reference("#/components/messages/lightMeasured")) + .build()) + .build() + ), + Pair("smartylighting.streetlights.1.0.action.{streetlightId}.turn.on", + ChannelItem.builder() + .parameters(mapOf(Pair("streetlightId", Reference("#/components/parameters/streetlightId")))) + .subscribe(Operation.builder() + .operationId("turnOn") + .traits(listOf(Reference("#/components/operationTraits/kafka"))) + .message(Reference("#/components/messages/turnOnOff")) + .build()) + .build() + ), + Pair("smartylighting.streetlights.1.0.action.{streetlightId}.turn.off", + ChannelItem.builder() + .parameters(mapOf(Pair("streetlightId", Reference("#/components/parameters/streetlightId")))) + .subscribe(Operation.builder() + .operationId("turnOff") + .traits(listOf(Reference("#/components/operationTraits/kafka"))) + .message(Reference("#/components/messages/turnOnOff")) + .build()) + .build() + ), + Pair("smartylighting.streetlights.1.0.action.{streetlightId}.dim", + ChannelItem.builder() + .parameters(mapOf(Pair("streetlightId", Reference("#/components/parameters/streetlightId")))) + .subscribe(Operation.builder() + .operationId("dimLight") + .traits(listOf(Reference("#/components/operationTraits/kafka"))) + .message(Reference("#/components/messages/dimLight")) + .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.") + .contentType("application/json") + .traits(listOf(Reference("#/components/messageTraits/commonHeaders"))) + .payload(Schema.builder().ref("#/components/schemas/lightMeasuredPayload").build()) + .build() + ), + Pair("turnOnOff", + Message.builder() + .name("turnOnOff") + .title("Turn on/off") + .summary("Command a particular streetlight to turn the lights on or off.") + .traits(listOf(Reference("#/components/messageTraits/commonHeaders"))) + .payload(Schema.builder().ref("#/components/schemas/turnOnOffPayload").build()) + .build() + ), + Pair("dimLight", + Message.builder() + .name("dimLight") + .title("Dim light") + .summary("Command a particular streetlight to dim the lights.") + .traits(listOf(Reference("#/components/messageTraits/commonHeaders"))) + .payload(Schema.builder().ref("#/components/schemas/dimLightPayload").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("turnOnOffPayload", + Schema.builder() + .type("object") + .properties(mapOf( + Pair("command", + Schema.builder() + .type("string") + .enumValue(listOf("on", "off")) + .description("Whether to turn on or off the light.") + .build() + ), + Pair("sentAt", + Schema.builder().ref("#/components/schemas/sentAt").build() + ) + )) + .build() + ), + Pair("dimLightPayload", + Schema.builder() + .type("object") + .properties(mapOf( + Pair("percentage", + Schema.builder() + .type("integer") + .minimum(BigDecimal.ZERO) + .maximum(BigDecimal.valueOf(100)) + .description("Percentage to which the light should be dimmed to.") + .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() + ) + )) + .securitySchemes(mapOf( + Pair("saslScram", + SecurityScheme.builder() + .type(SecurityScheme.Type.SCRAM_SHA256) + .description("Provide your username and password for SASL/SCRAM authentication") + .build() + ), + Pair("certs", + SecurityScheme( + SecurityScheme.Type.X509, + "Download the certificate files from service provider" + ) + ) + )) + .parameters(mapOf( + Pair("streetlightId", Parameter.builder() + .description("The ID of the streetlight.") + .schema(Schema.builder().type("string").build()) + .build() + ) + )) + .messageTraits(mapOf( + Pair("commonHeaders", + MessageTrait.builder() + .headers(Schema.builder() + .type("object") + .properties(mapOf( + Pair("my-app-header", Schema.builder() + .type("integer") + .minimum(BigDecimal.ZERO) + .maximum(BigDecimal.valueOf(100)) + .build() + ) + )) + .build() + ) + .build() + ) + )) + .operationTraits(mapOf( + Pair("kafka", + OperationTrait.builder() + .bindings(mapOf( + Pair("kafka", KafkaOperationBinding.builder() + .clientId(Schema.builder() + .type("string") + .enumValue(listOf("my-app-id")) + .build() + ) + .build() + ) + )) + .build() + ) + )) + .build() + } +} \ No newline at end of file diff --git a/asyncapi-core/src/test/resources/examples/v2.6.0/streetlights-kafka.yml b/asyncapi-core/src/test/resources/examples/v2.6.0/streetlights-kafka.yml new file mode 100644 index 00000000..28e66e34 --- /dev/null +++ b/asyncapi-core/src/test/resources/examples/v2.6.0/streetlights-kafka.yml @@ -0,0 +1,188 @@ +asyncapi: "2.6.0" +info: + title: Streetlights Kafka API + version: '1.0.0' + description: | + The Smartylighting Streetlights API allows you to remotely manage the city lights. + + ### Check out its awesome features: + + * Turn a specific streetlight on/off 🌃 + * Dim a specific streetlight 😎 + * Receive real-time information about environmental lighting conditions 📈 + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0 + +servers: + scram-connections: + url: test.mykafkacluster.org:18092 + protocol: kafka-secure + description: Test broker secured with scramSha256 + security: + - saslScram: [] + tags: + - name: "env:test-scram" + description: "This environment is meant for running internal tests through scramSha256" + - name: "kind:remote" + description: "This server is a remote server. Not exposed by the application" + - name: "visibility:private" + description: "This resource is private and only available to certain users" + mtls-connections: + url: test.mykafkacluster.org:28092 + protocol: kafka-secure + description: Test broker secured with X509 + security: + - certs: [] + tags: + - name: "env:test-mtls" + description: "This environment is meant for running internal tests through mtls" + - name: "kind:remote" + description: "This server is a remote server. Not exposed by the application" + - name: "visibility:private" + description: "This resource is private and only available to certain users" + +defaultContentType: application/json + +channels: + smartylighting.streetlights.1.0.event.{streetlightId}.lighting.measured: + description: The topic on which measured values may be produced and consumed. + parameters: + streetlightId: + $ref: '#/components/parameters/streetlightId' + publish: + summary: Inform about environmental lighting conditions of a particular streetlight. + operationId: receiveLightMeasurement + traits: + - $ref: '#/components/operationTraits/kafka' + message: + $ref: '#/components/messages/lightMeasured' + + smartylighting.streetlights.1.0.action.{streetlightId}.turn.on: + parameters: + streetlightId: + $ref: '#/components/parameters/streetlightId' + subscribe: + operationId: turnOn + traits: + - $ref: '#/components/operationTraits/kafka' + message: + $ref: '#/components/messages/turnOnOff' + + smartylighting.streetlights.1.0.action.{streetlightId}.turn.off: + parameters: + streetlightId: + $ref: '#/components/parameters/streetlightId' + subscribe: + operationId: turnOff + traits: + - $ref: '#/components/operationTraits/kafka' + message: + $ref: '#/components/messages/turnOnOff' + + smartylighting.streetlights.1.0.action.{streetlightId}.dim: + parameters: + streetlightId: + $ref: '#/components/parameters/streetlightId' + subscribe: + operationId: dimLight + traits: + - $ref: '#/components/operationTraits/kafka' + message: + $ref: '#/components/messages/dimLight' + +components: + messages: + lightMeasured: + name: lightMeasured + title: Light measured + summary: Inform about environmental lighting conditions of a particular streetlight. + contentType: application/json + traits: + - $ref: '#/components/messageTraits/commonHeaders' + payload: + $ref: "#/components/schemas/lightMeasuredPayload" + turnOnOff: + name: turnOnOff + title: Turn on/off + summary: Command a particular streetlight to turn the lights on or off. + traits: + - $ref: '#/components/messageTraits/commonHeaders' + payload: + $ref: "#/components/schemas/turnOnOffPayload" + dimLight: + name: dimLight + title: Dim light + summary: Command a particular streetlight to dim the lights. + traits: + - $ref: '#/components/messageTraits/commonHeaders' + payload: + $ref: "#/components/schemas/dimLightPayload" + + schemas: + lightMeasuredPayload: + type: object + properties: + lumens: + type: integer + minimum: 0 + description: Light intensity measured in lumens. + sentAt: + $ref: "#/components/schemas/sentAt" + turnOnOffPayload: + type: object + properties: + command: + type: string + enum: + - 'on' + - 'off' + description: Whether to turn on or off the light. + sentAt: + $ref: "#/components/schemas/sentAt" + dimLightPayload: + type: object + properties: + percentage: + type: integer + description: Percentage to which the light should be dimmed to. + minimum: 0 + maximum: 100 + sentAt: + $ref: "#/components/schemas/sentAt" + sentAt: + type: string + format: date-time + description: Date and time when the message was sent. + + securitySchemes: + saslScram: + type: scramSha256 + description: Provide your username and password for SASL/SCRAM authentication + certs: + type: X509 + description: Download the certificate files from service provider + + parameters: + streetlightId: + description: The ID of the streetlight. + schema: + type: string + + messageTraits: + commonHeaders: + headers: + type: object + properties: + my-app-header: + type: integer + minimum: 0 + maximum: 100 + + operationTraits: + kafka: + bindings: + kafka: + clientId: + type: string + enum: ['my-app-id'] \ No newline at end of file