From 3dfe45871051955897405dfe78f8b60cc4743223 Mon Sep 17 00:00:00 2001 From: Yogesh Ananda Nikam Date: Mon, 23 Dec 2024 11:47:30 +0530 Subject: [PATCH] fix: Change the payload type in message example to object in v3_0_0 to fix the failure where the spec with an array payload was not getting parsed properly --- .../model/channel/message/MessageExample.java | 2 +- .../v3/_0_0/ArrayAsMessageAsyncAPI.kt | 100 ++++++++++++++++++ .../v3.0.0/message-of-array-type-asyncapi.yml | 39 +++++++ 3 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 asyncapi-core/src/test/kotlin/com/asyncapi/examples/v3/_0_0/ArrayAsMessageAsyncAPI.kt create mode 100644 asyncapi-core/src/test/resources/examples/v3.0.0/message-of-array-type-asyncapi.yml diff --git a/asyncapi-core/src/main/java/com/asyncapi/v3/_0_0/model/channel/message/MessageExample.java b/asyncapi-core/src/main/java/com/asyncapi/v3/_0_0/model/channel/message/MessageExample.java index 00baa026..ba7d9fe1 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/v3/_0_0/model/channel/message/MessageExample.java +++ b/asyncapi-core/src/main/java/com/asyncapi/v3/_0_0/model/channel/message/MessageExample.java @@ -30,7 +30,7 @@ public class MessageExample extends ExtendableObject { * The value of this field MUST validate against the Message {@link Message} payload field. */ @Nullable - public Map payload; + public Object payload; /** * A machine-friendly name. diff --git a/asyncapi-core/src/test/kotlin/com/asyncapi/examples/v3/_0_0/ArrayAsMessageAsyncAPI.kt b/asyncapi-core/src/test/kotlin/com/asyncapi/examples/v3/_0_0/ArrayAsMessageAsyncAPI.kt new file mode 100644 index 00000000..94ab1ca8 --- /dev/null +++ b/asyncapi-core/src/test/kotlin/com/asyncapi/examples/v3/_0_0/ArrayAsMessageAsyncAPI.kt @@ -0,0 +1,100 @@ +package com.asyncapi.examples.v3._0_0 + +import com.asyncapi.schemas.asyncapi.Reference +import com.asyncapi.v3._0_0.model.channel.Channel +import com.asyncapi.v3._0_0.model.channel.message.Message +import com.asyncapi.v3._0_0.model.component.Components +import com.asyncapi.v3._0_0.model.info.Info +import com.asyncapi.v3._0_0.model.operation.Operation +import com.asyncapi.v3._0_0.model.operation.OperationAction +import com.asyncapi.schemas.asyncapi.AsyncAPISchema +import com.asyncapi.v3._0_0.model.channel.message.MessageExample + +class ArrayAsMessageAsyncAPI: AbstractExampleValidationTest() { + + override fun specificationLocation(): String = "/examples/v3.0.0/message-of-array-type-asyncapi.yml" + + override fun expectedInfo(): Info { + return Info.builder() + .title("Message of array type example") + .version("1.0.0") + .build() + } + + override fun expectedServers(): Map = emptyMap() + + override fun expectedChannels(): Map { + return mapOf( + Pair("test", + Channel.builder() + .address("test") + .messages(mapOf( + Pair("testMessages", + Reference("#/components/messages/testMessages") + ) + )) + .build() + ) + ) + } + + override fun expectedOperations(): Map { + return mapOf( + Pair("onTestMsg", + Operation.builder() + .action(OperationAction.RECEIVE) + .channel(Reference("#/channels/test")) + .messages(listOf(Reference("#/channels/test/messages/testMessages"))) + .build() + ) + ) + } + + override fun expectedComponents(): Components { + return Components.builder() + .messages(mapOf( + Pair("testMessages", + Message.builder() + .payload( + Reference("#/components/schemas/objectWithKeyArray") + ) + .examples( + listOf( + MessageExample.builder().name("example1").payload( + listOf( + mapOf("key" to "value1"), + mapOf("key" to "value2") + ) + ).build(), + MessageExample.builder().name("example2").payload( + listOf( + mapOf("key" to "value3") + ) + ).build() + ) + ) + .build() + ) + )) + .schemas(mapOf( + Pair( + "objectWithKeyArray", AsyncAPISchema.builder() + .type("array") + .items( + AsyncAPISchema.builder() + .type("object") + .properties( + mapOf( + Pair("key", AsyncAPISchema.builder().type("string").build()) + ) + ) + .build() + ) + .build() + ) + )) + .build() + } + +} + diff --git a/asyncapi-core/src/test/resources/examples/v3.0.0/message-of-array-type-asyncapi.yml b/asyncapi-core/src/test/resources/examples/v3.0.0/message-of-array-type-asyncapi.yml new file mode 100644 index 00000000..03a4d532 --- /dev/null +++ b/asyncapi-core/src/test/resources/examples/v3.0.0/message-of-array-type-asyncapi.yml @@ -0,0 +1,39 @@ +asyncapi: 3.0.0 +info: + title: Message of array type example + version: 1.0.0 +channels: + test: + address: test + messages: + testMessages: + $ref: '#/components/messages/testMessages' +operations: + onTestMsg: + action: receive + channel: + $ref: '#/channels/test' + messages: + - $ref: '#/channels/test/messages/testMessages' +components: + messages: + testMessages: + payload: + $ref: '#/components/schemas/objectWithKeyArray' + examples: + - name: example1 + payload: + - key: "value1" + - key: "value2" + - name: example2 + payload: + - key: "value3" + schemas: + objectWithKeyArray: + type: array + items: + type: object + properties: + key: + type: string +