diff --git a/.gitignore b/.gitignore index 796d33cb9..a2da0882e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ springwolf-bindings/springwolf-sqs-binding/build/ node_modules/ asyncapi.actual.json +asyncapi.actual.yaml # Eclipse IDE .classpath diff --git a/springwolf-core/build.gradle b/springwolf-core/build.gradle index d75436a25..1401958f9 100644 --- a/springwolf-core/build.gradle +++ b/springwolf-core/build.gradle @@ -14,6 +14,7 @@ dependencies { implementation "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}" implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}" + implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}" implementation "org.slf4j:slf4j-api:${slf4jApiVersion}" diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/yaml/DefaultExampleYamlValueSerializer.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/yaml/DefaultExampleYamlValueSerializer.java index 36b0f25c3..38cdcb2db 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/yaml/DefaultExampleYamlValueSerializer.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/yaml/DefaultExampleYamlValueSerializer.java @@ -4,11 +4,24 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; +import io.github.springwolf.core.configuration.properties.SpringwolfConfigProperties; import io.swagger.v3.core.util.Yaml; public class DefaultExampleYamlValueSerializer implements ExampleYamlValueSerializer { - private static final ObjectMapper yamlMapper = Yaml.mapper(); + private final ObjectMapper yamlMapper; + + public DefaultExampleYamlValueSerializer(SpringwolfConfigProperties springwolfConfigProperties) { + this.yamlMapper = Yaml.mapper(); + + if (springwolfConfigProperties.isStudioCompatibility()) { + // AsyncApi Studio has problems with missing quotes on dates, so we add quotes on every example + // see https://github.com/springwolf/springwolf-core/issues/820 + ((YAMLFactory) yamlMapper.getFactory()).disable(YAMLGenerator.Feature.MINIMIZE_QUOTES); + } + } @Override public String writeDocumentAsYamlString(JsonNode node) throws JsonProcessingException { diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/yaml/ExampleYamlValueGenerator.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/yaml/ExampleYamlValueGenerator.java index 1ac98a505..daf3c2ff4 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/yaml/ExampleYamlValueGenerator.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/yaml/ExampleYamlValueGenerator.java @@ -6,6 +6,7 @@ import io.github.springwolf.core.asyncapi.components.examples.walkers.ExampleValueGenerator; import io.github.springwolf.core.asyncapi.components.examples.walkers.PropertyExample; import io.github.springwolf.core.asyncapi.components.examples.walkers.json.ExampleJsonValueGenerator; +import io.github.springwolf.core.configuration.properties.SpringwolfConfigProperties; import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.media.StringSchema; import lombok.RequiredArgsConstructor; @@ -24,6 +25,7 @@ public class ExampleYamlValueGenerator implements ExampleValueGenerator lookupSchemaName(Schema schema) { public String prepareForSerialization(Schema schema, JsonNode exampleObject) { final String name = schema.getName(); try { - // spec workaround to embedded yaml examples as string https://github.com/asyncapi/spec/issues/1038 - schema.setType(OVERRIDE_SCHEMA.getType()); - schema.setTypes(OVERRIDE_SCHEMA.getTypes()); + if (springwolfConfigProperties.isStudioCompatibility()) { + + // spec workaround to embedded yaml examples as string https://github.com/asyncapi/spec/issues/1038 + schema.setType(OVERRIDE_SCHEMA.getType()); + schema.setTypes(OVERRIDE_SCHEMA.getTypes()); + } return exampleYamlValueSerializer.writeDocumentAsYamlString(exampleObject); } catch (JsonProcessingException e) { diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/configuration/SpringwolfAutoConfiguration.java b/springwolf-core/src/main/java/io/github/springwolf/core/configuration/SpringwolfAutoConfiguration.java index d0b5efcf8..a15def408 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/configuration/SpringwolfAutoConfiguration.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/configuration/SpringwolfAutoConfiguration.java @@ -162,14 +162,17 @@ public SchemaWalker xmlSchemaWalker(ExampleXmlValueSerializer exampleXmlValueSer @Bean @ConditionalOnMissingBean - public ExampleYamlValueSerializer defaultExampleYamlValueSerializer() { - return new DefaultExampleYamlValueSerializer(); + public ExampleYamlValueSerializer defaultExampleYamlValueSerializer( + SpringwolfConfigProperties springwolfConfigProperties) { + return new DefaultExampleYamlValueSerializer(springwolfConfigProperties); } @Bean - public SchemaWalker yamlSchemaWalker(ExampleYamlValueSerializer exampleYamlValueSerializer) { - return new DefaultSchemaWalker<>( - new ExampleYamlValueGenerator(new ExampleJsonValueGenerator(), exampleYamlValueSerializer)); + public SchemaWalker yamlSchemaWalker( + ExampleYamlValueSerializer exampleYamlValueSerializer, + SpringwolfConfigProperties springwolfConfigProperties) { + return new DefaultSchemaWalker<>(new ExampleYamlValueGenerator( + new ExampleJsonValueGenerator(), exampleYamlValueSerializer, springwolfConfigProperties)); } @Bean diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/configuration/properties/SpringwolfConfigProperties.java b/springwolf-core/src/main/java/io/github/springwolf/core/configuration/properties/SpringwolfConfigProperties.java index 8877a5f48..5fc4bc202 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/configuration/properties/SpringwolfConfigProperties.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/configuration/properties/SpringwolfConfigProperties.java @@ -56,6 +56,13 @@ public enum InitMode { */ private boolean useFqn = true; + /** + * Feature toggle to enable/disable all workarounds for AsyncApi Studio + * to ensure a best-effort out-of-the-box experience. + * @see https://studio.asyncapi.com/ + */ + private boolean studioCompatibility = true; + @Deprecated(forRemoval = true) private Paths paths = new Paths(); diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/DefaultYamlComponentsServiceTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/DefaultYamlComponentsServiceTest.java index aa44d7dbe..cd22f8401 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/DefaultYamlComponentsServiceTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/DefaultYamlComponentsServiceTest.java @@ -43,8 +43,11 @@ class DefaultYamlComponentsServiceTest { private static final String CONTENT_TYPE_APPLICATION_YAML = "application/yaml"; - private final ExampleYamlValueGenerator exampleYamlValueGenerator = - new ExampleYamlValueGenerator(new ExampleJsonValueGenerator(), new DefaultExampleYamlValueSerializer()); + private final SpringwolfConfigProperties springwolfConfigProperties = new SpringwolfConfigProperties(); + private final ExampleYamlValueGenerator exampleYamlValueGenerator = new ExampleYamlValueGenerator( + new ExampleJsonValueGenerator(), + new DefaultExampleYamlValueSerializer(springwolfConfigProperties), + springwolfConfigProperties); private final SwaggerSchemaService schemaService = new SwaggerSchemaService( List.of(), diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalkerYamlIntegrationTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalkerYamlIntegrationTest.java index 587dafca5..e1037c6bb 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalkerYamlIntegrationTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalkerYamlIntegrationTest.java @@ -5,6 +5,7 @@ import io.github.springwolf.core.asyncapi.components.examples.walkers.json.ExampleJsonValueGenerator; import io.github.springwolf.core.asyncapi.components.examples.walkers.yaml.DefaultExampleYamlValueSerializer; import io.github.springwolf.core.asyncapi.components.examples.walkers.yaml.ExampleYamlValueGenerator; +import io.github.springwolf.core.configuration.properties.SpringwolfConfigProperties; import io.swagger.v3.oas.models.media.ArraySchema; import io.swagger.v3.oas.models.media.BinarySchema; import io.swagger.v3.oas.models.media.BooleanSchema; @@ -31,8 +32,11 @@ class DefaultSchemaWalkerYamlIntegrationTest { - private final ExampleYamlValueGenerator exampleYamlValueGenerator = - new ExampleYamlValueGenerator(new ExampleJsonValueGenerator(), new DefaultExampleYamlValueSerializer()); + private final SpringwolfConfigProperties springwolfConfigProperties = new SpringwolfConfigProperties(); + private final ExampleYamlValueGenerator exampleYamlValueGenerator = new ExampleYamlValueGenerator( + new ExampleJsonValueGenerator(), + new DefaultExampleYamlValueSerializer(springwolfConfigProperties), + springwolfConfigProperties); private final DefaultSchemaWalker jsonSchemaWalker = new DefaultSchemaWalker<>(exampleYamlValueGenerator); @@ -68,7 +72,7 @@ void build(TestInfo testInfo) { String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); assertThat(actualString).isEqualTo(""" - string + "string" """); } @@ -198,7 +202,7 @@ void type_string(TestInfo testInfo) { String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); assertThat(actualString).isEqualTo(""" - string + "string" """); } @@ -211,7 +215,7 @@ void type_string_example_set(TestInfo testInfo) { String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); assertThat(actualString).isEqualTo(""" - custom-example-value + "custom-example-value" """); } @@ -225,7 +229,7 @@ void type_string_from_enum(TestInfo testInfo) { String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); assertThat(actualString).isEqualTo(""" - EnumItem1 + "EnumItem1" """); } @@ -238,7 +242,7 @@ void type_string_format_byte(TestInfo testInfo) { String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); assertThat(actualString).isEqualTo(""" - YmFzZTY0LWV4YW1wbGU= + "YmFzZTY0LWV4YW1wbGU=" """); } @@ -264,7 +268,7 @@ void type_string_format_date(TestInfo testInfo) { String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); assertThat(actualString).isEqualTo(""" - 2015-07-20 + "2015-07-20" """); } @@ -277,7 +281,7 @@ void type_string_format_datetime(TestInfo testInfo) { assertThat(actualString) .isEqualTo(""" - 2015-07-20T15:49:04-07:00 + "2015-07-20T15:49:04-07:00" """); } @@ -289,7 +293,7 @@ void type_string_format_email(TestInfo testInfo) { String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); assertThat(actualString).isEqualTo(""" - example@example.com + "example@example.com" """); } @@ -301,7 +305,7 @@ void type_string_format_password(TestInfo testInfo) { String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); assertThat(actualString).isEqualTo(""" - string-password + "string-password" """); } @@ -314,7 +318,7 @@ void type_string_format_uuid(TestInfo testInfo) { assertThat(actualString) .isEqualTo(""" - 3fa85f64-5717-4562-b3fc-2c963f66afa6 + "3fa85f64-5717-4562-b3fc-2c963f66afa6" """); } @@ -360,7 +364,7 @@ void type_primitive_array(TestInfo testInfo) { String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); assertThat(actualString).isEqualTo(""" - - string + - "string" """); } } @@ -383,7 +387,7 @@ void type_object_array(TestInfo testInfo) { .isEqualTo( """ - b: true - s: string + s: "string" """); } @@ -399,7 +403,7 @@ void composite_object_without_references(TestInfo testInfo) { assertThat(actualString) .isEqualTo(""" b: true - s: string + s: "string" """); } @@ -423,8 +427,8 @@ void composite_object_with_references(TestInfo testInfo) { """ f: b: true - s: string - s: string + s: "string" + s: "string" """); } @@ -440,7 +444,7 @@ void object_with_anyOf(TestInfo testInfo) { String actualString = jsonSchemaWalker.fromSchema(compositeSchema, Map.of("Nested", propertySchema)); assertThat(actualString).isEqualTo(""" - anyOfField: string + anyOfField: "string" """); } @@ -456,7 +460,7 @@ void object_with_oneOf(TestInfo testInfo) { String actualString = jsonSchemaWalker.fromSchema(compositeSchema, Map.of("Nested", propertySchema)); assertThat(actualString).isEqualTo(""" - oneOfField: string + oneOfField: "string" """); } @@ -481,7 +485,7 @@ void object_with_allOf(TestInfo testInfo) { .isEqualTo( """ allOfField: - field1: string + field1: "string" field2: 1.1 """); } @@ -497,7 +501,7 @@ void schema_with_problematic_object_toString_example(TestInfo testInfo) { assertThat(actualString) .isEqualTo( """ - Text with special character /\\\\'\\b\\f\\t\\r\\n. + "Text with special character /\\\\\\\\'\\\\b\\\\f\\\\t\\\\r\\\\n." """); } diff --git a/springwolf-core/src/test/resources/schemas/yaml/annotation-definitions-yaml.json b/springwolf-core/src/test/resources/schemas/yaml/annotation-definitions-yaml.json index d388bb994..934a57569 100644 --- a/springwolf-core/src/test/resources/schemas/yaml/annotation-definitions-yaml.json +++ b/springwolf-core/src/test/resources/schemas/yaml/annotation-definitions-yaml.json @@ -1,7 +1,7 @@ { "io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceTest$SchemaWithOneOf$AllOf" : { "type" : "string", - "examples" : [ "firstOne: string\nfirstTwo: 0\nsecondOne: string\nsecondTwo: true\n" ], + "examples" : [ "firstOne: \"string\"\nfirstTwo: 0\nsecondOne: \"string\"\nsecondTwo: true\n" ], "allOf" : [ { "$ref" : "#/components/schemas/io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceTest$SchemaWithOneOf$ImplementationOne" }, { @@ -10,7 +10,7 @@ }, "io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceTest$SchemaWithOneOf$AnyOf" : { "type" : "string", - "examples" : [ "firstOne: string\nsecondOne: string\n" ], + "examples" : [ "firstOne: \"string\"\nsecondOne: \"string\"\n" ], "anyOf" : [ { "$ref" : "#/components/schemas/io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceTest$SchemaWithOneOf$ImplementationOne" }, { @@ -27,7 +27,7 @@ "type" : "string" } }, - "examples" : [ "firstOne: string\nsecondOne: string\n" ] + "examples" : [ "firstOne: \"string\"\nsecondOne: \"string\"\n" ] }, "io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceTest$SchemaWithOneOf$ImplementationTwo" : { "type" : "string", @@ -44,7 +44,7 @@ }, "io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceTest$SchemaWithOneOf$OneOf" : { "type" : "string", - "examples" : [ "|\n firstOne: string\n secondOne: string\n" ], + "examples" : [ "\"firstOne: \\\"string\\\"\\nsecondOne: \\\"string\\\"\\n\"\n" ], "oneOf" : [ { "$ref" : "#/components/schemas/io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceTest$SchemaWithOneOf$ImplementationOne" }, { @@ -67,6 +67,6 @@ "$ref" : "#/components/schemas/io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceTest$SchemaWithOneOf$OneOf" } }, - "examples" : [ "allOf: |\n firstOne: string\n firstTwo: 0\n secondOne: string\n secondTwo: true\nanyOf: |\n firstOne: string\n secondOne: string\nfield: string\noneOf: |\n |\n firstOne: string\n secondOne: string\n" ] + "examples" : [ "allOf: \"firstOne: \\\"string\\\"\\nfirstTwo: 0\\nsecondOne: \\\"string\\\"\\nsecondTwo: true\\n\"\nanyOf: \"firstOne: \\\"string\\\"\\nsecondOne: \\\"string\\\"\\n\"\nfield: \"string\"\noneOf: \"\\\"firstOne: \\\\\\\"string\\\\\\\"\\\\nsecondOne: \\\\\\\"string\\\\\\\"\\\\n\\\"\\n\"\n" ] } } diff --git a/springwolf-core/src/test/resources/schemas/yaml/api-payload-yaml.json b/springwolf-core/src/test/resources/schemas/yaml/api-payload-yaml.json index 5e3e567c3..a42b39e2d 100644 --- a/springwolf-core/src/test/resources/schemas/yaml/api-payload-yaml.json +++ b/springwolf-core/src/test/resources/schemas/yaml/api-payload-yaml.json @@ -3,6 +3,6 @@ "type" : "string", "description" : "The payload in the envelop", "maxLength" : 10, - "examples" : [ "string\n" ] + "examples" : [ "\"string\"\n" ] } } diff --git a/springwolf-core/src/test/resources/schemas/yaml/array-definitions-yaml.json b/springwolf-core/src/test/resources/schemas/yaml/array-definitions-yaml.json index 4a3b592e5..a43eeb428 100644 --- a/springwolf-core/src/test/resources/schemas/yaml/array-definitions-yaml.json +++ b/springwolf-core/src/test/resources/schemas/yaml/array-definitions-yaml.json @@ -9,7 +9,7 @@ } } }, - "examples" : [ "flist:\n- b: true\n s: string\n" ] + "examples" : [ "flist:\n- b: true\n s: \"string\"\n" ] }, "io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceTest$SimpleFoo" : { "type" : "string", @@ -21,6 +21,6 @@ "type" : "string" } }, - "examples" : [ "b: true\ns: string\n" ] + "examples" : [ "b: true\ns: \"string\"\n" ] } } diff --git a/springwolf-core/src/test/resources/schemas/yaml/complex-definitions-yaml.json b/springwolf-core/src/test/resources/schemas/yaml/complex-definitions-yaml.json index 4280e1d9d..775c1ccf2 100644 --- a/springwolf-core/src/test/resources/schemas/yaml/complex-definitions-yaml.json +++ b/springwolf-core/src/test/resources/schemas/yaml/complex-definitions-yaml.json @@ -28,7 +28,7 @@ "type" : "string" } }, - "examples" : [ "b: true\nd: 1.1\ndt: 2015-07-20T15:49:04-07:00\nf: 1.1\ni: 0\n\"n\":\n nba: YmFzZTY0LWV4YW1wbGU=\n nc:\n cyclic: {}\n nli:\n - 0\n nmfm: {}\n ns: string\n nsm:\n - s: string\n nu: 3fa85f64-5717-4562-b3fc-2c963f66afa6\ns: string\n" ] + "examples" : [ "b: true\nd: 1.1\ndt: \"2015-07-20T15:49:04-07:00\"\nf: 1.1\ni: 0\n\"n\":\n nba: \"YmFzZTY0LWV4YW1wbGU=\"\n nc:\n cyclic: {}\n nli:\n - 0\n nmfm: {}\n ns: \"string\"\n nsm:\n - s: \"string\"\n nu: \"3fa85f64-5717-4562-b3fc-2c963f66afa6\"\ns: \"string\"\n" ] }, "io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceTest$ComplexFoo$Nested" : { "type" : "string", @@ -68,7 +68,7 @@ "format" : "uuid" } }, - "examples" : [ "nba: YmFzZTY0LWV4YW1wbGU=\nnc:\n cyclic: {}\nnli:\n- 0\nnmfm: {}\nns: string\nnsm:\n- s: string\nnu: 3fa85f64-5717-4562-b3fc-2c963f66afa6\n" ] + "examples" : [ "nba: \"YmFzZTY0LWV4YW1wbGU=\"\nnc:\n cyclic: {}\nnli:\n- 0\nnmfm: {}\nns: \"string\"\nnsm:\n- s: \"string\"\nnu: \"3fa85f64-5717-4562-b3fc-2c963f66afa6\"\n" ] }, "io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceTest$ComplexFoo$Nested$Cyclic" : { "type" : "string", @@ -86,6 +86,6 @@ "type" : "string" } }, - "examples" : [ "s: string\n" ] + "examples" : [ "s: \"string\"\n" ] } } diff --git a/springwolf-core/src/test/resources/schemas/yaml/definitions-yaml.json b/springwolf-core/src/test/resources/schemas/yaml/definitions-yaml.json index 8c46c35d2..44a7ae5be 100644 --- a/springwolf-core/src/test/resources/schemas/yaml/definitions-yaml.json +++ b/springwolf-core/src/test/resources/schemas/yaml/definitions-yaml.json @@ -9,7 +9,7 @@ "type" : "string" } }, - "examples" : [ "f:\n b: true\n s: string\ns: string\n" ] + "examples" : [ "f:\n b: true\n s: \"string\"\ns: \"string\"\n" ] }, "io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceTest$FooWithEnum" : { "type" : "string", @@ -22,7 +22,7 @@ "type" : "string" } }, - "examples" : [ "b: BAR1\ns: string\n" ] + "examples" : [ "b: \"BAR1\"\ns: \"string\"\n" ] }, "io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceTest$SimpleFoo" : { "type" : "string", @@ -34,6 +34,6 @@ "type" : "string" } }, - "examples" : [ "b: true\ns: string\n" ] + "examples" : [ "b: true\ns: \"string\"\n" ] } } diff --git a/springwolf-core/src/test/resources/schemas/yaml/documented-definitions-yaml.json b/springwolf-core/src/test/resources/schemas/yaml/documented-definitions-yaml.json index 3c2a26b20..f2d06a7ee 100644 --- a/springwolf-core/src/test/resources/schemas/yaml/documented-definitions-yaml.json +++ b/springwolf-core/src/test/resources/schemas/yaml/documented-definitions-yaml.json @@ -53,7 +53,7 @@ } }, "description" : "foo model", - "examples" : [ "bi: 0\ndt: 2000-01-01T02:00:00+02:00\nf:\n b: true\n s: string\nld: 2024-04-24\nls_plain:\n- string\nmss:\n key1: value1\nmss_plain: {}\ns: s value\n" ], + "examples" : [ "bi: 0\ndt: \"2000-01-01T02:00:00+02:00\"\nf:\n b: true\n s: \"string\"\nld: \"2024-04-24\"\nls_plain:\n- \"string\"\nmss:\n key1: \"value1\"\nmss_plain: {}\ns: \"s value\"\n" ], "required" : [ "dt", "f", "s" ] }, "io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceTest$SimpleFoo" : { @@ -66,6 +66,6 @@ "type" : "string" } }, - "examples" : [ "b: true\ns: string\n" ] + "examples" : [ "b: true\ns: \"string\"\n" ] } } diff --git a/springwolf-core/src/test/resources/schemas/yaml/generics-wrapper-definitions-yaml.json b/springwolf-core/src/test/resources/schemas/yaml/generics-wrapper-definitions-yaml.json index d75724c85..e36bbf84b 100644 --- a/springwolf-core/src/test/resources/schemas/yaml/generics-wrapper-definitions-yaml.json +++ b/springwolf-core/src/test/resources/schemas/yaml/generics-wrapper-definitions-yaml.json @@ -6,6 +6,6 @@ "type" : "boolean" } }, - "examples" : [ "- string\n" ] + "examples" : [ "- \"string\"\n" ] } } diff --git a/springwolf-examples/springwolf-kafka-example/src/test/java/io/github/springwolf/examples/kafka/ApiIntegrationTest.java b/springwolf-examples/springwolf-kafka-example/src/test/java/io/github/springwolf/examples/kafka/ApiIntegrationTest.java index 34b4efd96..255f5ebc4 100644 --- a/springwolf-examples/springwolf-kafka-example/src/test/java/io/github/springwolf/examples/kafka/ApiIntegrationTest.java +++ b/springwolf-examples/springwolf-kafka-example/src/test/java/io/github/springwolf/examples/kafka/ApiIntegrationTest.java @@ -43,4 +43,18 @@ void asyncApiResourceArtifactTest() throws IOException { assertEquals(expected, actualPatched); } + + @Test + void asyncApiResourceArtifactYamlTest() throws IOException { + String url = "/springwolf/docs.yaml"; + String actual = restTemplate.getForObject(url, String.class); + // When running with EmbeddedKafka, the kafka bootstrap server does run on random ports + String actualPatched = actual.replace(bootstrapServers, "kafka:29092"); + Files.writeString(Path.of("src", "test", "resources", "asyncapi.actual.yaml"), actualPatched); + + InputStream s = this.getClass().getResourceAsStream("/asyncapi.yaml"); + String expected = new String(s.readAllBytes(), StandardCharsets.UTF_8); + + assertEquals(expected, actualPatched); + } } 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 fef2dc6af..4af484bb0 100644 --- a/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.json +++ b/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.json @@ -1206,7 +1206,7 @@ } }, "examples": [ - "someEnum: FOO1\nsomeLong: 0\nsomeString: string\n" + "someEnum: \"FOO1\"\nsomeLong: 0\nsomeString: \"string\"\n" ], "x-json-schema": { "$schema": "https://json-schema.org/draft-04/schema#", @@ -1968,4 +1968,4 @@ ] } } -} \ No newline at end of file +} diff --git a/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.yaml b/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.yaml new file mode 100644 index 000000000..94e897664 --- /dev/null +++ b/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.yaml @@ -0,0 +1,1378 @@ +asyncapi: 3.0.0 +info: + title: Springwolf example project - Kafka + version: 1.0.0 + description: "Springwolf example project to demonstrate springwolfs abilities, including\ + \ **markdown** support for descriptions." + contact: + name: springwolf + url: https://github.com/springwolf/springwolf-core + email: example@example.com + license: + name: Apache License 2.0 + x-generator: springwolf +defaultContentType: application/json +servers: + kafka-server: + host: kafka:29092 + protocol: kafka +channels: + another-topic: + address: another-topic + messages: + io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto: + $ref: "#/components/messages/io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto" + bindings: + kafka: + bindingVersion: 0.5.0 + avro-topic: + address: avro-topic + messages: + io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto: + $ref: "#/components/messages/io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto" + example-topic: + address: example-topic + messages: + io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto: + $ref: "#/components/messages/io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto" + bindings: + kafka: + bindingVersion: 0.5.0 + integer-topic: + address: integer-topic + messages: + java.lang.Number: + $ref: "#/components/messages/java.lang.Number" + bindings: + kafka: + bindingVersion: 0.5.0 + multi-payload-topic: + address: multi-payload-topic + messages: + io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto: + $ref: "#/components/messages/io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto" + io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto: + $ref: "#/components/messages/io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto" + javax.money.MonetaryAmount: + $ref: "#/components/messages/javax.money.MonetaryAmount" + no-payload-used-topic: + address: no-payload-used-topic + messages: + PayloadNotUsed: + $ref: "#/components/messages/PayloadNotUsed" + bindings: + kafka: + bindingVersion: 0.5.0 + protobuf-topic: + address: protobuf-topic + messages: + io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto$Message: + $ref: "#/components/messages/io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto$Message" + bindings: + kafka: + bindingVersion: 0.5.0 + string-topic: + address: string-topic + messages: + io.github.springwolf.examples.kafka.consumers.StringConsumer$StringEnvelope: + $ref: "#/components/messages/io.github.springwolf.examples.kafka.consumers.StringConsumer$StringEnvelope" + java.lang.String: + $ref: "#/components/messages/java.lang.String" + topic-defined-via-asyncPublisher-annotation: + address: topic-defined-via-asyncPublisher-annotation + messages: + io.github.springwolf.examples.kafka.dtos.NestedPayloadDto: + $ref: "#/components/messages/io.github.springwolf.examples.kafka.dtos.NestedPayloadDto" + servers: + - $ref: "#/servers/kafka-server" + vehicle-topic: + address: vehicle-topic + messages: + io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase: + $ref: "#/components/messages/io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase" + bindings: + kafka: + bindingVersion: 0.5.0 + xml-topic: + address: xml-topic + messages: + io.github.springwolf.examples.kafka.dtos.XmlPayloadDto: + $ref: "#/components/messages/io.github.springwolf.examples.kafka.dtos.XmlPayloadDto" + yaml-topic: + address: yaml-topic + messages: + io.github.springwolf.examples.kafka.dtos.YamlPayloadDto: + $ref: "#/components/messages/io.github.springwolf.examples.kafka.dtos.YamlPayloadDto" +components: + schemas: + HeadersNotDocumented: + type: object + properties: {} + description: "There can be headers, but they are not explicitly documented." + examples: + - {} + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + description: "There can be headers, but they are not explicitly documented." + type: object + HeadersNotUsed: + type: object + properties: {} + description: No headers are present. + examples: + - {} + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + description: No headers are present. + type: object + PayloadNotUsed: + type: object + properties: {} + description: No payload specified + examples: + - {} + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + description: No payload specified + type: object + SpringDefaultHeaderAndCloudEvent: + type: object + properties: + __TypeId__: + type: string + description: Spring Type Id Header + enum: + - io.github.springwolf.examples.kafka.dtos.NestedPayloadDto + examples: + - io.github.springwolf.examples.kafka.dtos.NestedPayloadDto + ce_id: + type: string + description: CloudEvent Id Header + enum: + - 2c60089e-6f39-459d-8ced-2d6df7e4c03a + examples: + - 2c60089e-6f39-459d-8ced-2d6df7e4c03a + ce_source: + type: string + description: CloudEvent Source Header + enum: + - http://localhost + examples: + - http://localhost + ce_specversion: + type: string + description: CloudEvent Spec Version Header + enum: + - "1.0" + examples: + - "1.0" + ce_subject: + type: string + description: CloudEvent Subject Header + enum: + - Springwolf example project - Kafka + examples: + - Springwolf example project - Kafka + ce_time: + type: string + description: CloudEvent Time Header + enum: + - 2023-10-28 20:01:23+00:00 + examples: + - 2023-10-28 20:01:23+00:00 + ce_type: + type: string + description: CloudEvent Payload Type Header + enum: + - NestedPayloadDto.v1 + examples: + - NestedPayloadDto.v1 + content-type: + type: string + description: CloudEvent Content-Type Header + enum: + - application/json + examples: + - application/json + description: Spring __TypeId__ and CloudEvent Headers + examples: + - __TypeId__: io.github.springwolf.examples.kafka.dtos.NestedPayloadDto + ce_id: 2c60089e-6f39-459d-8ced-2d6df7e4c03a + ce_source: http://localhost + ce_specversion: "1.0" + ce_subject: Springwolf example project - Kafka + ce_time: 2023-10-28 20:01:23+00:00 + ce_type: NestedPayloadDto.v1 + content-type: application/json + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + description: Spring __TypeId__ and CloudEvent Headers + properties: + __TypeId__: + description: Spring Type Id Header + enum: + - io.github.springwolf.examples.kafka.dtos.NestedPayloadDto + type: string + ce_id: + description: CloudEvent Id Header + enum: + - 2c60089e-6f39-459d-8ced-2d6df7e4c03a + type: string + ce_source: + description: CloudEvent Source Header + enum: + - http://localhost + type: string + ce_specversion: + description: CloudEvent Spec Version Header + enum: + - "1.0" + type: string + ce_subject: + description: CloudEvent Subject Header + enum: + - Springwolf example project - Kafka + type: string + ce_time: + description: CloudEvent Time Header + enum: + - 2023-10-28 20:01:23+00:00 + type: string + ce_type: + description: CloudEvent Payload Type Header + enum: + - NestedPayloadDto.v1 + type: string + content-type: + description: CloudEvent Content-Type Header + enum: + - application/json + type: string + type: object + SpringKafkaDefaultHeaders-AnotherPayloadAvroDto: + type: object + properties: + __TypeId__: + type: string + description: Spring Type Id Header + enum: + - io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto + examples: + - io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto + examples: + - __TypeId__: io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + __TypeId__: + description: Spring Type Id Header + enum: + - io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto + type: string + type: object + SpringKafkaDefaultHeaders-AnotherPayloadDto: + type: object + properties: + __TypeId__: + type: string + description: Spring Type Id Header + enum: + - io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto + examples: + - io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto + examples: + - __TypeId__: io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + __TypeId__: + description: Spring Type Id Header + enum: + - io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto + type: string + type: object + SpringKafkaDefaultHeaders-ExamplePayloadDto: + type: object + properties: + __TypeId__: + type: string + description: Spring Type Id Header + enum: + - io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto + examples: + - io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto + kafka_offset: + type: number + examples: + - 1.1 + kafka_receivedMessageKey: + type: string + examples: + - '"string"' + examples: + - __TypeId__: io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto + kafka_offset: 1.1 + kafka_receivedMessageKey: string + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + __TypeId__: + description: Spring Type Id Header + enum: + - io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto + type: string + kafka_offset: + type: number + kafka_receivedMessageKey: + type: string + type: object + SpringKafkaDefaultHeaders-Integer: + type: object + properties: + __TypeId__: + type: string + description: Spring Type Id Header + enum: + - java.lang.Number + examples: + - java.lang.Number + examples: + - __TypeId__: java.lang.Number + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + __TypeId__: + description: Spring Type Id Header + enum: + - java.lang.Number + type: string + type: object + SpringKafkaDefaultHeaders-Message: + type: object + properties: + __TypeId__: + type: string + description: Spring Type Id Header + enum: + - io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto$Message + examples: + - io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto$Message + examples: + - __TypeId__: io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto$Message + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + __TypeId__: + description: Spring Type Id Header + enum: + - io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto$Message + type: string + type: object + SpringKafkaDefaultHeaders-MonetaryAmount: + type: object + properties: + __TypeId__: + type: string + description: Spring Type Id Header + enum: + - javax.money.MonetaryAmount + examples: + - javax.money.MonetaryAmount + examples: + - __TypeId__: javax.money.MonetaryAmount + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + __TypeId__: + description: Spring Type Id Header + enum: + - javax.money.MonetaryAmount + type: string + type: object + SpringKafkaDefaultHeaders-PayloadNotUsed: + type: object + properties: + __TypeId__: + type: string + description: Spring Type Id Header + enum: + - PayloadNotUsed + examples: + - PayloadNotUsed + examples: + - __TypeId__: PayloadNotUsed + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + __TypeId__: + description: Spring Type Id Header + enum: + - PayloadNotUsed + type: string + type: object + SpringKafkaDefaultHeaders-String: + type: object + properties: + __TypeId__: + type: string + description: Spring Type Id Header + enum: + - java.lang.String + examples: + - java.lang.String + examples: + - __TypeId__: java.lang.String + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + __TypeId__: + description: Spring Type Id Header + enum: + - java.lang.String + type: string + type: object + SpringKafkaDefaultHeaders-VehicleBase: + type: object + properties: + __TypeId__: + type: string + description: Spring Type Id Header + enum: + - io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase + examples: + - io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase + examples: + - __TypeId__: io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + __TypeId__: + description: Spring Type Id Header + enum: + - io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase + type: string + type: object + SpringKafkaDefaultHeaders-XmlPayloadDto: + type: object + properties: + __TypeId__: + type: string + description: Spring Type Id Header + enum: + - io.github.springwolf.examples.kafka.dtos.XmlPayloadDto + examples: + - io.github.springwolf.examples.kafka.dtos.XmlPayloadDto + examples: + - __TypeId__: io.github.springwolf.examples.kafka.dtos.XmlPayloadDto + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + __TypeId__: + description: Spring Type Id Header + enum: + - io.github.springwolf.examples.kafka.dtos.XmlPayloadDto + type: string + type: object + SpringKafkaDefaultHeaders-YamlPayloadDto: + type: object + properties: + __TypeId__: + type: string + description: Spring Type Id Header + enum: + - io.github.springwolf.examples.kafka.dtos.YamlPayloadDto + examples: + - io.github.springwolf.examples.kafka.dtos.YamlPayloadDto + examples: + - __TypeId__: io.github.springwolf.examples.kafka.dtos.YamlPayloadDto + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + __TypeId__: + description: Spring Type Id Header + enum: + - io.github.springwolf.examples.kafka.dtos.YamlPayloadDto + type: string + type: object + io.github.springwolf.examples.kafka.consumers.StringConsumer$StringEnvelope: + title: StringEnvelope + type: string + description: Payload description using @Schema annotation and @AsyncApiPayload + within envelope class + maxLength: 100 + examples: + - '"string"' + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + description: Payload description using @Schema annotation and @AsyncApiPayload + within envelope class + maxLength: 100 + title: StringEnvelope + type: string + io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto: + title: AnotherPayloadAvroDto + type: object + properties: + examplePayloadAvroDto: + $ref: "#/components/schemas/io.github.springwolf.examples.kafka.dto.avro.ExamplePayloadAvroDto" + someEnum: + type: string + enum: + - FOO1 + - FOO2 + - FOO3 + examples: + - examplePayloadAvroDto: + someLong: 0 + someString: string + someEnum: FOO1 + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + examplePayloadAvroDto: + properties: + someLong: + format: int64 + type: integer + someString: + type: string + type: object + someEnum: + enum: + - FOO1 + - FOO2 + - FOO3 + type: string + title: AnotherPayloadAvroDto + type: object + io.github.springwolf.examples.kafka.dto.avro.ExamplePayloadAvroDto: + type: object + properties: + someLong: + type: integer + format: int64 + someString: + type: string + examples: + - someLong: 0 + someString: string + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + someLong: + format: int64 + type: integer + someString: + type: string + type: object + io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto$Message: + title: Message + type: object + properties: + someEnum: + type: string + enum: + - FOO1 + - FOO2 + - FOO3 + - UNRECOGNIZED + someLong: + type: integer + format: int64 + someString: + type: string + examples: + - someEnum: FOO1 + someLong: 0 + someString: string + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + someEnum: + enum: + - FOO1 + - FOO2 + - FOO3 + - UNRECOGNIZED + type: string + someLong: + format: int64 + type: integer + someString: + type: string + title: Message + type: object + io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto: + title: AnotherPayloadDto + type: object + properties: + example: + $ref: "#/components/schemas/io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto" + foo: + type: string + description: Foo field + examples: + - bar + description: Another payload model + examples: + - example: + someEnum: FOO2 + someLong: 5 + someString: some string value + foo: bar + required: + - example + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + description: Another payload model + properties: + example: + description: | + Example payload model demonstrating markdown text styling: + **bold**, *cursive* and underlined + properties: + someEnum: + description: Some enum field + enum: + - FOO1 + - FOO2 + - FOO3 + type: string + someLong: + description: Some long field + format: int64 + type: integer + someString: + description: | + ### Some string field with Markdown + + - **bold** + - *cursive* + - images: Springwolf + - and code blocks (json, http, java) + ```json + { + "key1":"value1", + "key2":"value2" + } + ``` + type: string + required: + - someEnum + - someString + title: ExamplePayloadDto + type: object + foo: + description: Foo field + type: string + required: + - example + title: AnotherPayloadDto + type: object + io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto: + title: ExamplePayloadDto + type: object + properties: + someEnum: + type: string + description: Some enum field + enum: + - FOO1 + - FOO2 + - FOO3 + examples: + - FOO2 + someLong: + type: integer + description: Some long field + format: int64 + examples: + - 5 + someString: + type: string + description: | + ### Some string field with Markdown + + - **bold** + - *cursive* + - images: Springwolf + - and code blocks (json, http, java) + ```json + { + "key1":"value1", + "key2":"value2" + } + ``` + examples: + - some string value + description: | + Example payload model demonstrating markdown text styling: + **bold**, *cursive* and underlined + examples: + - someEnum: FOO2 + someLong: 5 + someString: some string value + required: + - someEnum + - someString + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + description: | + Example payload model demonstrating markdown text styling: + **bold**, *cursive* and underlined + properties: + someEnum: + description: Some enum field + enum: + - FOO1 + - FOO2 + - FOO3 + type: string + someLong: + description: Some long field + format: int64 + type: integer + someString: + description: | + ### Some string field with Markdown + + - **bold** + - *cursive* + - images: Springwolf + - and code blocks (json, http, java) + ```json + { + "key1":"value1", + "key2":"value2" + } + ``` + type: string + required: + - someEnum + - someString + title: ExamplePayloadDto + type: object + io.github.springwolf.examples.kafka.dtos.NestedPayloadDto: + title: NestedPayloadDto + type: object + properties: + examplePayloads: + type: array + items: + $ref: "#/components/schemas/io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto" + someStrings: + type: array + items: + type: string + description: Some string field + examples: + - some string value + uniqueItems: true + description: Payload model with nested complex types + examples: + - examplePayloads: + - someEnum: FOO2 + someLong: 5 + someString: some string value + someStrings: + - some string value + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + description: Payload model with nested complex types + properties: + examplePayloads: + items: + description: | + Example payload model demonstrating markdown text styling: + **bold**, *cursive* and underlined + properties: + someEnum: + description: Some enum field + enum: + - FOO1 + - FOO2 + - FOO3 + type: string + someLong: + description: Some long field + format: int64 + type: integer + someString: + description: | + ### Some string field with Markdown + + - **bold** + - *cursive* + - images: Springwolf + - and code blocks (json, http, java) + ```json + { + "key1":"value1", + "key2":"value2" + } + ``` + type: string + required: + - someEnum + - someString + title: ExamplePayloadDto + type: object + type: array + someStrings: + items: + description: Some string field + type: string + type: array + uniqueItems: true + title: NestedPayloadDto + type: object + io.github.springwolf.examples.kafka.dtos.XmlPayloadDto: + title: XmlPayloadDto + type: string + properties: + someAttribute: + type: string + someEnum: + type: string + enum: + - FOO1 + - FOO2 + - FOO3 + someLong: + type: integer + format: int64 + someString: + type: string + examples: + - FOO10string + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + someAttribute: {} + someEnum: + enum: + - FOO1 + - FOO2 + - FOO3 + type: string + someLong: + format: int64 + type: integer + someString: + type: string + title: XmlPayloadDto + type: string + io.github.springwolf.examples.kafka.dtos.YamlPayloadDto: + title: YamlPayloadDto + type: string + properties: + someEnum: + type: string + enum: + - FOO1 + - FOO2 + - FOO3 + someLong: + type: integer + format: int64 + someString: + type: string + examples: + - | + someEnum: "FOO1" + someLong: 0 + someString: "string" + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + someEnum: + enum: + - FOO1 + - FOO2 + - FOO3 + type: string + someLong: + format: int64 + type: integer + someString: + type: string + title: YamlPayloadDto + type: string + io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase: + discriminator: vehicleType + title: VehicleBase + type: object + properties: + powerSource: + type: string + topSpeed: + type: integer + format: int32 + vehicleType: + type: string + description: Demonstrates the use of discriminator for polymorphic deserialization + (not publishable) + examples: + - powerSource: string + topSpeed: 0 + vehicleType: string + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + description: Demonstrates the use of discriminator for polymorphic deserialization + (not publishable) + properties: + powerSource: + type: string + topSpeed: + format: int32 + type: integer + vehicleType: {} + title: VehicleBase + type: object + io.github.springwolf.examples.kafka.dtos.discriminator.VehicleElectricPayloadDto: + type: object + description: Electric vehicle implementation of VehicleBase + examples: + - batteryCapacity: 0 + chargeTime: 0 + powerSource: string + topSpeed: 0 + vehicleType: string + allOf: + - $ref: "#/components/schemas/io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase" + - type: object + properties: + batteryCapacity: + type: integer + format: int32 + chargeTime: + type: integer + format: int32 + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + allOf: + - description: Demonstrates the use of discriminator for polymorphic deserialization + (not publishable) + properties: + powerSource: + type: string + topSpeed: + format: int32 + type: integer + vehicleType: {} + title: VehicleBase + type: object + - properties: + batteryCapacity: {} + chargeTime: {} + type: object + description: Electric vehicle implementation of VehicleBase + type: object + io.github.springwolf.examples.kafka.dtos.discriminator.VehicleGasolinePayloadDto: + type: object + description: Gasoline vehicle implementation of VehicleBase + examples: + - fuelCapacity: 0 + powerSource: string + topSpeed: 0 + vehicleType: string + allOf: + - $ref: "#/components/schemas/io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase" + - type: object + properties: + fuelCapacity: + type: integer + format: int32 + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + allOf: + - description: Demonstrates the use of discriminator for polymorphic deserialization + (not publishable) + properties: + powerSource: + type: string + topSpeed: + format: int32 + type: integer + vehicleType: {} + title: VehicleBase + type: object + - properties: + fuelCapacity: {} + type: object + description: Gasoline vehicle implementation of VehicleBase + type: object + java.lang.Number: + title: Integer + type: number + examples: + - 1.1 + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + title: Integer + type: number + java.lang.String: + title: String + type: string + examples: + - '"string"' + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + title: String + type: string + javax.money.MonetaryAmount: + title: MonetaryAmount + type: object + properties: + amount: + type: number + exclusiveMinimum: 0.01 + examples: + - 99.99 + currency: + type: string + examples: + - USD + examples: + - amount: 99.99 + currency: USD + x-json-schema: + $schema: https://json-schema.org/draft-04/schema# + properties: + amount: + exclusiveMinimum: 0.01 + type: number + currency: + type: string + title: MonetaryAmount + type: object + messages: + PayloadNotUsed: + headers: + $ref: "#/components/schemas/SpringKafkaDefaultHeaders-PayloadNotUsed" + payload: + schemaFormat: application/vnd.aai.asyncapi+json;version=3.0.0 + schema: + $ref: "#/components/schemas/PayloadNotUsed" + name: PayloadNotUsed + title: PayloadNotUsed + bindings: + kafka: + bindingVersion: 0.5.0 + io.github.springwolf.examples.kafka.consumers.StringConsumer$StringEnvelope: + headers: + $ref: "#/components/schemas/HeadersNotUsed" + payload: + schemaFormat: application/vnd.aai.asyncapi+json;version=3.0.0 + schema: + $ref: "#/components/schemas/io.github.springwolf.examples.kafka.consumers.StringConsumer$StringEnvelope" + name: StringPayload + title: StringEnvelope + description: Payload description using @Schema annotation and @AsyncApiPayload + within envelope class + bindings: + kafka: + bindingVersion: 0.5.0 + io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto: + headers: + $ref: "#/components/schemas/HeadersNotDocumented" + payload: + schemaFormat: application/vnd.aai.asyncapi+json;version=3.0.0 + schema: + $ref: "#/components/schemas/io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto" + name: io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto + title: AnotherPayloadAvroDto + bindings: + kafka: + bindingVersion: 0.5.0 + io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto$Message: + headers: + $ref: "#/components/schemas/SpringKafkaDefaultHeaders-Message" + payload: + schemaFormat: application/vnd.aai.asyncapi+json;version=3.0.0 + schema: + $ref: "#/components/schemas/io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto$Message" + name: io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto$Message + title: Message + bindings: + kafka: + bindingVersion: 0.5.0 + io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto: + headers: + $ref: "#/components/schemas/SpringKafkaDefaultHeaders-AnotherPayloadDto" + payload: + schemaFormat: application/vnd.aai.asyncapi+json;version=3.0.0 + schema: + $ref: "#/components/schemas/io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto" + name: io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto + title: AnotherPayloadDto + bindings: + kafka: + bindingVersion: 0.5.0 + io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto: + headers: + $ref: "#/components/schemas/SpringKafkaDefaultHeaders-ExamplePayloadDto" + payload: + schemaFormat: application/vnd.aai.asyncapi+json;version=3.0.0 + schema: + $ref: "#/components/schemas/io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto" + name: io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto + title: ExamplePayloadDto + bindings: + kafka: + key: + type: string + examples: + - '"string"' + bindingVersion: 0.5.0 + io.github.springwolf.examples.kafka.dtos.NestedPayloadDto: + headers: + $ref: "#/components/schemas/SpringDefaultHeaderAndCloudEvent" + payload: + schemaFormat: application/vnd.aai.asyncapi+json;version=3.0.0 + schema: + $ref: "#/components/schemas/io.github.springwolf.examples.kafka.dtos.NestedPayloadDto" + name: io.github.springwolf.examples.kafka.dtos.NestedPayloadDto + title: NestedPayloadDto + description: Payload model with nested complex types + bindings: + kafka: + key: + type: string + description: Kafka Producer Message Key + examples: + - example-key + bindingVersion: 0.5.0 + io.github.springwolf.examples.kafka.dtos.XmlPayloadDto: + headers: + $ref: "#/components/schemas/HeadersNotDocumented" + payload: + schemaFormat: application/vnd.aai.asyncapi+json;version=3.0.0 + schema: + $ref: "#/components/schemas/io.github.springwolf.examples.kafka.dtos.XmlPayloadDto" + contentType: text/xml + name: io.github.springwolf.examples.kafka.dtos.XmlPayloadDto + title: XmlPayloadDto + description: Showcases a xml based message + bindings: + kafka: + bindingVersion: 0.5.0 + io.github.springwolf.examples.kafka.dtos.YamlPayloadDto: + headers: + $ref: "#/components/schemas/HeadersNotDocumented" + payload: + schemaFormat: application/vnd.aai.asyncapi+json;version=3.0.0 + schema: + $ref: "#/components/schemas/io.github.springwolf.examples.kafka.dtos.YamlPayloadDto" + contentType: application/yaml + name: io.github.springwolf.examples.kafka.dtos.YamlPayloadDto + title: YamlPayloadDto + description: Showcases a yaml based message + bindings: + kafka: + bindingVersion: 0.5.0 + io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase: + headers: + $ref: "#/components/schemas/SpringKafkaDefaultHeaders-VehicleBase" + payload: + schemaFormat: application/vnd.aai.asyncapi+json;version=3.0.0 + schema: + $ref: "#/components/schemas/io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase" + name: io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase + title: VehicleBase + bindings: + kafka: + bindingVersion: 0.5.0 + java.lang.Number: + headers: + $ref: "#/components/schemas/SpringKafkaDefaultHeaders-Integer" + payload: + schemaFormat: application/vnd.aai.asyncapi+json;version=3.0.0 + schema: + $ref: "#/components/schemas/java.lang.Number" + name: java.lang.Number + title: Integer + bindings: + kafka: + bindingVersion: 0.5.0 + java.lang.String: + headers: + $ref: "#/components/schemas/SpringKafkaDefaultHeaders-String" + payload: + schemaFormat: application/vnd.aai.asyncapi+json;version=3.0.0 + schema: + $ref: "#/components/schemas/java.lang.String" + name: java.lang.String + title: String + bindings: + kafka: + bindingVersion: 0.5.0 + javax.money.MonetaryAmount: + headers: + $ref: "#/components/schemas/SpringKafkaDefaultHeaders-MonetaryAmount" + payload: + schemaFormat: application/vnd.aai.asyncapi+json;version=3.0.0 + schema: + $ref: "#/components/schemas/javax.money.MonetaryAmount" + name: javax.money.MonetaryAmount + title: MonetaryAmount + bindings: + kafka: + key: + type: string + description: Kafka Consumer Message Key + examples: + - example-key + bindingVersion: 0.5.0 +operations: + another-topic_receive_receiveAnotherPayloadBatched: + action: receive + channel: + $ref: "#/channels/another-topic" + bindings: + kafka: + groupId: + type: string + enum: + - example-group-id + bindingVersion: 0.5.0 + messages: + - $ref: "#/channels/another-topic/messages/io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto" + avro-topic_receive_receiveExampleAvroPayload: + action: receive + channel: + $ref: "#/channels/avro-topic" + title: avro-topic_receive + description: Requires a running kafka-schema-registry. See docker-compose.yml + to start it + bindings: + kafka: + bindingVersion: 0.5.0 + messages: + - $ref: "#/channels/avro-topic/messages/io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto" + example-topic_receive_receiveExamplePayload: + action: receive + channel: + $ref: "#/channels/example-topic" + bindings: + kafka: + bindingVersion: 0.5.0 + messages: + - $ref: "#/channels/example-topic/messages/io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto" + integer-topic_receive_receiveIntegerPayload: + action: receive + channel: + $ref: "#/channels/integer-topic" + bindings: + kafka: + bindingVersion: 0.5.0 + messages: + - $ref: "#/channels/integer-topic/messages/java.lang.Number" + multi-payload-topic_receive_ExampleClassLevelKafkaListener: + action: receive + channel: + $ref: "#/channels/multi-payload-topic" + bindings: + kafka: + bindingVersion: 0.5.0 + messages: + - $ref: "#/channels/multi-payload-topic/messages/io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto" + - $ref: "#/channels/multi-payload-topic/messages/io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto" + - $ref: "#/channels/multi-payload-topic/messages/javax.money.MonetaryAmount" + multi-payload-topic_receive_receiveMonetaryAmount: + action: receive + channel: + $ref: "#/channels/multi-payload-topic" + title: multi-payload-topic_receive + description: Override description in the AsyncListener annotation with servers + at kafka:29092 + bindings: + kafka: + groupId: + type: string + enum: + - foo-groupId + clientId: + type: string + enum: + - foo-clientId + bindingVersion: 0.5.0 + messages: + - $ref: "#/channels/multi-payload-topic/messages/javax.money.MonetaryAmount" + no-payload-used-topic_receive_receiveExamplePayload: + action: receive + channel: + $ref: "#/channels/no-payload-used-topic" + bindings: + kafka: + bindingVersion: 0.5.0 + messages: + - $ref: "#/channels/no-payload-used-topic/messages/PayloadNotUsed" + protobuf-topic_receive_receiveExampleProtobufPayload: + action: receive + channel: + $ref: "#/channels/protobuf-topic" + bindings: + kafka: + bindingVersion: 0.5.0 + messages: + - $ref: "#/channels/protobuf-topic/messages/io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto$Message" + string-topic_receive_receiveStringPayload: + action: receive + channel: + $ref: "#/channels/string-topic" + title: string-topic_receive + description: Final classes (like String) can be documented using an envelope class + and the @AsyncApiPayload annotation. + bindings: + kafka: + bindingVersion: 0.5.0 + messages: + - $ref: "#/channels/string-topic/messages/io.github.springwolf.examples.kafka.consumers.StringConsumer$StringEnvelope" + - $ref: "#/channels/string-topic/messages/java.lang.String" + topic-defined-via-asyncPublisher-annotation_send_sendMessage: + action: send + channel: + $ref: "#/channels/topic-defined-via-asyncPublisher-annotation" + title: topic-defined-via-asyncPublisher-annotation_send + description: "Custom, optional description defined in the AsyncPublisher annotation" + bindings: + kafka: + clientId: + type: string + enum: + - foo-clientId + bindingVersion: 0.5.0 + messages: + - $ref: "#/channels/topic-defined-via-asyncPublisher-annotation/messages/io.github.springwolf.examples.kafka.dtos.NestedPayloadDto" + vehicle-topic_receive_receiveExamplePayload: + action: receive + channel: + $ref: "#/channels/vehicle-topic" + bindings: + kafka: + bindingVersion: 0.5.0 + messages: + - $ref: "#/channels/vehicle-topic/messages/io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase" + xml-topic_receive_receiveExamplePayload: + action: receive + channel: + $ref: "#/channels/xml-topic" + title: xml-topic_receive + description: Auto-generated description + bindings: + kafka: + bindingVersion: 0.5.0 + messages: + - $ref: "#/channels/xml-topic/messages/io.github.springwolf.examples.kafka.dtos.XmlPayloadDto" + yaml-topic_receive_receiveExamplePayload: + action: receive + channel: + $ref: "#/channels/yaml-topic" + title: yaml-topic_receive + description: Auto-generated description + bindings: + kafka: + bindingVersion: 0.5.0 + messages: + - $ref: "#/channels/yaml-topic/messages/io.github.springwolf.examples.kafka.dtos.YamlPayloadDto"