From 07a6b30d9d43ff66910ba4e6edbfd15e578c851d Mon Sep 17 00:00:00 2001 From: Nikita Marunko Date: Wed, 27 Dec 2023 22:52:00 +0900 Subject: [PATCH 1/8] test: ignore line ending in generated specs assertions Is failing in Windows OS Refs #378 --- ...ultAsyncApiSerializerServiceIntegrationTest.java | 3 ++- .../schemas/DefaultSchemasServiceTest.java | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/DefaultAsyncApiSerializerServiceIntegrationTest.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/DefaultAsyncApiSerializerServiceIntegrationTest.java index d91b612f5..53c3cf248 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/DefaultAsyncApiSerializerServiceIntegrationTest.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/DefaultAsyncApiSerializerServiceIntegrationTest.java @@ -19,6 +19,7 @@ import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.media.StringSchema; import lombok.Data; +import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -110,7 +111,7 @@ void AsyncAPI_should_map_to_a_valid_asyncapi_json() throws IOException { String actual = serializer.toJsonString(asyncapi); InputStream s = this.getClass().getResourceAsStream("/asyncapi/asyncapi.json"); String expected = new String(s.readAllBytes(), StandardCharsets.UTF_8); - assertEquals(expected, actual); + assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(actual)); } @Test 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 604c132f4..086b66720 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 @@ -14,6 +14,7 @@ import jakarta.annotation.Nullable; import lombok.Data; import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -51,7 +52,7 @@ void getDefinitions() throws IOException { String expected = jsonResource("/schemas/definitions.json"); System.out.println("Got: " + actualDefinitions); - assertEquals(expected, actualDefinitions); + assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(actualDefinitions)); } @Test @@ -62,7 +63,7 @@ void getDocumentedDefinitions() throws IOException { String expected = jsonResource("/schemas/documented-definitions.json"); System.out.println("Got: " + actualDefinitions); - assertEquals(expected, actualDefinitions); + assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(actualDefinitions)); } @Test @@ -73,7 +74,7 @@ void getArrayDefinitions() throws IOException { String expected = jsonResource("/schemas/array-definitions.json"); System.out.println("Got: " + actualDefinitions); - assertEquals(expected, actualDefinitions); + assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(actualDefinitions)); } @Test @@ -84,7 +85,7 @@ void getComplexDefinitions() throws IOException { String expected = jsonResource("/schemas/complex-definitions.json"); System.out.println("Got: " + actualDefinitions); - assertEquals(expected, actualDefinitions); + assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(actualDefinitions)); } @Test @@ -95,7 +96,7 @@ void getListWrapperDefinitions() throws IOException { String expected = jsonResource("/schemas/generics-wrapper-definitions.json"); System.out.println("Got: " + actualDefinitions); - assertEquals(expected, actualDefinitions); + assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(actualDefinitions)); } @Test @@ -256,7 +257,7 @@ void testSchemaWithOneOf() throws IOException { String expected = jsonResource("/schemas/annotation-definitions.json"); System.out.println("Got: " + actualDefinitions); - assertEquals(expected, actualDefinitions); + assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(actualDefinitions)); } @Data From d852fb387ece224994dc4876fc923ef62d756a97 Mon Sep 17 00:00:00 2001 From: Nikita Marunko Date: Thu, 28 Dec 2023 22:21:51 +0900 Subject: [PATCH 2/8] refactor(kafka): add primitive payload, example of `minimum` value To visualize in UI Refs #378 test(kafka): add primitive types More data to demonstrate + type badges check --- .../monetaryamount/MonetaryAmount.java | 2 +- .../kafka/consumers/ExampleConsumer.java | 5 +++ .../kafka/SpringContextIntegrationTest.java | 2 +- .../src/test/resources/asyncapi.json | 42 +++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/springwolf-add-ons/springwolf-common-model-converters/src/main/java/io/github/stavshamir/springwolf/addons/common_model_converters/converters/monetaryamount/MonetaryAmount.java b/springwolf-add-ons/springwolf-common-model-converters/src/main/java/io/github/stavshamir/springwolf/addons/common_model_converters/converters/monetaryamount/MonetaryAmount.java index ea6d52de3..25d76d649 100644 --- a/springwolf-add-ons/springwolf-common-model-converters/src/main/java/io/github/stavshamir/springwolf/addons/common_model_converters/converters/monetaryamount/MonetaryAmount.java +++ b/springwolf-add-ons/springwolf-common-model-converters/src/main/java/io/github/stavshamir/springwolf/addons/common_model_converters/converters/monetaryamount/MonetaryAmount.java @@ -10,7 +10,7 @@ class MonetaryAmount { @JsonProperty("amount") - @Schema(example = "99.99") + @Schema(example = "99.99", minimum = "0.1") private BigDecimal amount; @JsonProperty("currency") diff --git a/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/kafka/consumers/ExampleConsumer.java b/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/kafka/consumers/ExampleConsumer.java index 784f6b5eb..a9d9791c2 100644 --- a/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/kafka/consumers/ExampleConsumer.java +++ b/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/kafka/consumers/ExampleConsumer.java @@ -29,6 +29,11 @@ public void receiveExamplePayload(ExamplePayloadDto payload) { anotherProducer.sendMessage(example); } + @KafkaListener(topics = "primitive-topic") + public void receivePrimitivePayload(String primitivePayload) { + log.info("Received new messages in primitive-topic: {}", primitivePayload); + } + @KafkaListener(topics = "another-topic", groupId = "example-group-id", batch = "true") public void receiveAnotherPayloadBatched(List payloads) { log.info("Received new messages in another-topic: {}", payloads.toString()); diff --git a/springwolf-examples/springwolf-kafka-example/src/test/java/io/github/stavshamir/springwolf/example/kafka/SpringContextIntegrationTest.java b/springwolf-examples/springwolf-kafka-example/src/test/java/io/github/stavshamir/springwolf/example/kafka/SpringContextIntegrationTest.java index 67f22580d..9d0274d23 100644 --- a/springwolf-examples/springwolf-kafka-example/src/test/java/io/github/stavshamir/springwolf/example/kafka/SpringContextIntegrationTest.java +++ b/springwolf-examples/springwolf-kafka-example/src/test/java/io/github/stavshamir/springwolf/example/kafka/SpringContextIntegrationTest.java @@ -48,7 +48,7 @@ void testContextWithApplicationProperties() { @Test void testAllChannelsAreFound() { - assertThat(asyncApiService.getAsyncAPI().getChannels()).hasSize(4); + assertThat(asyncApiService.getAsyncAPI().getChannels()).hasSize(5); } } 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 51d971788..a952aa847 100644 --- a/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.json +++ b/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.json @@ -172,6 +172,38 @@ } } }, + "primitive-topic": { + "publish": { + "operationId": "primitive-topic_publish_receivePrimitivePayload", + "description": "Auto-generated description", + "bindings": { + "kafka": { + "bindingVersion": "0.4.0" + } + }, + "message": { + "schemaFormat": "application/vnd.oai.openapi+json;version=3.0.0", + "name": "java.lang.String", + "title": "String", + "payload": { + "$ref": "#/components/schemas/String" + }, + "headers": { + "$ref": "#/components/schemas/HeadersNotDocumented" + }, + "bindings": { + "kafka": { + "bindingVersion": "0.4.0" + } + } + } + }, + "bindings": { + "kafka": { + "bindingVersion": "0.4.0" + } + } + }, "topic-defined-via-asyncPublisher-annotation": { "subscribe": { "operationId": "topic-defined-via-asyncPublisher-annotation_subscribe", @@ -456,10 +488,19 @@ "type": "object" } }, + "String": { + "type": "string", + "example": "string", + "x-json-schema": { + "$schema": "https://json-schema.org/draft-04/schema#", + "type": "string" + } + }, "io.github.stavshamir.springwolf.addons.common_model_converters.converters.monetaryamount.MonetaryAmount": { "type": "object", "properties": { "amount": { + "minimum": 0.1, "type": "number", "example": 99.99 }, @@ -477,6 +518,7 @@ "name": "io.github.stavshamir.springwolf.addons.common_model_converters.converters.monetaryamount.MonetaryAmount", "properties": { "amount": { + "minimum": 0.1, "name": "amount", "type": "number" }, From 43b1dac78c032dd96dc9c645852347460e03f10e Mon Sep 17 00:00:00 2001 From: Nikita Marunko Date: Sat, 30 Dec 2023 22:56:37 +0900 Subject: [PATCH 3/8] refactor(ui): add schema properties template To reuse for primitive types Refs #378 --- .../schemas/schema/schema.component.html | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/springwolf-ui/src/app/components/schemas/schema/schema.component.html b/springwolf-ui/src/app/components/schemas/schema/schema.component.html index 4057dd0bd..3684d7ba3 100644 --- a/springwolf-ui/src/app/components/schemas/schema/schema.component.html +++ b/springwolf-ui/src/app/components/schemas/schema/schema.component.html @@ -21,25 +21,29 @@ > - {{ - property.value.type - }} - - {{ property.value.refTitle }} - - ({{ property.value.format }}) -
{{ property.value.description }}
- example: {{ property.value.example.value }} - - {{ - enum - }} - + + + + {{ value.type }} + + {{ value.refTitle }} + + ({{ value.format }}) +
{{ value.description }}
+ example: {{ value.example.value }} + + {{ enum }} + + +
From 5edb43da361b1b948ebdc79d7bcbad7d5f97df1d Mon Sep 17 00:00:00 2001 From: Nikita Marunko Date: Wed, 27 Dec 2023 23:10:04 +0900 Subject: [PATCH 4/8] feat(ui): add `type` badge to schema payload header No intuitive way to check whether the payload is an objects or a string Refs #378 --- .../src/app/components/schemas/schemas.component.css | 11 +++++++++++ .../src/app/components/schemas/schemas.component.html | 8 ++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/springwolf-ui/src/app/components/schemas/schemas.component.css b/springwolf-ui/src/app/components/schemas/schemas.component.css index 575231555..0eae36c5b 100644 --- a/springwolf-ui/src/app/components/schemas/schemas.component.css +++ b/springwolf-ui/src/app/components/schemas/schemas.component.css @@ -9,3 +9,14 @@ h3 { padding: 6px; font-weight: normal; } + +.badge { +} + +.type-badge { + background-color: #e0e0e0; + border-radius: 4px; + padding: 4px; + font-weight: normal; + font-size: small; +} diff --git a/springwolf-ui/src/app/components/schemas/schemas.component.html b/springwolf-ui/src/app/components/schemas/schemas.component.html index 4c8dc4563..3e2ac7500 100644 --- a/springwolf-ui/src/app/components/schemas/schemas.component.html +++ b/springwolf-ui/src/app/components/schemas/schemas.component.html @@ -11,8 +11,12 @@

