From adc1d80a3301f5d8193f65063c639c17d725e010 Mon Sep 17 00:00:00 2001 From: sam0r040 <93372330+sam0r040@users.noreply.github.com> Date: Fri, 27 Oct 2023 17:47:41 +0200 Subject: [PATCH] feat(core): add configuration option to use fully qualified names in schemas (#393) * feat(core): add configuration option to use fully qualified names in schemas default is false (unchanged behavior) Co-authored-by: Timon Back * feat(core): rebase to master * test(core): update DefaultSchemaServiceTest * feat(example): Use fqn in example * feat(ui): show only schema type (not fqn) in ui * feat(core): Use class name for title, not fqn * feat(ui): ui can show fqn payload * test(plugin): add SpringwolfConfigProperties in test context * feat(core): use swagger-core getUseFqn to reset fqn * test(amqp): update asyncapi_withdocketfromenvironment.json after rebase --------- Co-authored-by: Timon Back Co-authored-by: Timon Back --- .../SpringwolfAutoConfiguration.java | 7 +- .../AbstractClassLevelListenerScanner.java | 2 +- .../AbstractMethodLevelListenerScanner.java | 2 +- .../AbstractOperationDataScanner.java | 2 +- .../SpringwolfConfigProperties.java | 9 + .../schemas/DefaultSchemasService.java | 28 ++- ...odLevelListenerScannerIntegrationTest.java | 8 +- ...erOperationDataScannerIntegrationTest.java | 14 +- ...erOperationDataScannerIntegrationTest.java | 14 +- ...tenerAnnotationScannerIntegrationTest.java | 2 + ...isherAnnotationScannerIntegrationTest.java | 11 +- .../schemas/DefaultSchemasServiceTest.java | 32 ++- .../src/main/resources/application.properties | 1 + .../src/test/resources/asyncapi.json | 30 +-- .../asyncapi_withdocketfromenvironment.json | 26 +- .../src/main/resources/application.properties | 1 + .../src/test/resources/asyncapi.json | 238 +++++++++--------- .../src/main/resources/application.properties | 1 + .../src/test/resources/asyncapi.json | 22 +- .../src/main/resources/application.properties | 1 + .../src/test/resources/asyncapi.json | 22 +- ...lRabbitListenerScannerIntegrationTest.java | 8 +- ...lRabbitListenerScannerIntegrationTest.java | 2 + ...elKafkaListenerScannerIntegrationTest.java | 8 +- ...elKafkaListenerScannerIntegrationTest.java | 8 +- ...evelSqsListenerScannerIntegrationTest.java | 2 + .../channel-main/channel-main.component.css | 7 - .../channel-main/channel-main.component.html | 20 +- .../channel-main/channel-main.component.ts | 14 +- .../src/app/channels/channels.component.html | 2 +- .../app/schemas/schema/schema.component.html | 6 +- .../src/app/schemas/schemas.component.css | 7 + .../src/app/schemas/schemas.component.html | 7 +- .../src/app/shared/asyncapi-mapper.service.ts | 7 +- .../src/app/shared/models/channel.model.ts | 2 + .../src/app/shared/models/schema.model.ts | 3 + 36 files changed, 347 insertions(+), 229 deletions(-) diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfAutoConfiguration.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfAutoConfiguration.java index 0e59ba2d7..ab9d3ca81 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfAutoConfiguration.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfAutoConfiguration.java @@ -67,8 +67,11 @@ public ChannelsService channelsService(List channelsS @Bean @ConditionalOnMissingBean - public SchemasService schemasService(List modelConverters, ExampleGenerator exampleGenerator) { - return new DefaultSchemasService(modelConverters, exampleGenerator); + public SchemasService schemasService( + List modelConverters, + ExampleGenerator exampleGenerator, + SpringwolfConfigProperties springwolfConfigProperties) { + return new DefaultSchemasService(modelConverters, exampleGenerator, springwolfConfigProperties); } @Bean diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/AbstractClassLevelListenerScanner.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/AbstractClassLevelListenerScanner.java index 7f9b3d6bb..67408b10d 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/AbstractClassLevelListenerScanner.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/AbstractClassLevelListenerScanner.java @@ -178,7 +178,7 @@ private Message buildMessage(Method method) { return Message.builder() .name(payloadType.getName()) - .title(modelName) + .title(payloadType.getSimpleName()) .payload(PayloadReference.fromModelName(modelName)) .headers(HeaderReference.fromModelName(headerModelName)) .bindings(buildMessageBinding(method)) diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/AbstractMethodLevelListenerScanner.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/AbstractMethodLevelListenerScanner.java index 3bbb6af54..18ab12b87 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/AbstractMethodLevelListenerScanner.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/AbstractMethodLevelListenerScanner.java @@ -123,7 +123,7 @@ private ChannelItem buildChannel( Message message = Message.builder() .name(payloadType.getName()) - .title(modelName) + .title(payloadType.getSimpleName()) .payload(PayloadReference.fromModelName(modelName)) .headers(HeaderReference.fromModelName(headerModelName)) .bindings(messageBinding) diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/AbstractOperationDataScanner.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/AbstractOperationDataScanner.java index 907c3443a..f911998ea 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/AbstractOperationDataScanner.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/AbstractOperationDataScanner.java @@ -109,7 +109,7 @@ private Message buildMessage(OperationData operationData) { var builder = Message.builder() .name(payloadType.getName()) - .title(modelName) + .title(payloadType.getSimpleName()) .description(description) .payload(PayloadReference.fromModelName(modelName)) .headers(HeaderReference.fromModelName(headerModelName)) diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfConfigProperties.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfConfigProperties.java index 7ff503c81..8cb676435 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfConfigProperties.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfConfigProperties.java @@ -42,6 +42,15 @@ public enum InitMode { */ private InitMode initMode = InitMode.FAIL_FAST; + /** + * Use fully qualified names for the schema classes + * + * Example: + * useFqn = true -> java.lang.String + * useFqn = false -> String + */ + private boolean useFqn = false; + @Nullable private Endpoint endpoint; diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasService.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasService.java index 300145e4e..c285c8472 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasService.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasService.java @@ -2,9 +2,11 @@ package io.github.stavshamir.springwolf.schemas; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.AsyncHeaders; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; import io.github.stavshamir.springwolf.schemas.example.ExampleGenerator; import io.swagger.v3.core.converter.ModelConverter; import io.swagger.v3.core.converter.ModelConverters; +import io.swagger.v3.core.jackson.TypeNameResolver; import io.swagger.v3.oas.models.media.MapSchema; import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.media.StringSchema; @@ -15,20 +17,26 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Function; @Slf4j public class DefaultSchemasService implements SchemasService { private final ModelConverters converter = ModelConverters.getInstance(); private final ExampleGenerator exampleGenerator; + private final SpringwolfConfigProperties properties; private final Map definitions = new HashMap<>(); private Map finalizedDefinitions = null; - public DefaultSchemasService(List externalModelConverters, ExampleGenerator exampleGenerator) { + public DefaultSchemasService( + List externalModelConverters, + ExampleGenerator exampleGenerator, + SpringwolfConfigProperties properties) { externalModelConverters.forEach(converter::addConverter); this.exampleGenerator = exampleGenerator; + this.properties = properties; } @Override @@ -61,10 +69,10 @@ public String register(AsyncHeaders headers) { public String register(Class type) { log.debug("Registering schema for {}", type.getSimpleName()); - Map schemas = converter.readAll(type); + Map schemas = runWithFqnSetting((unused) -> converter.readAll(type)); this.definitions.putAll(schemas); - if (schemas.size() == 0 && type.equals(String.class)) { + if (schemas.isEmpty() && type.equals(String.class)) { this.definitions.put("String", new StringSchema()); return "String"; } @@ -81,6 +89,20 @@ public String register(Class type) { return type.getSimpleName(); } + private R runWithFqnSetting(Function callable) { + boolean previousUseFqn = TypeNameResolver.std.getUseFqn(); + if (properties.isUseFqn()) { + TypeNameResolver.std.setUseFqn(true); + } + + R result = callable.apply(null); + + if (properties.isUseFqn()) { + TypeNameResolver.std.setUseFqn(previousUseFqn); + } + return result; + } + private void removeSwaggerSchemaFields(String schemaName, Schema schema) { schema.setAdditionalProperties(null); diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/TestMethodLevelListenerScannerIntegrationTest.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/TestMethodLevelListenerScannerIntegrationTest.java index d9790d143..c2409a379 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/TestMethodLevelListenerScannerIntegrationTest.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/TestMethodLevelListenerScannerIntegrationTest.java @@ -9,6 +9,7 @@ import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.AsyncHeaders; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.HeaderReference; import io.github.stavshamir.springwolf.configuration.AsyncApiDocket; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; import io.github.stavshamir.springwolf.schemas.DefaultSchemasService; import io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator; import lombok.Data; @@ -33,7 +34,12 @@ @ExtendWith(SpringExtension.class) @ContextConfiguration( - classes = {TestMethodLevelListenerScanner.class, DefaultSchemasService.class, ExampleJsonGenerator.class}) + classes = { + TestMethodLevelListenerScanner.class, + DefaultSchemasService.class, + ExampleJsonGenerator.class, + SpringwolfConfigProperties.class + }) class TestMethodLevelListenerScannerIntegrationTest { @Autowired diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/ConsumerOperationDataScannerIntegrationTest.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/ConsumerOperationDataScannerIntegrationTest.java index 9ad7b544b..07b46bf47 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/ConsumerOperationDataScannerIntegrationTest.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/ConsumerOperationDataScannerIntegrationTest.java @@ -14,6 +14,7 @@ import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.HeaderReference; import io.github.stavshamir.springwolf.configuration.AsyncApiDocket; import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; import io.github.stavshamir.springwolf.schemas.DefaultSchemasService; import io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator; import io.swagger.v3.oas.annotations.media.Schema; @@ -35,7 +36,12 @@ @ExtendWith(SpringExtension.class) @ContextConfiguration( - classes = {ConsumerOperationDataScanner.class, DefaultSchemasService.class, ExampleJsonGenerator.class}) + classes = { + ConsumerOperationDataScanner.class, + DefaultSchemasService.class, + ExampleJsonGenerator.class, + SpringwolfConfigProperties.class, + }) class ConsumerOperationDataScannerIntegrationTest { @Autowired @@ -73,8 +79,8 @@ void allFieldsConsumerData() { .bindings(Map.of("kafka", new KafkaOperationBinding())) .message(Message.builder() .name(ExamplePayloadDto.class.getName()) - .description(messageDescription) .title(ExamplePayloadDto.class.getSimpleName()) + .description(messageDescription) .payload(PayloadReference.fromModelName(ExamplePayloadDto.class.getSimpleName())) .headers(HeaderReference.fromModelName(AsyncHeaders.NOT_DOCUMENTED.getSchemaName())) .bindings(Map.of("kafka", new KafkaMessageBinding())) @@ -144,16 +150,16 @@ void multipleConsumersForSameTopic() { Set messages = Set.of( Message.builder() .name(ExamplePayloadDto.class.getName()) - .description(messageDescription1) .title(ExamplePayloadDto.class.getSimpleName()) + .description(messageDescription1) .payload(PayloadReference.fromModelName(ExamplePayloadDto.class.getSimpleName())) .headers(HeaderReference.fromModelName(AsyncHeaders.NOT_DOCUMENTED.getSchemaName())) .bindings(Map.of("kafka", new KafkaMessageBinding())) .build(), Message.builder() .name(AnotherExamplePayloadDto.class.getName()) - .description(messageDescription2) .title(AnotherExamplePayloadDto.class.getSimpleName()) + .description(messageDescription2) .payload(PayloadReference.fromModelName(AnotherExamplePayloadDto.class.getSimpleName())) .headers(HeaderReference.fromModelName(AsyncHeaders.NOT_USED.getSchemaName())) .bindings(Map.of("kafka", new KafkaMessageBinding())) diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/ProducerOperationDataScannerIntegrationTest.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/ProducerOperationDataScannerIntegrationTest.java index 0f939f91b..4fff0c5dd 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/ProducerOperationDataScannerIntegrationTest.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/ProducerOperationDataScannerIntegrationTest.java @@ -14,6 +14,7 @@ import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.HeaderReference; import io.github.stavshamir.springwolf.configuration.AsyncApiDocket; import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; import io.github.stavshamir.springwolf.schemas.DefaultSchemasService; import io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator; import io.swagger.v3.oas.annotations.media.Schema; @@ -35,7 +36,12 @@ @ExtendWith(SpringExtension.class) @ContextConfiguration( - classes = {ProducerOperationDataScanner.class, DefaultSchemasService.class, ExampleJsonGenerator.class}) + classes = { + ProducerOperationDataScanner.class, + DefaultSchemasService.class, + ExampleJsonGenerator.class, + SpringwolfConfigProperties.class, + }) class ProducerOperationDataScannerIntegrationTest { @Autowired @@ -73,8 +79,8 @@ void allFieldsProducerData() { .bindings(Map.of("kafka", new KafkaOperationBinding())) .message(Message.builder() .name(ExamplePayloadDto.class.getName()) - .description(messageDescription1) .title(ExamplePayloadDto.class.getSimpleName()) + .description(messageDescription1) .payload(PayloadReference.fromModelName(ExamplePayloadDto.class.getSimpleName())) .headers(HeaderReference.fromModelName(AsyncHeaders.NOT_DOCUMENTED.getSchemaName())) .bindings(Map.of("kafka", new KafkaMessageBinding())) @@ -144,16 +150,16 @@ void multipleProducersForSameTopic() { Set messages = Set.of( Message.builder() .name(ExamplePayloadDto.class.getName()) - .description(messageDescription1) .title(ExamplePayloadDto.class.getSimpleName()) + .description(messageDescription1) .payload(PayloadReference.fromModelName(ExamplePayloadDto.class.getSimpleName())) .headers(HeaderReference.fromModelName(AsyncHeaders.NOT_DOCUMENTED.getSchemaName())) .bindings(Map.of("kafka", new KafkaMessageBinding())) .build(), Message.builder() .name(AnotherExamplePayloadDto.class.getName()) - .description(messageDescription2) .title(AnotherExamplePayloadDto.class.getSimpleName()) + .description(messageDescription2) .payload(PayloadReference.fromModelName(AnotherExamplePayloadDto.class.getSimpleName())) .headers(HeaderReference.fromModelName(AsyncHeaders.NOT_USED.getSchemaName())) .bindings(Map.of("kafka", new KafkaMessageBinding())) diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncListenerAnnotationScannerIntegrationTest.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncListenerAnnotationScannerIntegrationTest.java index 31e777733..6bd75763d 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncListenerAnnotationScannerIntegrationTest.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncListenerAnnotationScannerIntegrationTest.java @@ -9,6 +9,7 @@ import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.PayloadReference; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.AsyncHeaders; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.HeaderReference; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; import io.github.stavshamir.springwolf.schemas.DefaultSchemasService; import io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator; import io.swagger.v3.oas.annotations.media.Schema; @@ -36,6 +37,7 @@ AsyncListenerAnnotationScanner.class, DefaultSchemasService.class, ExampleJsonGenerator.class, + SpringwolfConfigProperties.class, TestOperationBindingProcessor.class }) @TestPropertySource(properties = {"test.property.test-channel=test-channel", "test.property.description=description"}) diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncPublisherAnnotationScannerIntegrationTest.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncPublisherAnnotationScannerIntegrationTest.java index 5b6f0b96a..53a995f60 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncPublisherAnnotationScannerIntegrationTest.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncPublisherAnnotationScannerIntegrationTest.java @@ -9,6 +9,7 @@ import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.PayloadReference; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.AsyncHeaders; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.HeaderReference; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; import io.github.stavshamir.springwolf.schemas.DefaultSchemasService; import io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator; import lombok.Data; @@ -35,6 +36,7 @@ AsyncPublisherAnnotationScanner.class, DefaultSchemasService.class, ExampleJsonGenerator.class, + SpringwolfConfigProperties.class, TestOperationBindingProcessor.class }) @TestPropertySource(properties = {"test.property.test-channel=test-channel", "test.property.description=description"}) @@ -72,8 +74,7 @@ void scan_componentHasPublisherMethod() { Message message = Message.builder() .name(SimpleFoo.class.getName()) .title(SimpleFoo.class.getSimpleName()) - // Message description is not supported yet - // .description("") + .description(null) .payload(PayloadReference.fromModelName(SimpleFoo.class.getSimpleName())) .headers(HeaderReference.fromModelName(AsyncHeaders.NOT_DOCUMENTED.getSchemaName())) .bindings(EMPTY_MAP) @@ -104,8 +105,7 @@ void scan_componentHasPublisherMethodWithAllAttributes() { Message message = Message.builder() .name(SimpleFoo.class.getName()) .title(SimpleFoo.class.getSimpleName()) - // Message description is not supported yet - // .description("description") + .description(null) .payload(PayloadReference.fromModelName(SimpleFoo.class.getSimpleName())) .headers(HeaderReference.fromModelName("TestSchema")) .bindings(EMPTY_MAP) @@ -136,8 +136,7 @@ void scan_componentHasMultiplePublisherAnnotations() { Message message = Message.builder() .name(SimpleFoo.class.getName()) .title(SimpleFoo.class.getSimpleName()) - // Message description is not supported yet - // .description("") + .description(null) .payload(PayloadReference.fromModelName(SimpleFoo.class.getSimpleName())) .headers(HeaderReference.fromModelName(AsyncHeaders.NOT_DOCUMENTED.getSchemaName())) .bindings(EMPTY_MAP) diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasServiceTest.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasServiceTest.java index eb18ed0aa..5bc2fa108 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasServiceTest.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasServiceTest.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; import io.github.stavshamir.springwolf.schemas.example.ExampleGenerator; import io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator; import io.swagger.v3.core.util.Json; @@ -32,7 +33,8 @@ class DefaultSchemasServiceTest { private final ExampleGenerator exampleGenerator = new ExampleJsonGenerator(); - private final SchemasService schemasService = new DefaultSchemasService(List.of(), exampleGenerator); + private final SchemasService schemasService = + new DefaultSchemasService(List.of(), exampleGenerator, new SpringwolfConfigProperties()); private static final ObjectMapper objectMapper = Json.mapper().enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS); @@ -91,6 +93,28 @@ void classWithSchemaAnnotation() { assertThat(modelName).isEqualTo("DifferentName"); } + @Test + void getDefinitionWithFqnClassName() throws IOException { + // given + SpringwolfConfigProperties properties = new SpringwolfConfigProperties(); + properties.setUseFqn(true); + + SchemasService schemasServiceWithFqn = new DefaultSchemasService(List.of(), exampleGenerator, properties); + + // when + Class clazz = + OneFieldFooWithFqn.class; // swagger seems to cache results. Therefore, a new class must be used. + schemasServiceWithFqn.register(clazz); + String actualDefinitions = + objectMapper.writer(printer).writeValueAsString(schemasServiceWithFqn.getDefinitions()); + + // then + System.out.println("Got: " + actualDefinitions); + String fqnClassName = clazz.getName(); + assertThat(actualDefinitions).contains(fqnClassName); + assertThat(fqnClassName.length()).isGreaterThan(clazz.getSimpleName().length()); + } + private String jsonResource(String path) throws IOException { InputStream s = this.getClass().getResourceAsStream(path); return new String(s.readAllBytes(), StandardCharsets.UTF_8); @@ -103,6 +127,12 @@ private static class SimpleFoo { private boolean b; } + @Data + @NoArgsConstructor + private static class OneFieldFooWithFqn { + private String s; + } + @Data @NoArgsConstructor @Schema(description = "foo model") diff --git a/springwolf-examples/springwolf-amqp-example/src/main/resources/application.properties b/springwolf-examples/springwolf-amqp-example/src/main/resources/application.properties index c0716f620..a85a87524 100644 --- a/springwolf-examples/springwolf-amqp-example/src/main/resources/application.properties +++ b/springwolf-examples/springwolf-amqp-example/src/main/resources/application.properties @@ -28,6 +28,7 @@ springwolf.docket.info.license.name=Apache License 2.0 springwolf.docket.info.license.extension-fields.x-desc=some description springwolf.docket.servers.amqp.protocol=amqp springwolf.docket.servers.amqp.url=${spring.rabbitmq.host}:${spring.rabbitmq.port} +springwolf.use-fqn=true springwolf.plugin.amqp.publishing.enabled=true diff --git a/springwolf-examples/springwolf-amqp-example/src/test/resources/asyncapi.json b/springwolf-examples/springwolf-amqp-example/src/test/resources/asyncapi.json index b607d33f4..092aaec00 100644 --- a/springwolf-examples/springwolf-amqp-example/src/test/resources/asyncapi.json +++ b/springwolf-examples/springwolf-amqp-example/src/test/resources/asyncapi.json @@ -41,7 +41,7 @@ "name": "io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto", "title": "AnotherPayloadDto", "payload": { - "$ref": "#/components/schemas/AnotherPayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -92,7 +92,7 @@ "title": "AnotherPayloadDto", "description": "Another payload model", "payload": { - "$ref": "#/components/schemas/AnotherPayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -133,7 +133,7 @@ "title": "AnotherPayloadDto", "description": "Another payload model", "payload": { - "$ref": "#/components/schemas/AnotherPayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -178,7 +178,7 @@ "title": "ExamplePayloadDto", "description": "Example payload model", "payload": { - "$ref": "#/components/schemas/ExamplePayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.amqp.dtos.ExamplePayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -208,7 +208,7 @@ "name": "io.github.stavshamir.springwolf.example.amqp.dtos.ExamplePayloadDto", "title": "ExamplePayloadDto", "payload": { - "$ref": "#/components/schemas/ExamplePayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.amqp.dtos.ExamplePayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -258,7 +258,7 @@ "name": "io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto", "title": "AnotherPayloadDto", "payload": { - "$ref": "#/components/schemas/AnotherPayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -308,7 +308,7 @@ "name": "io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto", "title": "AnotherPayloadDto", "payload": { - "$ref": "#/components/schemas/AnotherPayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -344,14 +344,19 @@ }, "components": { "schemas": { - "AnotherPayloadDto": { + "HeadersNotDocumented": { + "type": "object", + "properties": { }, + "example": { } + }, + "io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto": { "required": [ "example" ], "type": "object", "properties": { "example": { - "$ref": "#/components/schemas/ExamplePayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.amqp.dtos.ExamplePayloadDto" }, "foo": { "type": "string", @@ -369,7 +374,7 @@ "foo": "bar" } }, - "ExamplePayloadDto": { + "io.github.stavshamir.springwolf.example.amqp.dtos.ExamplePayloadDto": { "required": [ "someEnum", "someString" @@ -404,11 +409,6 @@ "someLong": 5, "someString": "some string value" } - }, - "HeadersNotDocumented": { - "type": "object", - "properties": { }, - "example": { } } } }, diff --git a/springwolf-examples/springwolf-amqp-example/src/test/resources/asyncapi_withdocketfromenvironment.json b/springwolf-examples/springwolf-amqp-example/src/test/resources/asyncapi_withdocketfromenvironment.json index 57422225d..c4ccff4fa 100644 --- a/springwolf-examples/springwolf-amqp-example/src/test/resources/asyncapi_withdocketfromenvironment.json +++ b/springwolf-examples/springwolf-amqp-example/src/test/resources/asyncapi_withdocketfromenvironment.json @@ -41,7 +41,7 @@ "name": "io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto", "title": "AnotherPayloadDto", "payload": { - "$ref": "#/components/schemas/AnotherPayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -96,7 +96,7 @@ "title": "ExamplePayloadDto", "description": "Example payload model", "payload": { - "$ref": "#/components/schemas/ExamplePayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.amqp.dtos.ExamplePayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -126,7 +126,7 @@ "name": "io.github.stavshamir.springwolf.example.amqp.dtos.ExamplePayloadDto", "title": "ExamplePayloadDto", "payload": { - "$ref": "#/components/schemas/ExamplePayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.amqp.dtos.ExamplePayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -176,7 +176,7 @@ "name": "io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto", "title": "AnotherPayloadDto", "payload": { - "$ref": "#/components/schemas/AnotherPayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -226,7 +226,7 @@ "name": "io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto", "title": "AnotherPayloadDto", "payload": { - "$ref": "#/components/schemas/AnotherPayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -262,14 +262,19 @@ }, "components": { "schemas": { - "AnotherPayloadDto": { + "HeadersNotDocumented": { + "type": "object", + "properties": { }, + "example": { } + }, + "io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto": { "required": [ "example" ], "type": "object", "properties": { "example": { - "$ref": "#/components/schemas/ExamplePayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.amqp.dtos.ExamplePayloadDto" }, "foo": { "type": "string", @@ -287,7 +292,7 @@ "foo": "bar" } }, - "ExamplePayloadDto": { + "io.github.stavshamir.springwolf.example.amqp.dtos.ExamplePayloadDto": { "required": [ "someEnum", "someString" @@ -322,11 +327,6 @@ "someLong": 5, "someString": "some string value" } - }, - "HeadersNotDocumented": { - "type": "object", - "properties": { }, - "example": { } } } }, diff --git a/springwolf-examples/springwolf-kafka-example/src/main/resources/application.properties b/springwolf-examples/springwolf-kafka-example/src/main/resources/application.properties index e98fd53cb..7f0882c0f 100644 --- a/springwolf-examples/springwolf-kafka-example/src/main/resources/application.properties +++ b/springwolf-examples/springwolf-kafka-example/src/main/resources/application.properties @@ -36,6 +36,7 @@ springwolf.docket.info.contact.name=springwolf springwolf.docket.info.contact.email=example@example.com springwolf.docket.info.contact.url=https://github.com/springwolf/springwolf-core springwolf.docket.info.license.name=Apache License 2.0 +springwolf.use-fqn=true # Springwolf kafka configuration springwolf.docket.servers.kafka.protocol=kafka diff --git a/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.json b/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.json index afdd7b465..cc59d8f3a 100644 --- a/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.json +++ b/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.json @@ -41,7 +41,7 @@ "name": "io.github.stavshamir.springwolf.example.kafka.dtos.AnotherPayloadDto", "title": "AnotherPayloadDto", "payload": { - "$ref": "#/components/schemas/AnotherPayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.kafka.dtos.AnotherPayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -74,7 +74,7 @@ "title": "ExamplePayloadDto", "description": "Example payload model", "payload": { - "$ref": "#/components/schemas/ExamplePayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.kafka.dtos.ExamplePayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -107,7 +107,7 @@ "title": "AnotherPayloadDto", "description": "Another payload model", "payload": { - "$ref": "#/components/schemas/AnotherPayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.kafka.dtos.AnotherPayloadDto" }, "headers": { "$ref": "#/components/schemas/CloudEventHeadersForAnotherPayloadDtoEndpoint" @@ -139,7 +139,7 @@ "name": "io.github.stavshamir.springwolf.example.kafka.dtos.ExamplePayloadDto", "title": "ExamplePayloadDto", "payload": { - "$ref": "#/components/schemas/ExamplePayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.kafka.dtos.ExamplePayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -185,7 +185,7 @@ "name": "io.github.stavshamir.springwolf.example.kafka.dtos.AnotherPayloadDto", "title": "AnotherPayloadDto", "payload": { - "$ref": "#/components/schemas/AnotherPayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.kafka.dtos.AnotherPayloadDto" }, "headers": { "$ref": "#/components/schemas/SpringKafkaDefaultHeaders-AnotherPayloadDto" @@ -201,7 +201,7 @@ "name": "io.github.stavshamir.springwolf.example.kafka.dtos.ExamplePayloadDto", "title": "ExamplePayloadDto", "payload": { - "$ref": "#/components/schemas/ExamplePayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.kafka.dtos.ExamplePayloadDto" }, "headers": { "$ref": "#/components/schemas/SpringKafkaDefaultHeaders-ExamplePayloadDto" @@ -217,7 +217,7 @@ "name": "javax.money.MonetaryAmount", "title": "MonetaryAmount", "payload": { - "$ref": "#/components/schemas/MonetaryAmount" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.addons.common_model_converters.converters.monetaryamount.MonetaryAmount" }, "headers": { "$ref": "#/components/schemas/SpringKafkaDefaultHeaders-MonetaryAmount" @@ -258,7 +258,7 @@ "title": "NestedPayloadDto", "description": "Payload model with nested complex types", "payload": { - "$ref": "#/components/schemas/NestedPayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.kafka.dtos.NestedPayloadDto" }, "headers": { "$ref": "#/components/schemas/SpringKafkaDefaultHeaders" @@ -279,31 +279,6 @@ }, "components": { "schemas": { - "AnotherPayloadDto": { - "required": [ - "example" - ], - "type": "object", - "properties": { - "example": { - "$ref": "#/components/schemas/ExamplePayloadDto" - }, - "foo": { - "type": "string", - "description": "Foo field", - "example": "bar" - } - }, - "description": "Another payload model", - "example": { - "example": { - "someEnum": "FOO2", - "someLong": 5, - "someString": "some string value" - }, - "foo": "bar" - } - }, "CloudEventHeadersForAnotherPayloadDtoEndpoint": { "type": "object", "properties": { @@ -374,97 +349,11 @@ "content-type": "application/json" } }, - "ExamplePayloadDto": { - "required": [ - "someEnum", - "someString" - ], - "type": "object", - "properties": { - "someEnum": { - "type": "string", - "description": "Some enum field", - "example": "FOO2", - "enum": [ - "FOO1", - "FOO2", - "FOO3" - ] - }, - "someLong": { - "type": "integer", - "description": "Some long field", - "format": "int64", - "example": 5 - }, - "someString": { - "type": "string", - "description": "Some string field", - "example": "some string value" - } - }, - "description": "Example payload model", - "example": { - "someEnum": "FOO2", - "someLong": 5, - "someString": "some string value" - } - }, "HeadersNotDocumented": { "type": "object", "properties": { }, "example": { } }, - "MonetaryAmount": { - "type": "object", - "properties": { - "amount": { - "type": "number", - "example": 99.99 - }, - "currency": { - "type": "string", - "example": "USD" - } - }, - "example": { - "amount": 99.99, - "currency": "USD" - } - }, - "NestedPayloadDto": { - "type": "object", - "properties": { - "examplePayloads": { - "type": "array", - "items": { - "$ref": "#/components/schemas/ExamplePayloadDto" - } - }, - "someStrings": { - "uniqueItems": true, - "type": "array", - "items": { - "type": "string", - "description": "Some string field", - "example": "some string value" - } - } - }, - "description": "Payload model with nested complex types", - "example": { - "examplePayloads": [ - { - "someEnum": "FOO2", - "someLong": 5, - "someString": "some string value" - } - ], - "someStrings": [ - "some string value" - ] - } - }, "SpringKafkaDefaultHeaders": { "type": "object", "properties": { @@ -528,6 +417,117 @@ "example": { "__TypeId__": "javax.money.MonetaryAmount" } + }, + "io.github.stavshamir.springwolf.addons.common_model_converters.converters.monetaryamount.MonetaryAmount": { + "type": "object", + "properties": { + "amount": { + "type": "number", + "example": 99.99 + }, + "currency": { + "type": "string", + "example": "USD" + } + }, + "example": { + "amount": 99.99, + "currency": "USD" + } + }, + "io.github.stavshamir.springwolf.example.kafka.dtos.AnotherPayloadDto": { + "required": [ + "example" + ], + "type": "object", + "properties": { + "example": { + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.kafka.dtos.ExamplePayloadDto" + }, + "foo": { + "type": "string", + "description": "Foo field", + "example": "bar" + } + }, + "description": "Another payload model", + "example": { + "example": { + "someEnum": "FOO2", + "someLong": 5, + "someString": "some string value" + }, + "foo": "bar" + } + }, + "io.github.stavshamir.springwolf.example.kafka.dtos.ExamplePayloadDto": { + "required": [ + "someEnum", + "someString" + ], + "type": "object", + "properties": { + "someEnum": { + "type": "string", + "description": "Some enum field", + "example": "FOO2", + "enum": [ + "FOO1", + "FOO2", + "FOO3" + ] + }, + "someLong": { + "type": "integer", + "description": "Some long field", + "format": "int64", + "example": 5 + }, + "someString": { + "type": "string", + "description": "Some string field", + "example": "some string value" + } + }, + "description": "Example payload model", + "example": { + "someEnum": "FOO2", + "someLong": 5, + "someString": "some string value" + } + }, + "io.github.stavshamir.springwolf.example.kafka.dtos.NestedPayloadDto": { + "type": "object", + "properties": { + "examplePayloads": { + "type": "array", + "items": { + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.kafka.dtos.ExamplePayloadDto" + } + }, + "someStrings": { + "uniqueItems": true, + "type": "array", + "items": { + "type": "string", + "description": "Some string field", + "example": "some string value" + } + } + }, + "description": "Payload model with nested complex types", + "example": { + "examplePayloads": [ + { + "someEnum": "FOO2", + "someLong": 5, + "someString": "some string value" + } + ], + "someStrings": [ + "some string value" + ] + } } } }, diff --git a/springwolf-examples/springwolf-sns-example/src/main/resources/application.properties b/springwolf-examples/springwolf-sns-example/src/main/resources/application.properties index 63644df29..bd191de07 100644 --- a/springwolf-examples/springwolf-sns-example/src/main/resources/application.properties +++ b/springwolf-examples/springwolf-sns-example/src/main/resources/application.properties @@ -27,6 +27,7 @@ springwolf.docket.info.contact.url=https://github.com/springwolf/springwolf-core springwolf.docket.info.license.name=Apache License 2.0 springwolf.docket.servers.sns.protocol=sns springwolf.docket.servers.sns.url=http://localhost:4566 +springwolf.use-fqn=true springwolf.plugin.sns.publishing.enabled=true diff --git a/springwolf-examples/springwolf-sns-example/src/test/resources/asyncapi.json b/springwolf-examples/springwolf-sns-example/src/test/resources/asyncapi.json index 6daa45cb1..dd8ce4c59 100644 --- a/springwolf-examples/springwolf-sns-example/src/test/resources/asyncapi.json +++ b/springwolf-examples/springwolf-sns-example/src/test/resources/asyncapi.json @@ -34,7 +34,7 @@ "title": "AnotherPayloadDto", "description": "Another payload model", "payload": { - "$ref": "#/components/schemas/AnotherPayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.sns.dtos.AnotherPayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -56,7 +56,7 @@ "title": "AnotherPayloadDto", "description": "Another payload model", "payload": { - "$ref": "#/components/schemas/AnotherPayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.sns.dtos.AnotherPayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -80,7 +80,7 @@ "title": "ExamplePayloadDto", "description": "Example payload model", "payload": { - "$ref": "#/components/schemas/ExamplePayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.sns.dtos.ExamplePayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -94,14 +94,19 @@ }, "components": { "schemas": { - "AnotherPayloadDto": { + "HeadersNotDocumented": { + "type": "object", + "properties": { }, + "example": { } + }, + "io.github.stavshamir.springwolf.example.sns.dtos.AnotherPayloadDto": { "required": [ "example" ], "type": "object", "properties": { "example": { - "$ref": "#/components/schemas/ExamplePayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.sns.dtos.ExamplePayloadDto" }, "foo": { "type": "string", @@ -119,7 +124,7 @@ "foo": "bar" } }, - "ExamplePayloadDto": { + "io.github.stavshamir.springwolf.example.sns.dtos.ExamplePayloadDto": { "required": [ "someEnum", "someString" @@ -154,11 +159,6 @@ "someLong": 5, "someString": "some string value" } - }, - "HeadersNotDocumented": { - "type": "object", - "properties": { }, - "example": { } } } }, diff --git a/springwolf-examples/springwolf-sqs-example/src/main/resources/application.properties b/springwolf-examples/springwolf-sqs-example/src/main/resources/application.properties index 993005267..bda7b6ee5 100644 --- a/springwolf-examples/springwolf-sqs-example/src/main/resources/application.properties +++ b/springwolf-examples/springwolf-sqs-example/src/main/resources/application.properties @@ -27,6 +27,7 @@ springwolf.docket.info.contact.url=https://github.com/springwolf/springwolf-core springwolf.docket.info.license.name=Apache License 2.0 springwolf.docket.servers.sqs.protocol=sqs springwolf.docket.servers.sqs.url=http://localhost:4566 +springwolf.use-fqn=true springwolf.plugin.sqs.publishing.enabled=true diff --git a/springwolf-examples/springwolf-sqs-example/src/test/resources/asyncapi.json b/springwolf-examples/springwolf-sqs-example/src/test/resources/asyncapi.json index c341f0fcb..75926d9bf 100644 --- a/springwolf-examples/springwolf-sqs-example/src/test/resources/asyncapi.json +++ b/springwolf-examples/springwolf-sqs-example/src/test/resources/asyncapi.json @@ -39,7 +39,7 @@ "title": "AnotherPayloadDto", "description": "Another payload model", "payload": { - "$ref": "#/components/schemas/AnotherPayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.sqs.dtos.AnotherPayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -62,7 +62,7 @@ "name": "io.github.stavshamir.springwolf.example.sqs.dtos.AnotherPayloadDto", "title": "AnotherPayloadDto", "payload": { - "$ref": "#/components/schemas/AnotherPayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.sqs.dtos.AnotherPayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -85,7 +85,7 @@ "name": "io.github.stavshamir.springwolf.example.sqs.dtos.ExamplePayloadDto", "title": "ExamplePayloadDto", "payload": { - "$ref": "#/components/schemas/ExamplePayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.sqs.dtos.ExamplePayloadDto" }, "headers": { "$ref": "#/components/schemas/HeadersNotDocumented" @@ -102,14 +102,19 @@ }, "components": { "schemas": { - "AnotherPayloadDto": { + "HeadersNotDocumented": { + "type": "object", + "properties": { }, + "example": { } + }, + "io.github.stavshamir.springwolf.example.sqs.dtos.AnotherPayloadDto": { "required": [ "example" ], "type": "object", "properties": { "example": { - "$ref": "#/components/schemas/ExamplePayloadDto" + "$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.sqs.dtos.ExamplePayloadDto" }, "foo": { "type": "string", @@ -127,7 +132,7 @@ "foo": "bar" } }, - "ExamplePayloadDto": { + "io.github.stavshamir.springwolf.example.sqs.dtos.ExamplePayloadDto": { "required": [ "someEnum", "someString" @@ -162,11 +167,6 @@ "someLong": 5, "someString": "some string value" } - }, - "HeadersNotDocumented": { - "type": "object", - "properties": { }, - "example": { } } } }, diff --git a/springwolf-plugins/springwolf-amqp-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/ClassLevelRabbitListenerScannerIntegrationTest.java b/springwolf-plugins/springwolf-amqp-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/ClassLevelRabbitListenerScannerIntegrationTest.java index 5ab7227b1..c4c760adf 100644 --- a/springwolf-plugins/springwolf-amqp-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/ClassLevelRabbitListenerScannerIntegrationTest.java +++ b/springwolf-plugins/springwolf-amqp-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/ClassLevelRabbitListenerScannerIntegrationTest.java @@ -12,6 +12,7 @@ import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.PayloadReference; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.HeaderReference; import io.github.stavshamir.springwolf.configuration.AsyncApiDocket; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; import io.github.stavshamir.springwolf.schemas.DefaultSchemasService; import io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator; import lombok.Data; @@ -37,7 +38,12 @@ @ExtendWith(SpringExtension.class) @ContextConfiguration( - classes = {ClassLevelRabbitListenerScanner.class, DefaultSchemasService.class, ExampleJsonGenerator.class}) + classes = { + ClassLevelRabbitListenerScanner.class, + DefaultSchemasService.class, + ExampleJsonGenerator.class, + SpringwolfConfigProperties.class, + }) class ClassLevelRabbitListenerScannerIntegrationTest { @Autowired diff --git a/springwolf-plugins/springwolf-amqp-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelRabbitListenerScannerIntegrationTest.java b/springwolf-plugins/springwolf-amqp-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelRabbitListenerScannerIntegrationTest.java index 105625817..6163b5c91 100644 --- a/springwolf-plugins/springwolf-amqp-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelRabbitListenerScannerIntegrationTest.java +++ b/springwolf-plugins/springwolf-amqp-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelRabbitListenerScannerIntegrationTest.java @@ -13,6 +13,7 @@ import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.PayloadReference; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.AsyncHeaders; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.HeaderReference; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; import io.github.stavshamir.springwolf.schemas.DefaultSchemasService; import io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator; import lombok.Data; @@ -52,6 +53,7 @@ MethodLevelRabbitListenerScanner.class, DefaultSchemasService.class, ExampleJsonGenerator.class, + SpringwolfConfigProperties.class, MethodLevelRabbitListenerScannerIntegrationTest.ClassWithRabbitListenerAnnotationsBindingBean.class }) @TestPropertySource(properties = "amqp.queues.test=test-queue") diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/ClassLevelKafkaListenerScannerIntegrationTest.java b/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/ClassLevelKafkaListenerScannerIntegrationTest.java index 881bfe4cb..b9b3e6fa4 100644 --- a/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/ClassLevelKafkaListenerScannerIntegrationTest.java +++ b/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/ClassLevelKafkaListenerScannerIntegrationTest.java @@ -12,6 +12,7 @@ import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.PayloadReference; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.HeaderReference; import io.github.stavshamir.springwolf.configuration.AsyncApiDocket; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; import io.github.stavshamir.springwolf.schemas.DefaultSchemasService; import io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator; import lombok.Data; @@ -37,7 +38,12 @@ @ExtendWith(SpringExtension.class) @ContextConfiguration( - classes = {ClassLevelKafkaListenerScanner.class, DefaultSchemasService.class, ExampleJsonGenerator.class}) + classes = { + ClassLevelKafkaListenerScanner.class, + DefaultSchemasService.class, + ExampleJsonGenerator.class, + SpringwolfConfigProperties.class, + }) @TestPropertySource(properties = "kafka.topics.test=test-topic") class ClassLevelKafkaListenerScannerIntegrationTest { diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelKafkaListenerScannerIntegrationTest.java b/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelKafkaListenerScannerIntegrationTest.java index 0ec91f3c3..8353a4976 100644 --- a/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelKafkaListenerScannerIntegrationTest.java +++ b/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelKafkaListenerScannerIntegrationTest.java @@ -13,6 +13,7 @@ import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.AsyncHeaders; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.HeaderReference; import io.github.stavshamir.springwolf.configuration.AsyncApiDocket; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; import io.github.stavshamir.springwolf.schemas.DefaultSchemasService; import io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator; import lombok.Data; @@ -38,7 +39,12 @@ @ExtendWith(SpringExtension.class) @ContextConfiguration( - classes = {MethodLevelKafkaListenerScanner.class, DefaultSchemasService.class, ExampleJsonGenerator.class}) + classes = { + MethodLevelKafkaListenerScanner.class, + DefaultSchemasService.class, + ExampleJsonGenerator.class, + SpringwolfConfigProperties.class, + }) @TestPropertySource(properties = "kafka.topics.test=test-topic") class MethodLevelKafkaListenerScannerIntegrationTest { diff --git a/springwolf-plugins/springwolf-sqs-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelSqsListenerScannerIntegrationTest.java b/springwolf-plugins/springwolf-sqs-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelSqsListenerScannerIntegrationTest.java index be2990c97..e8e161ca3 100644 --- a/springwolf-plugins/springwolf-sqs-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelSqsListenerScannerIntegrationTest.java +++ b/springwolf-plugins/springwolf-sqs-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelSqsListenerScannerIntegrationTest.java @@ -14,6 +14,7 @@ import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.AsyncHeaders; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.HeaderReference; import io.github.stavshamir.springwolf.configuration.AsyncApiDocket; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; import io.github.stavshamir.springwolf.schemas.DefaultSchemasService; import io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator; import lombok.Data; @@ -41,6 +42,7 @@ MethodLevelSqsListenerScanner.class, DefaultSchemasService.class, ExampleJsonGenerator.class, + SpringwolfConfigProperties.class, }) @TestPropertySource(properties = "sqs.value.test=test-queue") class MethodLevelSqsListenerScannerIntegrationTest { diff --git a/springwolf-ui/src/app/channels/channel-main/channel-main.component.css b/springwolf-ui/src/app/channels/channel-main/channel-main.component.css index 42c3aac9d..545231e1c 100644 --- a/springwolf-ui/src/app/channels/channel-main/channel-main.component.css +++ b/springwolf-ui/src/app/channels/channel-main/channel-main.component.css @@ -29,13 +29,6 @@ button { font-weight: normal; } -.header-name { - background-color: #e0e0e0; - border-radius: 4px; - padding: 6px; - font-weight: normal; -} - .button-container { height: 50px; } diff --git a/springwolf-ui/src/app/channels/channel-main/channel-main.component.html b/springwolf-ui/src/app/channels/channel-main/channel-main.component.html index e26c60ad3..01b1b509f 100644 --- a/springwolf-ui/src/app/channels/channel-main/channel-main.component.html +++ b/springwolf-ui/src/app/channels/channel-main/channel-main.component.html @@ -94,23 +94,19 @@

Message

- {{ schemaName }} - - {{ - operation.message.payload.name - }} - + Schema: + {{ + operation.message.payload.name + }}

- {{ headersSchemaName }} - - {{ - operation.message.headers.name - }} - + Schema: + {{ + operation.message.headers.name + }}

diff --git a/springwolf-ui/src/app/channels/channel-main/channel-main.component.ts b/springwolf-ui/src/app/channels/channel-main/channel-main.component.ts index 0336ab5f2..abb1e6134 100644 --- a/springwolf-ui/src/app/channels/channel-main/channel-main.component.ts +++ b/springwolf-ui/src/app/channels/channel-main/channel-main.component.ts @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: Apache-2.0 */ -import { Component, OnInit, Input } from "@angular/core"; +import { Component, Input, OnInit } from "@angular/core"; import { AsyncApiService } from "src/app/shared/asyncapi.service"; import { Example } from "src/app/shared/models/example.model"; import { Schema } from "src/app/shared/models/schema.model"; @@ -19,12 +19,12 @@ export class ChannelMainComponent implements OnInit { @Input() operation: Operation; schema: Schema; - schemaName: string; + schemaIdentifier: string; defaultExample: Example; defaultExampleType: string; exampleTextAreaLineCount: number; headers: Schema; - headersSchemaName: string; + headersSchemaIdentifier: string; headersExample: Example; headersTextAreaLineCount: number; protocolName: string; @@ -40,19 +40,19 @@ export class ChannelMainComponent implements OnInit { ngOnInit(): void { this.asyncApiService.getAsyncApi().subscribe((asyncapi) => { const schemas: Map = asyncapi.components.schemas; - this.schemaName = this.operation.message.payload.name.slice( + this.schemaIdentifier = this.operation.message.payload.name.slice( this.operation.message.payload.name.lastIndexOf("/") + 1 ); - this.schema = schemas.get(this.schemaName); + this.schema = schemas.get(this.schemaIdentifier); this.defaultExample = this.schema.example; this.exampleTextAreaLineCount = this.defaultExample?.lineCount || 0; this.defaultExampleType = this.operation.message.name; - this.headersSchemaName = this.operation.message.headers.name.slice( + this.headersSchemaIdentifier = this.operation.message.headers.name.slice( this.operation.message.headers.name.lastIndexOf("/") + 1 ); - this.headers = schemas.get(this.headersSchemaName); + this.headers = schemas.get(this.headersSchemaIdentifier); this.headersExample = this.headers.example; this.headersTextAreaLineCount = this.headersExample?.lineCount || 0; this.messageBindingExampleTextAreaLineCount = diff --git a/springwolf-ui/src/app/channels/channels.component.html b/springwolf-ui/src/app/channels/channels.component.html index 2ebfeb6e2..c85f7f6fa 100644 --- a/springwolf-ui/src/app/channels/channels.component.html +++ b/springwolf-ui/src/app/channels/channels.component.html @@ -53,7 +53,7 @@

Channels

>

{{ channel.name }}

-
{{ channel.operation.message.title }}
+ {{ channel.operation.message.title }} {{ property.value.items.name }}[]{{ property.value.items.refTitle }}[] {{ property.value.type }} - - {{ property.value.name }} + + {{ property.value.refTitle }} ({{ property.value.format }})Schemas > -

{{ schema.key }}

+

{{ schema.value.title }}

{{ schema.value.description }}
- +

+ Title: {{ schema.value.name }} +

+ diff --git a/springwolf-ui/src/app/shared/asyncapi-mapper.service.ts b/springwolf-ui/src/app/shared/asyncapi-mapper.service.ts index 622883787..7f079fc29 100644 --- a/springwolf-ui/src/app/shared/asyncapi-mapper.service.ts +++ b/springwolf-ui/src/app/shared/asyncapi-mapper.service.ts @@ -182,11 +182,13 @@ export class AsyncApiMapperService { description: v.description, payload: { name: v.payload.$ref, + title: v.payload.$ref?.split(".")?.pop(), anchorUrl: AsyncApiMapperService.BASE_URL + v.payload.$ref?.split("/")?.pop(), }, headers: { name: v.headers.$ref, + title: v.headers.$ref?.split("/")?.pop(), anchorUrl: AsyncApiMapperService.BASE_URL + v.headers.$ref?.split("/")?.pop(), }, @@ -268,8 +270,11 @@ export class AsyncApiMapperService { const example = schema.example !== undefined ? new Example(schema.example) : undefined; return { - name: schema.$ref, + name: schemaName, + title: schemaName.split(".")?.pop(), description: schema.description, + refName: schema.$ref, + refTitle: schema.$ref?.split("/")?.pop(), anchorIdentifier: "#" + schemaName, anchorUrl: anchorUrl, type: schema.type, diff --git a/springwolf-ui/src/app/shared/models/channel.model.ts b/springwolf-ui/src/app/shared/models/channel.model.ts index ac69da30c..246eca06e 100644 --- a/springwolf-ui/src/app/shared/models/channel.model.ts +++ b/springwolf-ui/src/app/shared/models/channel.model.ts @@ -23,10 +23,12 @@ export interface Message { description?: string; payload: { name: string; + title: string; anchorUrl: string; }; headers: { name: string; + title: string; anchorUrl: string; }; bindings?: Map; diff --git a/springwolf-ui/src/app/shared/models/schema.model.ts b/springwolf-ui/src/app/shared/models/schema.model.ts index 7daad7ed5..f854ac8a1 100644 --- a/springwolf-ui/src/app/shared/models/schema.model.ts +++ b/springwolf-ui/src/app/shared/models/schema.model.ts @@ -3,8 +3,11 @@ import { Example } from "./example.model"; export interface Schema { name?: string; + title: string; description?: string; + refName?: string; + refTitle?: string; anchorIdentifier?: string; anchorUrl?: string;