Skip to content

Commit 3dfe458

Browse files
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
1 parent 4ab6473 commit 3dfe458

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed

asyncapi-core/src/main/java/com/asyncapi/v3/_0_0/model/channel/message/MessageExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class MessageExample extends ExtendableObject {
3030
* The value of this field MUST validate against the Message {@link Message} payload field.
3131
*/
3232
@Nullable
33-
public Map<String, Object> payload;
33+
public Object payload;
3434

3535
/**
3636
* A machine-friendly name.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.asyncapi.examples.v3._0_0
2+
3+
import com.asyncapi.schemas.asyncapi.Reference
4+
import com.asyncapi.v3._0_0.model.channel.Channel
5+
import com.asyncapi.v3._0_0.model.channel.message.Message
6+
import com.asyncapi.v3._0_0.model.component.Components
7+
import com.asyncapi.v3._0_0.model.info.Info
8+
import com.asyncapi.v3._0_0.model.operation.Operation
9+
import com.asyncapi.v3._0_0.model.operation.OperationAction
10+
import com.asyncapi.schemas.asyncapi.AsyncAPISchema
11+
import com.asyncapi.v3._0_0.model.channel.message.MessageExample
12+
13+
class ArrayAsMessageAsyncAPI: AbstractExampleValidationTest() {
14+
15+
override fun specificationLocation(): String = "/examples/v3.0.0/message-of-array-type-asyncapi.yml"
16+
17+
override fun expectedInfo(): Info {
18+
return Info.builder()
19+
.title("Message of array type example")
20+
.version("1.0.0")
21+
.build()
22+
}
23+
24+
override fun expectedServers(): Map<String, Any> = emptyMap()
25+
26+
override fun expectedChannels(): Map<String, Any> {
27+
return mapOf(
28+
Pair("test",
29+
Channel.builder()
30+
.address("test")
31+
.messages(mapOf(
32+
Pair("testMessages",
33+
Reference("#/components/messages/testMessages")
34+
)
35+
))
36+
.build()
37+
)
38+
)
39+
}
40+
41+
override fun expectedOperations(): Map<String, Any> {
42+
return mapOf(
43+
Pair("onTestMsg",
44+
Operation.builder()
45+
.action(OperationAction.RECEIVE)
46+
.channel(Reference("#/channels/test"))
47+
.messages(listOf(Reference("#/channels/test/messages/testMessages")))
48+
.build()
49+
)
50+
)
51+
}
52+
53+
override fun expectedComponents(): Components {
54+
return Components.builder()
55+
.messages(mapOf(
56+
Pair("testMessages",
57+
Message.builder()
58+
.payload(
59+
Reference("#/components/schemas/objectWithKeyArray")
60+
)
61+
.examples(
62+
listOf(
63+
MessageExample.builder().name("example1").payload(
64+
listOf(
65+
mapOf("key" to "value1"),
66+
mapOf("key" to "value2")
67+
)
68+
).build(),
69+
MessageExample.builder().name("example2").payload(
70+
listOf(
71+
mapOf("key" to "value3")
72+
)
73+
).build()
74+
)
75+
)
76+
.build()
77+
)
78+
))
79+
.schemas(mapOf(
80+
Pair(
81+
"objectWithKeyArray", AsyncAPISchema.builder()
82+
.type("array")
83+
.items(
84+
AsyncAPISchema.builder()
85+
.type("object")
86+
.properties(
87+
mapOf(
88+
Pair("key", AsyncAPISchema.builder().type("string").build())
89+
)
90+
)
91+
.build()
92+
)
93+
.build()
94+
)
95+
))
96+
.build()
97+
}
98+
99+
}
100+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
asyncapi: 3.0.0
2+
info:
3+
title: Message of array type example
4+
version: 1.0.0
5+
channels:
6+
test:
7+
address: test
8+
messages:
9+
testMessages:
10+
$ref: '#/components/messages/testMessages'
11+
operations:
12+
onTestMsg:
13+
action: receive
14+
channel:
15+
$ref: '#/channels/test'
16+
messages:
17+
- $ref: '#/channels/test/messages/testMessages'
18+
components:
19+
messages:
20+
testMessages:
21+
payload:
22+
$ref: '#/components/schemas/objectWithKeyArray'
23+
examples:
24+
- name: example1
25+
payload:
26+
- key: "value1"
27+
- key: "value2"
28+
- name: example2
29+
payload:
30+
- key: "value3"
31+
schemas:
32+
objectWithKeyArray:
33+
type: array
34+
items:
35+
type: object
36+
properties:
37+
key:
38+
type: string
39+

0 commit comments

Comments
 (0)