diff --git a/asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_6_0/Mercure.kt b/asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_6_0/Mercure.kt new file mode 100644 index 00000000..9bd85324 --- /dev/null +++ b/asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_6_0/Mercure.kt @@ -0,0 +1,112 @@ +package com.asyncapi.examples.v2._6_0 + +import com.asyncapi.v2.Reference +import com.asyncapi.v2._6_0.model.ExternalDocumentation +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 Mercure: AbstractExampleValidationTest() { + + override fun specificationLocation(): String = "/examples/v2.6.0/mercure.yml" + + override fun expectedDefaultContentType(): String = "application/ld+json" + + override fun expectedInfo(): Info { + return Info.builder() + .title("Mercure Hub Example") + .description("This example demonstrates how to define a Mercure hub.") + .version("1.0.0") + .build() + } + + override fun expectedServers(): Map { + return mapOf( + Pair("production", Server.builder() + .url("https://demo.mercure.rocks/.well-known/mercure") + .protocol("mercure") + .build() + ) + ) + } + + override fun expectedChannels(): Map { + return mapOf( + Pair("https://example.com/books/{id}", ChannelItem.builder() + .description("Every time a resource of type `http://schema.org/Book` is created or modified, a JSON-LD representation of the new version of this resource must be pushed in this Mercure topic.") + .parameters(mapOf( + Pair("id", Parameter.builder() + .schema(Schema.builder() + .type("integer") + .build() + ) + .build() + ) + )) + .subscribe(Operation.builder() + .message(Reference("#/components/messages/book")) + .build() + ) + .publish(Operation.builder() + .message(Reference("#/components/messages/book")) + .build() + ) + .build() + ) + ) + } + + override fun expectedComponents(): Components? { + return Components.builder() + .messages(mapOf( + Pair("book", Message.builder() + .summary("The content of a book resource.") + .externalDocs(ExternalDocumentation( + null, + "https://schema.org/Book" + )) + .payload(Schema.builder() + .type("object") + .properties(mapOf( + Pair("@id", Schema.builder() + .type("string") + .format("iri-reference") + .build() + ), + Pair("@type", Schema.builder() + .type("string") + .format("iri-reference") + .build() + ), + Pair("name", Schema.builder() + .type("string") + .build() + ), + Pair("isbn", Schema.builder() + .type("string") + .build() + ), + Pair("abstract", Schema.builder() + .type("string") + .build() + ), + )) + .build() + ) + .build() + ), + )) + .build() + } + +} \ No newline at end of file diff --git a/asyncapi-core/src/test/resources/examples/v2.6.0/mercure.yml b/asyncapi-core/src/test/resources/examples/v2.6.0/mercure.yml new file mode 100644 index 00000000..f296c003 --- /dev/null +++ b/asyncapi-core/src/test/resources/examples/v2.6.0/mercure.yml @@ -0,0 +1,49 @@ +asyncapi: "2.6.0" +info: + title: Mercure Hub Example + version: '1.0.0' + description: This example demonstrates how to define a Mercure hub. + +# While not mandatory, it's a best practice to use formats with hypermedia capabilities such as JSON-LD, Atom or HTML with the Mercure protocol +defaultContentType: application/ld+json + +servers: + production: + url: https://demo.mercure.rocks/.well-known/mercure + protocol: mercure + +channels: + 'https://example.com/books/{id}': + description: Every time a resource of type `http://schema.org/Book` is created or modified, a JSON-LD representation of the new version of this resource must be pushed in this Mercure topic. + parameters: + id: + schema: + type: integer + subscribe: + message: + $ref: '#/components/messages/book' + publish: + message: + $ref: '#/components/messages/book' + +components: + messages: + book: + summary: The content of a book resource. + externalDocs: + url: https://schema.org/Book + payload: + type: object + properties: + '@id': + type: string + format: iri-reference + '@type': + type: string + format: iri-reference + name: + type: string + isbn: + type: string + abstract: + type: string \ No newline at end of file