Schemas

{{ schema.value.title }}

- - {{ schema.value.description }} + +
{{ schema.value.description }}
+
{{ schema.value.type }}

From d3e17fa7a120e8db048872f6929aa15d3e114a17 Mon Sep 17 00:00:00 2001 From: Nikita Marunko Date: Sat, 30 Dec 2023 22:45:20 +0900 Subject: [PATCH 5/8] feat(ui): add minimum and maximum values to the spec`s model Feature request Refs #378 --- springwolf-ui/src/app/models/schema.model.ts | 2 ++ .../src/app/service/asyncapi/asyncapi-mapper.service.ts | 2 ++ springwolf-ui/src/app/service/asyncapi/models/schema.model.ts | 2 ++ 3 files changed, 6 insertions(+) diff --git a/springwolf-ui/src/app/models/schema.model.ts b/springwolf-ui/src/app/models/schema.model.ts index f854ac8a1..7ec71e02c 100644 --- a/springwolf-ui/src/app/models/schema.model.ts +++ b/springwolf-ui/src/app/models/schema.model.ts @@ -21,4 +21,6 @@ export interface Schema { required?: string[]; enum?: string[]; example?: Example; + minimum?: number; + maximum?: number; } diff --git a/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts b/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts index 490aca6d4..2bc155d75 100644 --- a/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts +++ b/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts @@ -270,6 +270,8 @@ export class AsyncApiMapperService { properties, required: schema.required, example, + minimum: schema.minimum, + maximum: schema.maximum, }; } diff --git a/springwolf-ui/src/app/service/asyncapi/models/schema.model.ts b/springwolf-ui/src/app/service/asyncapi/models/schema.model.ts index bd34aa40a..f205a8891 100644 --- a/springwolf-ui/src/app/service/asyncapi/models/schema.model.ts +++ b/springwolf-ui/src/app/service/asyncapi/models/schema.model.ts @@ -12,5 +12,7 @@ export interface ServerAsyncApiSchema { } | string; required?: string[]; + minimum?: number; + maximum?: number; $ref?: string; } From dcb042018e1a568bcae6193a7b96d5181fa05eed Mon Sep 17 00:00:00 2001 From: Nikita Marunko Date: Sat, 30 Dec 2023 23:09:01 +0900 Subject: [PATCH 6/8] feat(ui): display primitive type info Feature request. Only properties has info displayed Refs #378 --- .../app/components/schemas/schema/schema.component.html | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/springwolf-ui/src/app/components/schemas/schema/schema.component.html b/springwolf-ui/src/app/components/schemas/schema/schema.component.html index 3684d7ba3..3ec755a00 100644 --- a/springwolf-ui/src/app/components/schemas/schema/schema.component.html +++ b/springwolf-ui/src/app/components/schemas/schema/schema.component.html @@ -1,6 +1,15 @@ + + + + + +
{{ property.key }} From 4a4a9da0a35d0192600624eb37d9fdb39a0af76c Mon Sep 17 00:00:00 2001 From: Nikita Marunko Date: Mon, 1 Jan 2024 22:38:19 +0900 Subject: [PATCH 7/8] feat(ui): display minimum and maximum values Feature request. Refs #378 --- .../schemas/schema/schema.component.css | 12 +++++++++ .../schemas/schema/schema.component.html | 26 ++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/springwolf-ui/src/app/components/schemas/schema/schema.component.css b/springwolf-ui/src/app/components/schemas/schema/schema.component.css index 92adde268..19d2fefe5 100644 --- a/springwolf-ui/src/app/components/schemas/schema/schema.component.css +++ b/springwolf-ui/src/app/components/schemas/schema/schema.component.css @@ -12,6 +12,10 @@ color: red; } +.type-content { + display: flex; +} + .type { color: #55a; } @@ -20,3 +24,11 @@ color: #6b6b6b; font-style: italic; } + +.range { + background-color: rgb(128, 90, 213); + color: rgb(255, 255, 255); + margin: 0 8 0 8; + padding: 2 4 2 4; + border-radius: 4px; +} diff --git a/springwolf-ui/src/app/components/schemas/schema/schema.component.html b/springwolf-ui/src/app/components/schemas/schema/schema.component.html index 3ec755a00..67af11ea9 100644 --- a/springwolf-ui/src/app/components/schemas/schema/schema.component.html +++ b/springwolf-ui/src/app/components/schemas/schema/schema.component.html @@ -41,7 +41,19 @@
- {{ value.type }} +
+ {{ value.type }} + + + +
+ {{ value.refTitle }} @@ -56,3 +68,15 @@
+ + + + >= {{ minimum }} + + + <= {{ maximum }} + + + [ {{ minimum }} .. {{ maximum }} ] + + From d20f02a4bf6f2c69a80d91ece9eca6aa86c4407e Mon Sep 17 00:00:00 2001 From: Timon Back Date: Tue, 2 Jan 2024 18:40:26 +0100 Subject: [PATCH 8/8] Revert "test: ignore line ending in generated specs assertions" This reverts commit 07a6b30d9d43ff66910ba4e6edbfd15e578c851d. --- ...ultAsyncApiSerializerServiceIntegrationTest.java | 3 +-- .../schemas/DefaultSchemasServiceTest.java | 13 ++++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/DefaultAsyncApiSerializerServiceIntegrationTest.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/DefaultAsyncApiSerializerServiceIntegrationTest.java index 53c3cf248..d91b612f5 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/DefaultAsyncApiSerializerServiceIntegrationTest.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/DefaultAsyncApiSerializerServiceIntegrationTest.java @@ -19,7 +19,6 @@ import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.media.StringSchema; import lombok.Data; -import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -111,7 +110,7 @@ void AsyncAPI_should_map_to_a_valid_asyncapi_json() throws IOException { String actual = serializer.toJsonString(asyncapi); InputStream s = this.getClass().getResourceAsStream("/asyncapi/asyncapi.json"); String expected = new String(s.readAllBytes(), StandardCharsets.UTF_8); - assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(actual)); + assertEquals(expected, actual); } @Test 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 086b66720..604c132f4 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 @@ -14,7 +14,6 @@ import jakarta.annotation.Nullable; import lombok.Data; import lombok.NoArgsConstructor; -import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -52,7 +51,7 @@ void getDefinitions() throws IOException { String expected = jsonResource("/schemas/definitions.json"); System.out.println("Got: " + actualDefinitions); - assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(actualDefinitions)); + assertEquals(expected, actualDefinitions); } @Test @@ -63,7 +62,7 @@ void getDocumentedDefinitions() throws IOException { String expected = jsonResource("/schemas/documented-definitions.json"); System.out.println("Got: " + actualDefinitions); - assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(actualDefinitions)); + assertEquals(expected, actualDefinitions); } @Test @@ -74,7 +73,7 @@ void getArrayDefinitions() throws IOException { String expected = jsonResource("/schemas/array-definitions.json"); System.out.println("Got: " + actualDefinitions); - assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(actualDefinitions)); + assertEquals(expected, actualDefinitions); } @Test @@ -85,7 +84,7 @@ void getComplexDefinitions() throws IOException { String expected = jsonResource("/schemas/complex-definitions.json"); System.out.println("Got: " + actualDefinitions); - assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(actualDefinitions)); + assertEquals(expected, actualDefinitions); } @Test @@ -96,7 +95,7 @@ void getListWrapperDefinitions() throws IOException { String expected = jsonResource("/schemas/generics-wrapper-definitions.json"); System.out.println("Got: " + actualDefinitions); - assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(actualDefinitions)); + assertEquals(expected, actualDefinitions); } @Test @@ -257,7 +256,7 @@ void testSchemaWithOneOf() throws IOException { String expected = jsonResource("/schemas/annotation-definitions.json"); System.out.println("Got: " + actualDefinitions); - assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(actualDefinitions)); + assertEquals(expected, actualDefinitions); } @Data