-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a failing test to demonstrate the failure when the spec contains …
…an example where the payload is an array instead of an object
- Loading branch information
1 parent
4ab6473
commit ade6db2
Showing
2 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
asyncapi-core/src/test/kotlin/com/asyncapi/examples/v3/_0_0/ArrayAsMessageAsyncAPI.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
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 | ||
|
||
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<String, Any> = emptyMap() | ||
|
||
override fun expectedChannels(): Map<String, Any> { | ||
return mapOf( | ||
Pair("test", | ||
Channel.builder() | ||
.address("test") | ||
.messages(mapOf( | ||
Pair("testMessages", | ||
Reference("#/components/messages/testMessages") | ||
) | ||
)) | ||
.build() | ||
) | ||
) | ||
} | ||
|
||
override fun expectedOperations(): Map<String, Any> { | ||
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( | ||
AsyncAPISchema.builder() | ||
.oneOf(listOf( | ||
AsyncAPISchema.builder().ref("#/components/schemas/objectWithKey").build(), | ||
AsyncAPISchema.builder().ref("#/components/schemas/objectWithKey2").build() | ||
)) | ||
.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() | ||
} | ||
|
||
} | ||
|
39 changes: 39 additions & 0 deletions
39
asyncapi-core/src/test/resources/examples/v3.0.0/message-of-array-type-asyncapi.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|