diff --git a/springwolf-add-ons/springwolf-json-schema/src/main/java/io/github/springwolf/addons/json_schema/JsonSchemaGenerator.java b/springwolf-add-ons/springwolf-json-schema/src/main/java/io/github/springwolf/addons/json_schema/JsonSchemaGenerator.java index ff4b42cb6..a16a89437 100644 --- a/springwolf-add-ons/springwolf-json-schema/src/main/java/io/github/springwolf/addons/json_schema/JsonSchemaGenerator.java +++ b/springwolf-add-ons/springwolf-json-schema/src/main/java/io/github/springwolf/addons/json_schema/JsonSchemaGenerator.java @@ -65,7 +65,7 @@ private ObjectNode mapToJsonSchema( node.set("allOf", arrayNode); } if (schema.getConstValue() != null) { - node.put("const", schema.getConstValue().toString()); + node.set("const", jsonMapper.valueToTree(schema.getConstValue())); } if (schema.getDescription() != null) { node.put("description", schema.getDescription()); diff --git a/springwolf-add-ons/springwolf-json-schema/src/test/java/io/github/springwolf/addons/json_schema/JsonSchemaGeneratorTest.java b/springwolf-add-ons/springwolf-json-schema/src/test/java/io/github/springwolf/addons/json_schema/JsonSchemaGeneratorTest.java index 4fbf0de72..fba37f0c8 100644 --- a/springwolf-add-ons/springwolf-json-schema/src/test/java/io/github/springwolf/addons/json_schema/JsonSchemaGeneratorTest.java +++ b/springwolf-add-ons/springwolf-json-schema/src/test/java/io/github/springwolf/addons/json_schema/JsonSchemaGeneratorTest.java @@ -132,6 +132,21 @@ public static Stream validateJsonSchemaTest() { schema.setConst("test"); return schema; }), + Arguments.of( + "{\"const\": 42,\"type\":\"integer\",\"$schema\":\"https://json-schema.org/draft-07/schema#\"}", + (Supplier>) () -> { + Schema schema = new Schema<>(); + schema.setType("integer"); + schema.setConst(42); + return schema; + }), + Arguments.of( + "{\"const\": true,\"type\":\"boolean\",\"$schema\":\"https://json-schema.org/draft-07/schema#\"}", + (Supplier>) () -> { + BooleanSchema schema = new BooleanSchema(); + schema.setConst(true); + return schema; + }), Arguments.of( "{\"description\": \"test\",\"type\":\"string\",\"$schema\":\"https://json-schema.org/draft-07/schema#\"}", (Supplier>) () -> { diff --git a/springwolf-asyncapi/src/main/java/io/github/springwolf/asyncapi/v3/model/schema/SchemaObject.java b/springwolf-asyncapi/src/main/java/io/github/springwolf/asyncapi/v3/model/schema/SchemaObject.java index d202cf459..69e2724c8 100644 --- a/springwolf-asyncapi/src/main/java/io/github/springwolf/asyncapi/v3/model/schema/SchemaObject.java +++ b/springwolf-asyncapi/src/main/java/io/github/springwolf/asyncapi/v3/model/schema/SchemaObject.java @@ -98,6 +98,9 @@ public class SchemaObject extends ExtendableObject implements Schema { @JsonProperty(value = "maxLength") private Integer maxLength; + /** + * For a single entry, use {@link #constValue} + */ @JsonProperty("enum") private List enumValues; @@ -125,6 +128,9 @@ public class SchemaObject extends ExtendableObject implements Schema { @JsonProperty(value = "anyOf") private List anyOf; + /** + * For multiple entries, use {@link #enumValues} + */ @JsonProperty(value = "const") private Object constValue; diff --git a/springwolf-asyncapi/src/test/java/io/github/springwolf/asyncapi/v3/jackson/DefaultAsyncApiSerializerServiceIntegrationTest.java b/springwolf-asyncapi/src/test/java/io/github/springwolf/asyncapi/v3/jackson/DefaultAsyncApiSerializerServiceIntegrationTest.java index 28ba7873f..53cbaffc6 100644 --- a/springwolf-asyncapi/src/test/java/io/github/springwolf/asyncapi/v3/jackson/DefaultAsyncApiSerializerServiceIntegrationTest.java +++ b/springwolf-asyncapi/src/test/java/io/github/springwolf/asyncapi/v3/jackson/DefaultAsyncApiSerializerServiceIntegrationTest.java @@ -88,7 +88,7 @@ private AsyncAPI getAsyncAPITestObject(SchemaFormat schemaFormat) { Map messages = Map.of(message.getMessageId(), message); SchemaObject groupId = new SchemaObject(); - groupId.setEnumValues(List.of("myGroupId")); + groupId.setConstValue("myGroupId"); groupId.setType(Set.of(SchemaType.STRING.getValue())); OperationBinding operationBinding = @@ -102,11 +102,9 @@ private AsyncAPI getAsyncAPITestObject(SchemaFormat schemaFormat) { .build(); ChannelObject newUserChannel = ChannelObject.builder() - // FIXME: Can we autogenerate the address somehow? .address("new-user") .description("This channel is used to exchange messages about users signing up") - .servers(List.of( - ServerReference.builder().ref("#/servers/production").build())) + .servers(List.of(ServerReference.fromServer("production"))) .messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message))) .build(); diff --git a/springwolf-asyncapi/src/test/resources/v3/asyncapi/asyncapi-openapischema.json b/springwolf-asyncapi/src/test/resources/v3/asyncapi/asyncapi-openapischema.json index 926150e3b..ae95a9ae1 100644 --- a/springwolf-asyncapi/src/test/resources/v3/asyncapi/asyncapi-openapischema.json +++ b/springwolf-asyncapi/src/test/resources/v3/asyncapi/asyncapi-openapischema.json @@ -85,9 +85,7 @@ "kafka": { "groupId": { "type": "string", - "enum": [ - "myGroupId" - ] + "const": "myGroupId" }, "bindingVersion": "0.5.0" } diff --git a/springwolf-asyncapi/src/test/resources/v3/asyncapi/asyncapi-openapischema.yaml b/springwolf-asyncapi/src/test/resources/v3/asyncapi/asyncapi-openapischema.yaml index 9e4977e5b..e90173ebb 100644 --- a/springwolf-asyncapi/src/test/resources/v3/asyncapi/asyncapi-openapischema.yaml +++ b/springwolf-asyncapi/src/test/resources/v3/asyncapi/asyncapi-openapischema.yaml @@ -58,8 +58,7 @@ operations: kafka: groupId: type: string - enum: - - myGroupId + const: myGroupId bindingVersion: 0.5.0 messages: - "$ref": "#/channels/new-user/messages/io.github.springwolf.core.ExamplePayload" diff --git a/springwolf-asyncapi/src/test/resources/v3/asyncapi/asyncapi.json b/springwolf-asyncapi/src/test/resources/v3/asyncapi/asyncapi.json index 39cf166f7..e5ec28df0 100644 --- a/springwolf-asyncapi/src/test/resources/v3/asyncapi/asyncapi.json +++ b/springwolf-asyncapi/src/test/resources/v3/asyncapi/asyncapi.json @@ -82,9 +82,7 @@ "kafka": { "groupId": { "type": "string", - "enum": [ - "myGroupId" - ] + "const": "myGroupId" }, "bindingVersion": "0.5.0" } diff --git a/springwolf-asyncapi/src/test/resources/v3/asyncapi/asyncapi.yaml b/springwolf-asyncapi/src/test/resources/v3/asyncapi/asyncapi.yaml index 2dd219ecb..07e2180ae 100644 --- a/springwolf-asyncapi/src/test/resources/v3/asyncapi/asyncapi.yaml +++ b/springwolf-asyncapi/src/test/resources/v3/asyncapi/asyncapi.yaml @@ -56,8 +56,7 @@ operations: kafka: groupId: type: string - enum: - - myGroupId + const: myGroupId bindingVersion: 0.5.0 messages: - "$ref": "#/channels/new-user/messages/io.github.springwolf.core.ExamplePayload" diff --git a/springwolf-bindings/springwolf-kafka-binding/src/main/java/io/github/springwolf/bindings/kafka/scanners/operations/KafkaOperationBindingProcessor.java b/springwolf-bindings/springwolf-kafka-binding/src/main/java/io/github/springwolf/bindings/kafka/scanners/operations/KafkaOperationBindingProcessor.java index b9aec243d..6b5e9d488 100644 --- a/springwolf-bindings/springwolf-kafka-binding/src/main/java/io/github/springwolf/bindings/kafka/scanners/operations/KafkaOperationBindingProcessor.java +++ b/springwolf-bindings/springwolf-kafka-binding/src/main/java/io/github/springwolf/bindings/kafka/scanners/operations/KafkaOperationBindingProcessor.java @@ -11,7 +11,6 @@ import org.springframework.util.StringUtils; import org.springframework.util.StringValueResolver; -import java.util.List; import java.util.Set; public class KafkaOperationBindingProcessor extends AbstractOperationBindingProcessor { @@ -42,7 +41,7 @@ protected ProcessedOperationBinding mapToOperationBinding(KafkaAsyncOperationBin private static SchemaObject createStringSchema(String value) { if (value != null && !value.isEmpty()) { SchemaObject schema = new SchemaObject(); - schema.setEnumValues(List.of(value)); + schema.setConstValue(value); schema.setType(Set.of(SchemaType.STRING.getValue())); return schema; } diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalker.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalker.java index 6d2bf0108..a5c41e33d 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalker.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalker.java @@ -166,8 +166,10 @@ private Optional buildExampleFromUnvisitedSchema( return composedSchemaExample; } - // schema may be an openapi v3 or v3.1 schema. While v3 uses an simple 'type' field, v3.1 supports a set of - // types, for example ["string", "null"]. + Optional constOrEnumExample = buildFromConstOrEnum(schema); + if (constOrEnumExample.isPresent()) { + return constOrEnumExample; + } String type = getTypeForExampleValue(schema); if (type == null) { @@ -200,11 +202,6 @@ private Optional buildArrayExample(Schema schema, Map definit } private Optional buildFromStringSchema(Schema schema) { - String firstEnumValue = getFirstEnumValue(schema); - if (firstEnumValue != null) { - return exampleValueGenerator.createEnumExample(firstEnumValue, schema); - } - String format = schema.getFormat(); if (format == null) { return exampleValueGenerator.createStringExample(DEFAULT_STRING_EXAMPLE, schema); @@ -222,6 +219,20 @@ private Optional buildFromStringSchema(Schema schema) { }; } + private Optional buildFromConstOrEnum(Schema schema) { + Object constValue = schema.getConst(); + if (constValue != null) { + return exampleValueGenerator.createStringExample(constValue.toString(), schema); + } + + String firstEnumValue = getFirstEnumValue(schema); + if (firstEnumValue != null) { + return exampleValueGenerator.createEnumExample(firstEnumValue, schema); + } + + return Optional.empty(); + } + private String getFirstEnumValue(Schema schema) { List enums = schema.getEnum(); if (enums != null) { diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/common/annotation/AsyncAnnotationUtil.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/common/annotation/AsyncAnnotationUtil.java index 4c09eb8f0..d4e58069d 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/common/annotation/AsyncAnnotationUtil.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/common/annotation/AsyncAnnotationUtil.java @@ -74,7 +74,11 @@ public static SchemaObject getAsyncHeaders(AsyncOperation op, StringValueResolve List values = getHeaderValues(headersValues, stringValueResolver); if (!values.isEmpty()) { property.setExamples(new ArrayList<>(values)); - property.setEnumValues(values); + if (values.size() == 1) { + property.setConstValue(values.get(0)); + } else { + property.setEnumValues(values); + } } headerSchema.getProperties().put(propertyName, property); }); diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/schemas/SwaggerSchemaMapper.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/schemas/SwaggerSchemaMapper.java index f10285c76..b05c16418 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/schemas/SwaggerSchemaMapper.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/schemas/SwaggerSchemaMapper.java @@ -140,7 +140,11 @@ private SchemaObject mapSwaggerSchemaToAsyncApiSchema(Schema swaggerSchema) { if (isNullable) { enumStringValues.add(null); } - builder.enumValues(enumStringValues); + if (enumStringValues.size() == 1) { + builder.constValue(anEnum.get(0)); + } else { + builder.enumValues(enumStringValues); + } } Object example = swaggerSchema.getExample(); @@ -181,7 +185,9 @@ private SchemaObject mapSwaggerSchemaToAsyncApiSchema(Schema swaggerSchema) { builder.anyOf(anyOf.stream().map(this::mapSchemaOrRef).collect(Collectors.toList())); } - builder.constValue(swaggerSchema.getConst()); + if (swaggerSchema.getConst() != null) { + builder.constValue(swaggerSchema.getConst()); + } Schema not = swaggerSchema.getNot(); if (not != null) { @@ -297,6 +303,7 @@ private Schema mapSchemaObjectToSwagger(SchemaObject asyncApiSchema) { swaggerSchema.setDescription(asyncApiSchema.getDescription()); swaggerSchema.setExamples(asyncApiSchema.getExamples()); swaggerSchema.setEnum(asyncApiSchema.getEnumValues()); + swaggerSchema.setConst(asyncApiSchema.getConstValue()); if (asyncApiSchema.getProperties() != null) { Map properties = asyncApiSchema.getProperties().entrySet().stream() diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/SwaggerSchemaMapperTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/SwaggerSchemaMapperTest.java index 1822cb32b..bdb1256fd 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/SwaggerSchemaMapperTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/SwaggerSchemaMapperTest.java @@ -434,6 +434,20 @@ void mapEnum() { assertThat(componentSchema.getSchema().getEnumValues()).isEqualTo(schema.getEnum()); } + @Test + void mapSingleEnumValueAsConst() { + // given + ObjectSchema schema = new ObjectSchema(); + schema.setEnum(List.of("only")); + + // when + ComponentSchema componentSchema = swaggerSchemaMapper.mapSchema(schema); + + // then + assertThat(componentSchema.getSchema().getEnumValues()).isNull(); + assertThat(componentSchema.getSchema().getConstValue()).isEqualTo("only"); + } + @Test void mapExample() { // given @@ -723,6 +737,19 @@ void mapEnum() { assertThat(swaggerSchema.getEnum()).isEqualTo(schema.getEnumValues()); } + @Test + void mapConst() { + // given + SchemaObject schema = new SchemaObject(); + schema.setConstValue(42); + + // when + Schema swaggerSchema = swaggerSchemaMapper.mapToSwagger(schema); + + // then + assertThat(swaggerSchema.getConst()).isEqualTo(42); + } + @Test void mapNullableEnum() { // given diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalkerTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalkerTest.java index fc7b9c215..3e2f3f6cb 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalkerTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalkerTest.java @@ -4,6 +4,8 @@ import io.swagger.v3.oas.models.media.Schema; import org.junit.jupiter.api.Test; +import java.util.List; +import java.util.Map; import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; @@ -24,4 +26,19 @@ void getTypeForExampleValue() { assertThat(schemaWalker.getTypeForExampleValue(schema3)).isEqualTo("string"); assertThat(schemaWalker.getTypeForExampleValue(schema4)).isEqualTo("integer"); } + + @Test + void getDefaultValue() { + DefaultSchemaWalker schemaWalker = new DefaultSchemaWalker<>(new DummyExampleValueGenerator()); + + Schema schema1 = new Schema().type("string"); + Schema schema2 = new Schema().type("string"); + schema2.setConst("constValue"); + Schema schema3 = new Schema().type("string"); + schema3.setEnum(List.of("example1", "example2")); + + assertThat(schemaWalker.fromSchema(schema1, Map.of())).isEqualTo("string"); + assertThat(schemaWalker.fromSchema(schema2, Map.of())).isEqualTo("constValue"); + assertThat(schemaWalker.fromSchema(schema3, Map.of())).isEqualTo("example1"); + } } diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DummyExampleValueGenerator.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DummyExampleValueGenerator.java new file mode 100644 index 000000000..82d5c80e0 --- /dev/null +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DummyExampleValueGenerator.java @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: Apache-2.0 +package io.github.springwolf.core.asyncapi.components.examples.walkers; + +import io.swagger.v3.oas.models.media.Schema; + +import java.util.List; +import java.util.Optional; + +class DummyExampleValueGenerator implements ExampleValueGenerator { + + @Override + public boolean canHandle(String contentType) { + return true; + } + + @Override + public Optional lookupSchemaName(Schema schema) { + return Optional.empty(); + } + + @Override + public Object prepareForSerialization(Schema name, Object exampleObject) { + return exampleObject; + } + + @Override + public Optional createIntegerExample(Integer value, Schema schema) { + return Optional.of("integerExample"); + } + + @Override + public Optional createDoubleExample(Double value, Schema schema) { + return Optional.of("doubleExample"); + } + + @Override + public Optional createBooleanExample(Boolean value, Schema schema) { + return Optional.of("booleanExample"); + } + + @Override + public Optional createEmptyObjectExample() { + return Optional.of("emptyObjectExample"); + } + + @Override + public Optional createStringExample(String value, Schema schema) { + return Optional.of(value); + } + + @Override + public Optional createEnumExample(String anEnumValue, Schema schema) { + return Optional.of(anEnumValue); + } + + @Override + public Optional createUnknownSchemaStringTypeExample(String schemaType) { + return Optional.empty(); + } + + @Override + public Optional createUnknownSchemaStringFormatExample(String schemaFormat) { + return Optional.empty(); + } + + @Override + public Object createRaw(Object exampleValueString) { + return exampleValueString; + } + + @Override + public Object getExampleOrNull(Optional fieldName, Schema schema, Object example) { + return schema.getExample(); + } + + @Override + public Object createArrayExample(Optional name, Object arrayItem) { + return null; + } + + @Override + public void addPropertyExamples(Object object, List properties) {} + + @Override + public Object startObject(Optional name) { + return null; + } +} 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 fa8899f98..3eec77826 100644 --- a/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.json +++ b/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.json @@ -271,90 +271,74 @@ "title": "__TypeId__", "type": "string", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.NestedPayloadDto" - ], "examples": [ "io.github.springwolf.examples.kafka.dtos.NestedPayloadDto" - ] + ], + "const": "io.github.springwolf.examples.kafka.dtos.NestedPayloadDto" }, "ce_id": { "title": "ce_id", "type": "string", "description": "CloudEvent Id Header", - "enum": [ - "2c60089e-6f39-459d-8ced-2d6df7e4c03a" - ], "examples": [ "2c60089e-6f39-459d-8ced-2d6df7e4c03a" - ] + ], + "const": "2c60089e-6f39-459d-8ced-2d6df7e4c03a" }, "ce_source": { "title": "ce_source", "type": "string", "description": "CloudEvent Source Header", - "enum": [ - "http://localhost" - ], "examples": [ "http://localhost" - ] + ], + "const": "http://localhost" }, "ce_specversion": { "title": "ce_specversion", "type": "string", "description": "CloudEvent Spec Version Header", - "enum": [ - "1.0" - ], "examples": [ "1.0" - ] + ], + "const": "1.0" }, "ce_subject": { "title": "ce_subject", "type": "string", "description": "CloudEvent Subject Header", - "enum": [ - "Springwolf example project - Kafka" - ], "examples": [ "Springwolf example project - Kafka" - ] + ], + "const": "Springwolf example project - Kafka" }, "ce_time": { "title": "ce_time", "type": "string", "description": "CloudEvent Time Header", "format": "date-time", - "enum": [ - "2023-10-28T20:01:23+00:00" - ], "examples": [ "2023-10-28T20:01:23+00:00" - ] + ], + "const": "2023-10-28T20:01:23+00:00" }, "ce_type": { "title": "ce_type", "type": "string", "description": "CloudEvent Payload Type Header", - "enum": [ - "NestedPayloadDto.v1" - ], "examples": [ "NestedPayloadDto.v1" - ] + ], + "const": "NestedPayloadDto.v1" }, "content-type": { "title": "content-type", "type": "string", "description": "CloudEvent Content-Type Header", - "enum": [ - "application/json" - ], "examples": [ "application/json" - ] + ], + "const": "application/json" } }, "description": "Spring __TypeId__ and CloudEvent Headers", @@ -375,67 +359,51 @@ "description": "Spring __TypeId__ and CloudEvent Headers", "properties": { "__TypeId__": { + "const": "io.github.springwolf.examples.kafka.dtos.NestedPayloadDto", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.NestedPayloadDto" - ], "title": "__TypeId__", "type": "string" }, "ce_id": { + "const": "2c60089e-6f39-459d-8ced-2d6df7e4c03a", "description": "CloudEvent Id Header", - "enum": [ - "2c60089e-6f39-459d-8ced-2d6df7e4c03a" - ], "title": "ce_id", "type": "string" }, "ce_source": { + "const": "http://localhost", "description": "CloudEvent Source Header", - "enum": [ - "http://localhost" - ], "title": "ce_source", "type": "string" }, "ce_specversion": { + "const": "1.0", "description": "CloudEvent Spec Version Header", - "enum": [ - "1.0" - ], "title": "ce_specversion", "type": "string" }, "ce_subject": { + "const": "Springwolf example project - Kafka", "description": "CloudEvent Subject Header", - "enum": [ - "Springwolf example project - Kafka" - ], "title": "ce_subject", "type": "string" }, "ce_time": { + "const": "2023-10-28T20:01:23+00:00", "description": "CloudEvent Time Header", - "enum": [ - "2023-10-28T20:01:23+00:00" - ], "format": "date-time", "title": "ce_time", "type": "string" }, "ce_type": { + "const": "NestedPayloadDto.v1", "description": "CloudEvent Payload Type Header", - "enum": [ - "NestedPayloadDto.v1" - ], "title": "ce_type", "type": "string" }, "content-type": { + "const": "application/json", "description": "CloudEvent Content-Type Header", - "enum": [ - "application/json" - ], "title": "content-type", "type": "string" } @@ -452,12 +420,10 @@ "title": "__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" - ] + ], + "const": "io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto" } }, "examples": [ @@ -469,10 +435,8 @@ "$schema": "https://json-schema.org/draft-07/schema#", "properties": { "__TypeId__": { + "const": "io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto" - ], "title": "__TypeId__", "type": "string" } @@ -489,12 +453,10 @@ "title": "__TypeId__", "type": "string", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto" - ], "examples": [ "io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto" - ] + ], + "const": "io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto" } }, "examples": [ @@ -506,10 +468,8 @@ "$schema": "https://json-schema.org/draft-07/schema#", "properties": { "__TypeId__": { + "const": "io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto" - ], "title": "__TypeId__", "type": "string" } @@ -571,20 +531,18 @@ "type": "object" } }, - "SpringKafkaDefaultHeaders-ExamplePayloadDto-546532105": { - "title": "SpringKafkaDefaultHeaders-ExamplePayloadDto-546532105", + "SpringKafkaDefaultHeaders-ExamplePayloadDto-1408272656": { + "title": "SpringKafkaDefaultHeaders-ExamplePayloadDto-1408272656", "type": "object", "properties": { "__TypeId__": { "title": "__TypeId__", "type": "string", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto" - ], "examples": [ "io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto" - ] + ], + "const": "io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto" }, "kafka_offset": { "type": "integer", @@ -619,10 +577,8 @@ "$schema": "https://json-schema.org/draft-07/schema#", "properties": { "__TypeId__": { + "const": "io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto" - ], "title": "__TypeId__", "type": "string" }, @@ -638,7 +594,7 @@ "type": "object" } }, - "title": "SpringKafkaDefaultHeaders-ExamplePayloadDto-546532105", + "title": "SpringKafkaDefaultHeaders-ExamplePayloadDto-1408272656", "type": "object" } }, @@ -650,12 +606,10 @@ "title": "__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" - ] + ], + "const": "io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto.Message" } }, "examples": [ @@ -667,10 +621,8 @@ "$schema": "https://json-schema.org/draft-07/schema#", "properties": { "__TypeId__": { + "const": "io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto.Message", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto.Message" - ], "title": "__TypeId__", "type": "string" } @@ -687,12 +639,10 @@ "title": "__TypeId__", "type": "string", "description": "Spring Type Id Header", - "enum": [ - "javax.money.MonetaryAmount" - ], "examples": [ "javax.money.MonetaryAmount" - ] + ], + "const": "javax.money.MonetaryAmount" } }, "examples": [ @@ -704,10 +654,8 @@ "$schema": "https://json-schema.org/draft-07/schema#", "properties": { "__TypeId__": { + "const": "javax.money.MonetaryAmount", "description": "Spring Type Id Header", - "enum": [ - "javax.money.MonetaryAmount" - ], "title": "__TypeId__", "type": "string" } @@ -724,12 +672,10 @@ "title": "__TypeId__", "type": "string", "description": "Spring Type Id Header", - "enum": [ - "PayloadNotUsed" - ], "examples": [ "PayloadNotUsed" - ] + ], + "const": "PayloadNotUsed" } }, "examples": [ @@ -741,10 +687,8 @@ "$schema": "https://json-schema.org/draft-07/schema#", "properties": { "__TypeId__": { + "const": "PayloadNotUsed", "description": "Spring Type Id Header", - "enum": [ - "PayloadNotUsed" - ], "title": "__TypeId__", "type": "string" } @@ -761,12 +705,10 @@ "title": "__TypeId__", "type": "string", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.RequiredAndNullablePayloadDto" - ], "examples": [ "io.github.springwolf.examples.kafka.dtos.RequiredAndNullablePayloadDto" - ] + ], + "const": "io.github.springwolf.examples.kafka.dtos.RequiredAndNullablePayloadDto" } }, "examples": [ @@ -778,10 +720,8 @@ "$schema": "https://json-schema.org/draft-07/schema#", "properties": { "__TypeId__": { + "const": "io.github.springwolf.examples.kafka.dtos.RequiredAndNullablePayloadDto", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.RequiredAndNullablePayloadDto" - ], "title": "__TypeId__", "type": "string" } @@ -798,12 +738,10 @@ "title": "__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" - ] + ], + "const": "io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase" } }, "examples": [ @@ -815,10 +753,8 @@ "$schema": "https://json-schema.org/draft-07/schema#", "properties": { "__TypeId__": { + "const": "io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase" - ], "title": "__TypeId__", "type": "string" } @@ -835,12 +771,10 @@ "title": "__TypeId__", "type": "string", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.XmlPayloadDto" - ], "examples": [ "io.github.springwolf.examples.kafka.dtos.XmlPayloadDto" - ] + ], + "const": "io.github.springwolf.examples.kafka.dtos.XmlPayloadDto" } }, "examples": [ @@ -852,10 +786,8 @@ "$schema": "https://json-schema.org/draft-07/schema#", "properties": { "__TypeId__": { + "const": "io.github.springwolf.examples.kafka.dtos.XmlPayloadDto", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.XmlPayloadDto" - ], "title": "__TypeId__", "type": "string" } @@ -872,12 +804,10 @@ "title": "__TypeId__", "type": "string", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.YamlPayloadDto" - ], "examples": [ "io.github.springwolf.examples.kafka.dtos.YamlPayloadDto" - ] + ], + "const": "io.github.springwolf.examples.kafka.dtos.YamlPayloadDto" } }, "examples": [ @@ -889,10 +819,8 @@ "$schema": "https://json-schema.org/draft-07/schema#", "properties": { "__TypeId__": { + "const": "io.github.springwolf.examples.kafka.dtos.YamlPayloadDto", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.YamlPayloadDto" - ], "title": "__TypeId__", "type": "string" } @@ -909,12 +837,10 @@ "title": "__TypeId__", "type": "string", "description": "Spring Type Id Header", - "enum": [ - "java.lang.Integer" - ], "examples": [ "java.lang.Integer" - ] + ], + "const": "java.lang.Integer" } }, "examples": [ @@ -926,10 +852,8 @@ "$schema": "https://json-schema.org/draft-07/schema#", "properties": { "__TypeId__": { + "const": "java.lang.Integer", "description": "Spring Type Id Header", - "enum": [ - "java.lang.Integer" - ], "title": "__TypeId__", "type": "string" } @@ -946,12 +870,10 @@ "title": "__TypeId__", "type": "string", "description": "Spring Type Id Header", - "enum": [ - "java.lang.String" - ], "examples": [ "java.lang.String" - ] + ], + "const": "java.lang.String" } }, "examples": [ @@ -963,10 +885,8 @@ "$schema": "https://json-schema.org/draft-07/schema#", "properties": { "__TypeId__": { + "const": "java.lang.String", "description": "Spring Type Id Header", - "enum": [ - "java.lang.String" - ], "title": "__TypeId__", "type": "string" } @@ -2048,7 +1968,7 @@ }, "io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto": { "headers": { - "$ref": "#/components/schemas/SpringKafkaDefaultHeaders-ExamplePayloadDto-546532105" + "$ref": "#/components/schemas/SpringKafkaDefaultHeaders-ExamplePayloadDto-1408272656" }, "payload": { "schemaFormat": "application/vnd.aai.asyncapi+json;version=3.1.0", @@ -2245,9 +2165,7 @@ "kafka": { "groupId": { "type": "string", - "enum": [ - "example-group-id" - ] + "const": "example-group-id" }, "bindingVersion": "0.5.0" } @@ -2359,15 +2277,11 @@ "kafka": { "groupId": { "type": "string", - "enum": [ - "foo-groupId" - ] + "const": "foo-groupId" }, "clientId": { "type": "string", - "enum": [ - "foo-clientId" - ] + "const": "foo-clientId" }, "bindingVersion": "0.5.0" } @@ -2458,9 +2372,7 @@ "kafka": { "clientId": { "type": "string", - "enum": [ - "foo-clientId" - ] + "const": "foo-clientId" }, "bindingVersion": "0.5.0" } diff --git a/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.openapiv31.json b/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.openapiv31.json index 7611873fb..d95dce1f4 100644 --- a/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.openapiv31.json +++ b/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.openapiv31.json @@ -266,10 +266,8 @@ "properties": { "__TypeId__": { "type": "string", + "const": "io.github.springwolf.examples.kafka.dtos.NestedPayloadDto", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.NestedPayloadDto" - ], "examples": [ "io.github.springwolf.examples.kafka.dtos.NestedPayloadDto" ], @@ -277,10 +275,8 @@ }, "ce_id": { "type": "string", + "const": "2c60089e-6f39-459d-8ced-2d6df7e4c03a", "description": "CloudEvent Id Header", - "enum": [ - "2c60089e-6f39-459d-8ced-2d6df7e4c03a" - ], "examples": [ "2c60089e-6f39-459d-8ced-2d6df7e4c03a" ], @@ -288,10 +284,8 @@ }, "ce_source": { "type": "string", + "const": "http://localhost", "description": "CloudEvent Source Header", - "enum": [ - "http://localhost" - ], "examples": [ "http://localhost" ], @@ -299,10 +293,8 @@ }, "ce_specversion": { "type": "string", + "const": "1.0", "description": "CloudEvent Spec Version Header", - "enum": [ - "1.0" - ], "examples": [ "1.0" ], @@ -310,10 +302,8 @@ }, "ce_subject": { "type": "string", + "const": "Springwolf example project - Kafka", "description": "CloudEvent Subject Header", - "enum": [ - "Springwolf example project - Kafka" - ], "examples": [ "Springwolf example project - Kafka" ], @@ -322,10 +312,8 @@ "ce_time": { "type": "string", "format": "date-time", + "const": "2023-10-28T20:01:23+00:00", "description": "CloudEvent Time Header", - "enum": [ - "2023-10-28T20:01:23+00:00" - ], "examples": [ "2023-10-28T20:01:23+00:00" ], @@ -333,10 +321,8 @@ }, "ce_type": { "type": "string", + "const": "NestedPayloadDto.v1", "description": "CloudEvent Payload Type Header", - "enum": [ - "NestedPayloadDto.v1" - ], "examples": [ "NestedPayloadDto.v1" ], @@ -344,10 +330,8 @@ }, "content-type": { "type": "string", + "const": "application/json", "description": "CloudEvent Content-Type Header", - "enum": [ - "application/json" - ], "examples": [ "application/json" ], @@ -367,10 +351,8 @@ "properties": { "__TypeId__": { "type": "string", + "const": "io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto" - ], "examples": [ "io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto" ], @@ -390,10 +372,8 @@ "properties": { "__TypeId__": { "type": "string", + "const": "io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto" - ], "examples": [ "io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto" ], @@ -435,7 +415,7 @@ "title": "SpringKafkaDefaultHeaders-AnotherTopic" } }, - "SpringKafkaDefaultHeaders-ExamplePayloadDto-439176902": { + "SpringKafkaDefaultHeaders-ExamplePayloadDto-1900985633": { "schemaFormat": "application/vnd.oai.openapi;version=3.1.0", "schema": { "type": "object", @@ -447,10 +427,8 @@ "properties": { "__TypeId__": { "type": "string", + "const": "io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto" - ], "examples": [ "io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto" ], @@ -466,7 +444,7 @@ "example": "string" } }, - "title": "SpringKafkaDefaultHeaders-ExamplePayloadDto-439176902" + "title": "SpringKafkaDefaultHeaders-ExamplePayloadDto-1900985633" } }, "SpringKafkaDefaultHeaders-Message": { @@ -479,10 +457,8 @@ "properties": { "__TypeId__": { "type": "string", + "const": "io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto.Message", "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" ], @@ -502,10 +478,8 @@ "properties": { "__TypeId__": { "type": "string", + "const": "javax.money.MonetaryAmount", "description": "Spring Type Id Header", - "enum": [ - "javax.money.MonetaryAmount" - ], "examples": [ "javax.money.MonetaryAmount" ], @@ -525,10 +499,8 @@ "properties": { "__TypeId__": { "type": "string", + "const": "PayloadNotUsed", "description": "Spring Type Id Header", - "enum": [ - "PayloadNotUsed" - ], "examples": [ "PayloadNotUsed" ], @@ -548,10 +520,8 @@ "properties": { "__TypeId__": { "type": "string", + "const": "io.github.springwolf.examples.kafka.dtos.RequiredAndNullablePayloadDto", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.RequiredAndNullablePayloadDto" - ], "examples": [ "io.github.springwolf.examples.kafka.dtos.RequiredAndNullablePayloadDto" ], @@ -571,10 +541,8 @@ "properties": { "__TypeId__": { "type": "string", + "const": "io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase" - ], "examples": [ "io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase" ], @@ -594,10 +562,8 @@ "properties": { "__TypeId__": { "type": "string", + "const": "io.github.springwolf.examples.kafka.dtos.XmlPayloadDto", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.XmlPayloadDto" - ], "examples": [ "io.github.springwolf.examples.kafka.dtos.XmlPayloadDto" ], @@ -617,10 +583,8 @@ "properties": { "__TypeId__": { "type": "string", + "const": "io.github.springwolf.examples.kafka.dtos.YamlPayloadDto", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.YamlPayloadDto" - ], "examples": [ "io.github.springwolf.examples.kafka.dtos.YamlPayloadDto" ], @@ -640,10 +604,8 @@ "properties": { "__TypeId__": { "type": "string", + "const": "java.lang.Integer", "description": "Spring Type Id Header", - "enum": [ - "java.lang.Integer" - ], "examples": [ "java.lang.Integer" ], @@ -663,10 +625,8 @@ "properties": { "__TypeId__": { "type": "string", + "const": "java.lang.String", "description": "Spring Type Id Header", - "enum": [ - "java.lang.String" - ], "examples": [ "java.lang.String" ], @@ -1261,7 +1221,7 @@ }, "io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto": { "headers": { - "$ref": "#/components/schemas/SpringKafkaDefaultHeaders-ExamplePayloadDto-439176902" + "$ref": "#/components/schemas/SpringKafkaDefaultHeaders-ExamplePayloadDto-1900985633" }, "payload": { "schemaFormat": "application/vnd.aai.asyncapi+json;version=3.1.0", @@ -1460,9 +1420,7 @@ "kafka": { "groupId": { "type": "string", - "enum": [ - "example-group-id" - ] + "const": "example-group-id" }, "bindingVersion": "0.5.0" } @@ -1574,15 +1532,11 @@ "kafka": { "groupId": { "type": "string", - "enum": [ - "foo-groupId" - ] + "const": "foo-groupId" }, "clientId": { "type": "string", - "enum": [ - "foo-clientId" - ] + "const": "foo-clientId" }, "bindingVersion": "0.5.0" } @@ -1673,9 +1627,7 @@ "kafka": { "clientId": { "type": "string", - "enum": [ - "foo-clientId" - ] + "const": "foo-clientId" }, "bindingVersion": "0.5.0" } diff --git a/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.yaml b/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.yaml index da4a1ec13..07ccdcb16 100644 --- a/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.yaml +++ b/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.yaml @@ -185,67 +185,59 @@ components: title: __TypeId__ type: string description: Spring Type Id Header - enum: - - io.github.springwolf.examples.kafka.dtos.NestedPayloadDto examples: - io.github.springwolf.examples.kafka.dtos.NestedPayloadDto + const: io.github.springwolf.examples.kafka.dtos.NestedPayloadDto ce_id: title: ce_id type: string description: CloudEvent Id Header - enum: - - 2c60089e-6f39-459d-8ced-2d6df7e4c03a examples: - 2c60089e-6f39-459d-8ced-2d6df7e4c03a + const: 2c60089e-6f39-459d-8ced-2d6df7e4c03a ce_source: title: ce_source type: string description: CloudEvent Source Header - enum: - - http://localhost examples: - http://localhost + const: http://localhost ce_specversion: title: ce_specversion type: string description: CloudEvent Spec Version Header - enum: - - "1.0" examples: - "1.0" + const: "1.0" ce_subject: title: ce_subject type: string description: CloudEvent Subject Header - enum: - - Springwolf example project - Kafka examples: - Springwolf example project - Kafka + const: Springwolf example project - Kafka ce_time: title: ce_time type: string description: CloudEvent Time Header format: date-time - enum: - - 2023-10-28T20:01:23+00:00 examples: - 2023-10-28T20:01:23+00:00 + const: 2023-10-28T20:01:23+00:00 ce_type: title: ce_type type: string description: CloudEvent Payload Type Header - enum: - - NestedPayloadDto.v1 examples: - NestedPayloadDto.v1 + const: NestedPayloadDto.v1 content-type: title: content-type type: string description: CloudEvent Content-Type Header - enum: - - application/json examples: - application/json + const: application/json description: Spring __TypeId__ and CloudEvent Headers examples: - __TypeId__: io.github.springwolf.examples.kafka.dtos.NestedPayloadDto @@ -261,52 +253,44 @@ components: description: Spring __TypeId__ and CloudEvent Headers properties: __TypeId__: + const: io.github.springwolf.examples.kafka.dtos.NestedPayloadDto description: Spring Type Id Header - enum: - - io.github.springwolf.examples.kafka.dtos.NestedPayloadDto title: __TypeId__ type: string ce_id: + const: 2c60089e-6f39-459d-8ced-2d6df7e4c03a description: CloudEvent Id Header - enum: - - 2c60089e-6f39-459d-8ced-2d6df7e4c03a title: ce_id type: string ce_source: + const: http://localhost description: CloudEvent Source Header - enum: - - http://localhost title: ce_source type: string ce_specversion: + const: "1.0" description: CloudEvent Spec Version Header - enum: - - "1.0" title: ce_specversion type: string ce_subject: + const: Springwolf example project - Kafka description: CloudEvent Subject Header - enum: - - Springwolf example project - Kafka title: ce_subject type: string ce_time: + const: 2023-10-28T20:01:23+00:00 description: CloudEvent Time Header - enum: - - 2023-10-28T20:01:23+00:00 format: date-time title: ce_time type: string ce_type: + const: NestedPayloadDto.v1 description: CloudEvent Payload Type Header - enum: - - NestedPayloadDto.v1 title: ce_type type: string content-type: + const: application/json description: CloudEvent Content-Type Header - enum: - - application/json title: content-type type: string title: SpringDefaultHeaderAndCloudEvent @@ -319,19 +303,17 @@ components: title: __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 + const: 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-07/schema# properties: __TypeId__: + const: io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto description: Spring Type Id Header - enum: - - io.github.springwolf.examples.kafka.dto.avro.AnotherPayloadAvroDto title: __TypeId__ type: string title: SpringKafkaDefaultHeaders-AnotherPayloadAvroDto @@ -344,19 +326,17 @@ components: title: __TypeId__ type: string description: Spring Type Id Header - enum: - - io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto examples: - io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto + const: 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-07/schema# properties: __TypeId__: + const: io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto description: Spring Type Id Header - enum: - - io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto title: __TypeId__ type: string title: SpringKafkaDefaultHeaders-AnotherPayloadDto @@ -400,18 +380,17 @@ components: type: string title: SpringKafkaDefaultHeaders-AnotherTopic type: object - SpringKafkaDefaultHeaders-ExamplePayloadDto-546532105: - title: SpringKafkaDefaultHeaders-ExamplePayloadDto-546532105 + SpringKafkaDefaultHeaders-ExamplePayloadDto-1408272656: + title: SpringKafkaDefaultHeaders-ExamplePayloadDto-1408272656 type: object properties: __TypeId__: title: __TypeId__ type: string description: Spring Type Id Header - enum: - - io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto examples: - io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto + const: io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto kafka_offset: type: integer format: int32 @@ -435,9 +414,8 @@ components: $schema: https://json-schema.org/draft-07/schema# properties: __TypeId__: + const: io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto description: Spring Type Id Header - enum: - - io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto title: __TypeId__ type: string kafka_offset: @@ -448,7 +426,7 @@ components: kafka_recordMetadata: title: ConsumerRecordMetadata type: object - title: SpringKafkaDefaultHeaders-ExamplePayloadDto-546532105 + title: SpringKafkaDefaultHeaders-ExamplePayloadDto-1408272656 type: object SpringKafkaDefaultHeaders-Message: title: SpringKafkaDefaultHeaders-Message @@ -458,19 +436,17 @@ components: title: __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 + const: 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-07/schema# properties: __TypeId__: + const: io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto.Message description: Spring Type Id Header - enum: - - io.github.springwolf.examples.kafka.dto.proto.ExamplePayloadProtobufDto.Message title: __TypeId__ type: string title: SpringKafkaDefaultHeaders-Message @@ -483,19 +459,17 @@ components: title: __TypeId__ type: string description: Spring Type Id Header - enum: - - javax.money.MonetaryAmount examples: - javax.money.MonetaryAmount + const: javax.money.MonetaryAmount examples: - __TypeId__: javax.money.MonetaryAmount x-json-schema: $schema: https://json-schema.org/draft-07/schema# properties: __TypeId__: + const: javax.money.MonetaryAmount description: Spring Type Id Header - enum: - - javax.money.MonetaryAmount title: __TypeId__ type: string title: SpringKafkaDefaultHeaders-MonetaryAmount @@ -508,19 +482,17 @@ components: title: __TypeId__ type: string description: Spring Type Id Header - enum: - - PayloadNotUsed examples: - PayloadNotUsed + const: PayloadNotUsed examples: - __TypeId__: PayloadNotUsed x-json-schema: $schema: https://json-schema.org/draft-07/schema# properties: __TypeId__: + const: PayloadNotUsed description: Spring Type Id Header - enum: - - PayloadNotUsed title: __TypeId__ type: string title: SpringKafkaDefaultHeaders-PayloadNotUsed @@ -533,19 +505,17 @@ components: title: __TypeId__ type: string description: Spring Type Id Header - enum: - - io.github.springwolf.examples.kafka.dtos.RequiredAndNullablePayloadDto examples: - io.github.springwolf.examples.kafka.dtos.RequiredAndNullablePayloadDto + const: io.github.springwolf.examples.kafka.dtos.RequiredAndNullablePayloadDto examples: - __TypeId__: io.github.springwolf.examples.kafka.dtos.RequiredAndNullablePayloadDto x-json-schema: $schema: https://json-schema.org/draft-07/schema# properties: __TypeId__: + const: io.github.springwolf.examples.kafka.dtos.RequiredAndNullablePayloadDto description: Spring Type Id Header - enum: - - io.github.springwolf.examples.kafka.dtos.RequiredAndNullablePayloadDto title: __TypeId__ type: string title: SpringKafkaDefaultHeaders-RequiredAndNullablePayloadDto @@ -558,19 +528,17 @@ components: title: __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 + const: 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-07/schema# properties: __TypeId__: + const: io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase description: Spring Type Id Header - enum: - - io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase title: __TypeId__ type: string title: SpringKafkaDefaultHeaders-VehicleBase @@ -583,19 +551,17 @@ components: title: __TypeId__ type: string description: Spring Type Id Header - enum: - - io.github.springwolf.examples.kafka.dtos.XmlPayloadDto examples: - io.github.springwolf.examples.kafka.dtos.XmlPayloadDto + const: 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-07/schema# properties: __TypeId__: + const: io.github.springwolf.examples.kafka.dtos.XmlPayloadDto description: Spring Type Id Header - enum: - - io.github.springwolf.examples.kafka.dtos.XmlPayloadDto title: __TypeId__ type: string title: SpringKafkaDefaultHeaders-XmlPayloadDto @@ -608,19 +574,17 @@ components: title: __TypeId__ type: string description: Spring Type Id Header - enum: - - io.github.springwolf.examples.kafka.dtos.YamlPayloadDto examples: - io.github.springwolf.examples.kafka.dtos.YamlPayloadDto + const: 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-07/schema# properties: __TypeId__: + const: io.github.springwolf.examples.kafka.dtos.YamlPayloadDto description: Spring Type Id Header - enum: - - io.github.springwolf.examples.kafka.dtos.YamlPayloadDto title: __TypeId__ type: string title: SpringKafkaDefaultHeaders-YamlPayloadDto @@ -633,19 +597,17 @@ components: title: __TypeId__ type: string description: Spring Type Id Header - enum: - - java.lang.Integer examples: - java.lang.Integer + const: java.lang.Integer examples: - __TypeId__: java.lang.Integer x-json-schema: $schema: https://json-schema.org/draft-07/schema# properties: __TypeId__: + const: java.lang.Integer description: Spring Type Id Header - enum: - - java.lang.Integer title: __TypeId__ type: string title: SpringKafkaDefaultHeaders-integer @@ -658,19 +620,17 @@ components: title: __TypeId__ type: string description: Spring Type Id Header - enum: - - java.lang.String examples: - java.lang.String + const: java.lang.String examples: - __TypeId__: java.lang.String x-json-schema: $schema: https://json-schema.org/draft-07/schema# properties: __TypeId__: + const: java.lang.String description: Spring Type Id Header - enum: - - java.lang.String title: __TypeId__ type: string title: SpringKafkaDefaultHeaders-string @@ -1491,7 +1451,7 @@ components: bindingVersion: 0.5.0 io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto: headers: - $ref: "#/components/schemas/SpringKafkaDefaultHeaders-ExamplePayloadDto-546532105" + $ref: "#/components/schemas/SpringKafkaDefaultHeaders-ExamplePayloadDto-1408272656" payload: schemaFormat: application/vnd.aai.asyncapi+json;version=3.1.0 schema: @@ -1625,8 +1585,7 @@ operations: kafka: groupId: type: string - enum: - - example-group-id + const: example-group-id bindingVersion: 0.5.0 messages: - $ref: "#/channels/another-topic/messages/io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto" @@ -1693,12 +1652,10 @@ operations: kafka: groupId: type: string - enum: - - foo-groupId + const: foo-groupId clientId: type: string - enum: - - foo-clientId + const: foo-clientId bindingVersion: 0.5.0 messages: - $ref: "#/channels/multi-payload-topic/messages/javax.money.MonetaryAmount" @@ -1752,8 +1709,7 @@ operations: kafka: clientId: type: string - enum: - - foo-clientId + const: foo-clientId bindingVersion: 0.5.0 messages: - $ref: "#/channels/topic-defined-via-asyncPublisher-annotation/messages/io.github.springwolf.examples.kafka.dtos.NestedPayloadDto" diff --git a/springwolf-examples/springwolf-kafka-example/src/test/resources/groups/vehicles.json b/springwolf-examples/springwolf-kafka-example/src/test/resources/groups/vehicles.json index beb65d8aa..a5774c97e 100644 --- a/springwolf-examples/springwolf-kafka-example/src/test/resources/groups/vehicles.json +++ b/springwolf-examples/springwolf-kafka-example/src/test/resources/groups/vehicles.json @@ -48,12 +48,10 @@ "title": "__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" - ] + ], + "const": "io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase" } }, "examples": [ @@ -65,10 +63,8 @@ "$schema": "https://json-schema.org/draft-07/schema#", "properties": { "__TypeId__": { + "const": "io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase", "description": "Spring Type Id Header", - "enum": [ - "io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase" - ], "title": "__TypeId__", "type": "string" } diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/springwolf/plugins/kafka/asyncapi/components/header/AsyncHeadersForSpringKafkaBuilder.java b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/springwolf/plugins/kafka/asyncapi/components/header/AsyncHeadersForSpringKafkaBuilder.java index ebeb6f54d..9d1981c1f 100644 --- a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/springwolf/plugins/kafka/asyncapi/components/header/AsyncHeadersForSpringKafkaBuilder.java +++ b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/springwolf/plugins/kafka/asyncapi/components/header/AsyncHeadersForSpringKafkaBuilder.java @@ -28,19 +28,26 @@ public AsyncHeadersForSpringKafkaBuilder withTypeIdHeader(String exampleTypeId) return withTypeIdHeader(exampleTypeId, List.of(exampleTypeId)); } - public AsyncHeadersForSpringKafkaBuilder withTypeIdHeader(String exampleTypeId, List types) { + public AsyncHeadersForSpringKafkaBuilder withTypeIdHeader(String exampleTypeId, List values) { return this.withHeader( - DefaultJacksonJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME, types, exampleTypeId, "Spring Type Id Header"); + DefaultJacksonJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME, + values, + exampleTypeId, + "Spring Type Id Header"); } private AsyncHeadersForSpringKafkaBuilder withHeader( - String headerName, List types, String exampleType, String description) { + String headerName, List values, String exampleType, String description) { SchemaObject header = new SchemaObject(); header.setType(Set.of(SchemaType.STRING.getValue())); header.setTitle(headerName); header.setDescription(description); header.setExamples(List.of(exampleType)); - header.setEnumValues(types); + if (values.size() == 1) { + header.setConstValue(values.get(0)); + } else { + header.setEnumValues(values); + } headers.getProperties().put(headerName, header); return this; diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/springwolf/plugins/kafka/asyncapi/scanners/common/KafkaListenerUtil.java b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/springwolf/plugins/kafka/asyncapi/scanners/common/KafkaListenerUtil.java index af2ca4727..228c9b8da 100644 --- a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/springwolf/plugins/kafka/asyncapi/scanners/common/KafkaListenerUtil.java +++ b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/springwolf/plugins/kafka/asyncapi/scanners/common/KafkaListenerUtil.java @@ -87,7 +87,7 @@ public static SchemaObject buildKafkaGroupIdSchema(String groupId) { private static SchemaObject createStringSchema(String value) { if (value != null && !value.isEmpty()) { SchemaObject schema = new SchemaObject(); - schema.setEnumValues(List.of(value)); + schema.setConstValue(value); schema.setType(Set.of(SchemaType.STRING.getValue())); return schema; } diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/springwolf/plugins/kafka/asyncapi/scanners/common/KafkaListenerUtilTest.java b/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/springwolf/plugins/kafka/asyncapi/scanners/common/KafkaListenerUtilTest.java index e9a698a98..b65a748f2 100644 --- a/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/springwolf/plugins/kafka/asyncapi/scanners/common/KafkaListenerUtilTest.java +++ b/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/springwolf/plugins/kafka/asyncapi/scanners/common/KafkaListenerUtilTest.java @@ -74,27 +74,40 @@ void buildChannelBinding() { assertThat(channelBinding.get("kafka")).isEqualTo(new KafkaChannelBinding()); } - @Test - void buildOperationBinding() { - // given - KafkaListener annotation = mock(KafkaListener.class); - when(annotation.groupId()).thenReturn("${group-id}"); + @Nested + class OperationBindingTest { + @Test + void buildOperationBinding() { + // given + KafkaListener annotation = mock(KafkaListener.class); + when(annotation.groupId()).thenReturn("${group-id}"); - StringValueResolver stringValueResolver = mock(StringValueResolver.class); - when(stringValueResolver.resolveStringValue("${group-id}")).thenReturn("group-id"); + StringValueResolver stringValueResolver = mock(StringValueResolver.class); + when(stringValueResolver.resolveStringValue("${group-id}")).thenReturn("group-id"); - // when - Map operationBinding = - KafkaListenerUtil.buildOperationBinding(annotation, stringValueResolver); + // when + Map operationBinding = + KafkaListenerUtil.buildOperationBinding(annotation, stringValueResolver); - // then - assertThat(operationBinding.size()).isEqualTo(1); - assertThat(operationBinding.keySet()).isEqualTo(Sets.newTreeSet("kafka")); + // then + assertThat(operationBinding.size()).isEqualTo(1); + assertThat(operationBinding.keySet()).isEqualTo(Sets.newTreeSet("kafka")); - KafkaOperationBinding expectedOperationBinding = KafkaOperationBinding.builder() - .groupId(KafkaListenerUtil.buildKafkaGroupIdSchema("group-id")) - .build(); - assertThat(operationBinding.get("kafka")).isEqualTo(expectedOperationBinding); + KafkaOperationBinding expectedOperationBinding = KafkaOperationBinding.builder() + .groupId(KafkaListenerUtil.buildKafkaGroupIdSchema("group-id")) + .build(); + assertThat(operationBinding.get("kafka")).isEqualTo(expectedOperationBinding); + } + + @Test + void buildKafkaGroupIdSchema() { + // when + SchemaObject groupIdSchema = KafkaListenerUtil.buildKafkaGroupIdSchema("group-id"); + + // then + assertThat(groupIdSchema.getType()).isEqualTo(Set.of(SchemaType.STRING.getValue())); + assertThat(groupIdSchema.getConstValue()).isEqualTo("group-id"); + } } @Nested