Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,17 @@ private static Set<String> findUnmarkedNestedSchemas(
*/
private static Set<String> findUnmarkedNestedSchemasForAsyncAPISchema(
MarkingContext markingContext, SchemaObject schema) {
final Stream<ComponentSchema> propertySchemas;
if (schema.getProperties() != null) {
propertySchemas = schema.getProperties().values().stream()
.filter(el -> el instanceof ComponentSchema)
.map(el -> (ComponentSchema) el);
} else {
propertySchemas = Stream.empty();
}
Stream<ComponentSchema> propertySchemas = schema.getProperties() == null
? Stream.empty()
: schema.getProperties().values().stream()
.filter(ComponentSchema.class::isInstance)
.map(ComponentSchema.class::cast)
.flatMap(el -> {
Stream<ComponentSchema> base = Stream.of(el);
ComponentSchema items =
el.getSchema() != null ? el.getSchema().getItems() : null;
return items != null ? Stream.concat(base, Stream.of(items)) : base;
});

Stream<ComponentSchema> referencedSchemas = Stream.of(schema.getAllOf(), schema.getAnyOf(), schema.getOneOf())
.filter(Objects::nonNull)
Expand Down Expand Up @@ -286,12 +289,13 @@ private static Set<String> findUnmarkedNestedSchemasForAsyncAPISchema(
*/
private static Set<String> findUnmarkedNestedSchemasForOpenAPISchema(
MarkingContext markingContext, Schema<?> openapiSchema) {
final Stream<Schema> propertySchemas;
if (openapiSchema.getProperties() != null) {
propertySchemas = openapiSchema.getProperties().values().stream();
} else {
propertySchemas = Stream.empty();
}
Stream<Schema> propertySchemas = openapiSchema.getProperties() == null
? Stream.empty()
: openapiSchema.getProperties().values().stream().flatMap(schema -> {
Stream<Schema> base = Stream.of(schema);
Schema<?> items = schema.getItems();
return items != null ? Stream.concat(base, Stream.of(items)) : base;
});

Stream<Schema> referencedSchemas = Stream.of(
openapiSchema.getAllOf(), openapiSchema.getAnyOf(), openapiSchema.getOneOf())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

import io.github.springwolf.asyncapi.v3.model.AsyncAPI;
import io.github.springwolf.asyncapi.v3.model.channel.message.MessageObject;
import io.github.springwolf.asyncapi.v3.model.components.ComponentSchema;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaReference;
import io.github.springwolf.core.asyncapi.AsyncApiService;
import io.github.springwolf.core.fixtures.SpringwolfIntegrationTest;
import io.github.springwolf.core.integrationtests.application.listener.ListenerApplication;
import io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -16,51 +17,66 @@
import static org.assertj.core.api.Assertions.assertThat;

@Nested
@SpringBootTest(classes = ListenerApplication.class)
@SpringBootTest(classes = ComplexSchemaApplication.class)
@SpringwolfIntegrationTest
@TestPropertySource(
properties = {
"springwolf.docket.group-configs[0].group=FooMessage",
"springwolf.docket.group-configs[0].group=UserMessage",
"springwolf.docket.group-configs[0].action-to-match=",
"springwolf.docket.group-configs[0].channel-name-to-match=",
"springwolf.docket.group-configs[0].message-name-to-match=.*Foo",
"springwolf.docket.group-configs[0].message-name-to-match=.*User",
"springwolf.docket.group-configs[1].group=all & everything",
"springwolf.docket.group-configs[1].action-to-match=",
"springwolf.docket.group-configs[1].channel-name-to-match=.*",
"springwolf.docket.group-configs[1].message-name-to-match=",
})
class GroupingIntegrationTest {
class GroupingWithComplexSchemaIntegrationTest {
@Autowired
private AsyncApiService asyncApiService;

@Test
void shouldFindOnlyForGroupFoo() {
AsyncAPI asyncAPI = asyncApiService.getForGroupName("FooMessage").get();
void shouldFindOnlyForGroupUserMessage() {
AsyncAPI asyncAPI = asyncApiService.getForGroupName("UserMessage").get();

assertThat(asyncAPI.getChannels().keySet()).containsExactlyInAnyOrder("listener-channel");
assertThat(asyncAPI.getChannels().get("listener-channel").getMessages())
assertThat(asyncAPI.getChannels().keySet()).containsExactlyInAnyOrder("publisher-channel2");
assertThat(asyncAPI.getChannels().get("publisher-channel2").getMessages())
.containsOnlyKeys(
"io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Foo");
"io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.User");
assertThat(asyncAPI.getOperations())
.containsOnlyKeys("listener-channel_receive_listen3", "listener-channel_receive_listen4");
.containsOnlyKeys("publisher-channel2_send_publish1", "publisher-channel2_send_publish2");
assertThat(asyncAPI.getComponents().getMessages())
.containsOnlyKeys(
"io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Foo");
"io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.User");
assertThat(asyncAPI.getComponents().getSchemas())
.containsOnlyKeys(
"HeadersNotDocumented",
"io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Bar",
"io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Foo");
"io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.User",
"io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.Address",
"io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.City");

MessageObject fooMessage = (MessageObject) asyncAPI.getComponents()
.getMessages()
.get("io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Foo");
assertThat(fooMessage.getPayload().getMultiFormatSchema().getSchema()).isInstanceOf(SchemaReference.class);
SchemaReference fooSchemaRef =
(SchemaReference) fooMessage.getPayload().getMultiFormatSchema().getSchema();
assertThat(fooSchemaRef.getRef())
MessageObject userMessage = (MessageObject)
asyncAPI.getComponents()
.getMessages()
.get(
"io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.User");
assertThat(userMessage.getPayload().getMultiFormatSchema().getSchema()).isInstanceOf(SchemaReference.class);
SchemaReference userMessageToSchemaRef = (SchemaReference)
userMessage.getPayload().getMultiFormatSchema().getSchema();
assertThat(userMessageToSchemaRef.getRef())
.isEqualTo(
"#/components/schemas/io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Foo");
"#/components/schemas/io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.User");

// Verify that collection property is correctly represented using `items`
ComponentSchema addressesSchema = (ComponentSchema) asyncAPI.getComponents()
.getSchemas()
.get(
"io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.User")
.getSchema()
.getProperties()
.get("addresses");
assertThat(addressesSchema.getSchema().getItems().getReference().getRef())
.isEqualTo(
"#/components/schemas/io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.Address");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.springwolf.core.integrationtests.application.complexSchema;

import io.github.springwolf.core.asyncapi.annotations.AsyncOperation;
import io.github.springwolf.core.asyncapi.annotations.AsyncPublisher;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.Collection;
import java.util.List;

@SpringBootApplication
public class ComplexSchemaApplication {

@AsyncPublisher(operation = @AsyncOperation(channelName = "publisher-channel"))
public void publish(List<String> payload) {}

@Bean
public ComplexPublisher complexPublisher() {
return new ComplexPublisher();
}

public static class ComplexPublisher {
@AsyncPublisher(operation = @AsyncOperation(channelName = "publisher-channel2"))
public void publish1(User payload) {}

@AsyncPublisher(operation = @AsyncOperation(channelName = "publisher-channel2"))
public void publish2(List<User> payload) {}

public record User(String name, Integer age, Collection<Address> addresses) {}

public record Address(String streetName, String addition, City city) {}

public record City(String zipCode, String name) {}
}
}
Loading