From 2fd4db57f41385d3cc3d819165cce4ae4e0e9e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20M=C3=BCller?= Date: Wed, 15 May 2024 18:58:39 +0200 Subject: [PATCH] WIP --- .../examples/walkers/DefaultSchemaWalker.java | 20 ++-- .../walkers/ExampleValueGenerator.java | 2 +- .../json/ExampleJsonValueGenerator.java | 4 +- .../walkers/xml/ExampleXmlValueGenerator.java | 18 ++-- .../yaml/ExampleYamlValueGenerator.java | 2 +- ...efaultSchemaWalkerJsonIntegrationTest.java | 93 ++++++++++++------- ...efaultSchemaWalkerYamlIntegrationTest.java | 91 ++++++++++++------ 7 files changed, 149 insertions(+), 81 deletions(-) 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 fab1e7c36..b7f4e5582 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 @@ -52,7 +52,7 @@ public boolean canHandle(String contentType) { public R fromSchema(Schema schema, Map definitions) { exampleValueGenerator.initialize(); - String schemaName = exampleValueGenerator.lookupSchemaName(schema); + String schemaName = exampleValueGenerator.lookupSchemaName(schema).get(); try { T generatedExample = buildExample(schemaName, schema, definitions, new HashSet<>()) .orElseThrow(() -> new ExampleGeneratingException("Something went wrong")); @@ -154,13 +154,14 @@ private Optional getExampleValueFromSchemaAnnotation(Schema schema) { private Optional buildArrayExample(Schema schema, Map definitions, Set visited) { Schema arrayItemSchema = resolveSchemaFromRef(schema.getItems(), definitions).orElse(schema.getItems()); - String arrayItemName = exampleValueGenerator.lookupSchemaName(arrayItemSchema); - Optional arrayItem = buildExample(arrayItemName, arrayItemSchema, definitions, visited); + Optional arrayName = exampleValueGenerator.lookupSchemaName(schema); - String arrayName = exampleValueGenerator.lookupSchemaName(schema); - - return arrayItem.map(array -> exampleValueGenerator.createArrayExample(arrayName, array)); + return exampleValueGenerator + .lookupSchemaName(arrayItemSchema) + .or(() -> arrayName) + .flatMap(arrayItemName -> buildExample(arrayItemName, arrayItemSchema, definitions, visited)) + .map(arrayItem -> exampleValueGenerator.createArrayExample(arrayName.get(), arrayItem)); } private Optional buildFromStringSchema(Schema schema) { @@ -248,7 +249,12 @@ private List> buildPropertyExampleListFromSchema( Map properties, Map definitions, Set visited) { return properties.entrySet().stream() .map(propertySchema -> { - String propertyKey = exampleValueGenerator.lookupSchemaName(propertySchema.getValue()); + // There can be instances where the schema has no name and only the property is named + // in this case we se the key as schema name + String propertyKey = exampleValueGenerator + .lookupSchemaName(propertySchema.getValue()) + .orElse(propertySchema.getKey()); + Optional propertyValue = buildExample(propertyKey, propertySchema.getValue(), definitions, visited); diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/ExampleValueGenerator.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/ExampleValueGenerator.java index 138035e10..370c8335b 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/ExampleValueGenerator.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/ExampleValueGenerator.java @@ -21,7 +21,7 @@ public interface ExampleValueGenerator { */ default void initialize() {} - String lookupSchemaName(Schema schema); + Optional lookupSchemaName(Schema schema); /** * @return The serializable representation of the example (object for json and yaml, string for others) diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/json/ExampleJsonValueGenerator.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/json/ExampleJsonValueGenerator.java index 9cca5f2cb..aef73c92a 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/json/ExampleJsonValueGenerator.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/json/ExampleJsonValueGenerator.java @@ -34,8 +34,8 @@ public boolean canHandle(String contentType) { } @Override - public String lookupSchemaName(Schema schema) { - return schema.getName(); + public Optional lookupSchemaName(Schema schema) { + return Optional.ofNullable(schema.getName()); } @NotNull diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/xml/ExampleXmlValueGenerator.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/xml/ExampleXmlValueGenerator.java index b365baa38..d4250e881 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/xml/ExampleXmlValueGenerator.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/examples/walkers/xml/ExampleXmlValueGenerator.java @@ -61,11 +61,11 @@ public void initialize() { } @Override - public String lookupSchemaName(Schema schema) { + public Optional lookupSchemaName(Schema schema) { if (schema.getXml() != null && schema.getXml().getName() != null) { - return schema.getXml().getName(); + return Optional.of(schema.getXml().getName()); } - return schema.getName(); + return Optional.ofNullable(schema.getName()); } @Override @@ -158,15 +158,15 @@ public Node createArrayExample(String name, Node arrayItem) { @Override public String prepareForSerialization(Schema schema, Node exampleObject) { - final Node objectToWrite; + final Optional objectToWrite; if (exampleObject instanceof Element) { - objectToWrite = exampleObject; + objectToWrite = Optional.of(exampleObject); } else { - final String name = lookupSchemaName(schema); - objectToWrite = wrapNode(name, exampleObject); + objectToWrite = lookupSchemaName(schema).map(name -> wrapNode(name, exampleObject)); } + try { - document.appendChild(objectToWrite); + document.appendChild(objectToWrite.get()); String xml = exampleXmlValueSerializer.writeDocumentAsXmlString(document); exampleCache.putIfAbsent(getCacheKey(schema), exampleObject); @@ -229,7 +229,7 @@ private Node readXmlString(String xmlString) { private Optional createNodeOrAddAttribute(String value, Schema schema) { if (!nodeStack.isEmpty() && isAttribute(schema)) { Element currentParent = nodeStack.peek(); - currentParent.setAttribute(lookupSchemaName(schema), value); + lookupSchemaName(schema).ifPresent(name -> currentParent.setAttribute(name, value)); return Optional.empty(); } else { return Optional.of(document.createTextNode(value)); 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 d74dfb815..1ac98a505 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 @@ -31,7 +31,7 @@ public boolean canHandle(String contentType) { } @Override - public String lookupSchemaName(Schema schema) { + public Optional lookupSchemaName(Schema schema) { return exampleJsonValueGenerator.lookupSchemaName(schema); } diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalkerJsonIntegrationTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalkerJsonIntegrationTest.java index d500f5aa7..60a94a8b8 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalkerJsonIntegrationTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/examples/walkers/DefaultSchemaWalkerJsonIntegrationTest.java @@ -21,6 +21,7 @@ import io.swagger.v3.oas.models.media.UUIDSchema; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import java.math.BigDecimal; import java.util.List; @@ -62,8 +63,9 @@ void shouldNotHandleOtherContentType() { class FromSchema { @Test - void build() throws JsonProcessingException { + void build(TestInfo testInfo) throws JsonProcessingException { StringSchema schema = new StringSchema(); + schema.setName(testInfo.getDisplayName()); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); String actualString = jsonMapper.writeValueAsString(actual); @@ -72,8 +74,9 @@ void build() throws JsonProcessingException { } @Test - void failWhenMissingDefinition() { + void failWhenMissingDefinition(TestInfo testInfo) { ObjectSchema compositeSchema = new ObjectSchema(); + compositeSchema.setName(testInfo.getDisplayName()); Schema referenceSchema = new Schema(); referenceSchema.set$ref("#/components/schemas/Nested"); @@ -87,8 +90,9 @@ void failWhenMissingDefinition() { @Nested class TestSimpleSchema { @Test - void type_boolean() throws JsonProcessingException { + void type_boolean(TestInfo testInfo) throws JsonProcessingException { BooleanSchema schema = new BooleanSchema(); + schema.setName(testInfo.getDisplayName()); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); String actualString = jsonMapper.writeValueAsString(actual); @@ -97,8 +101,9 @@ void type_boolean() throws JsonProcessingException { } @Test - void type_boolean_example_set() throws JsonProcessingException { + void type_boolean_example_set(TestInfo testInfo) throws JsonProcessingException { BooleanSchema schema = new BooleanSchema(); + schema.setName(testInfo.getDisplayName()); schema.setExample(Boolean.FALSE); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -108,8 +113,9 @@ void type_boolean_example_set() throws JsonProcessingException { } @Test - void type_integer() throws JsonProcessingException { + void type_integer(TestInfo testInfo) throws JsonProcessingException { IntegerSchema schema = new IntegerSchema(); + schema.setName(testInfo.getDisplayName()); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); String actualString = jsonMapper.writeValueAsString(actual); @@ -118,8 +124,9 @@ void type_integer() throws JsonProcessingException { } @Test - void type_integer_example_set() throws JsonProcessingException { + void type_integer_example_set(TestInfo testInfo) throws JsonProcessingException { IntegerSchema schema = new IntegerSchema(); + schema.setName(testInfo.getDisplayName()); schema.setExample(Integer.parseInt("123")); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -129,8 +136,9 @@ void type_integer_example_set() throws JsonProcessingException { } @Test - void type_integer_format_long() throws JsonProcessingException { + void type_integer_format_long(TestInfo testInfo) throws JsonProcessingException { IntegerSchema schema = new IntegerSchema(); + schema.setName(testInfo.getDisplayName()); schema.setFormat("int64"); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -140,8 +148,9 @@ void type_integer_format_long() throws JsonProcessingException { } @Test - void type_number_format_float() throws JsonProcessingException { + void type_number_format_float(TestInfo testInfo) throws JsonProcessingException { Schema schema = new NumberSchema(); + schema.setName(testInfo.getDisplayName()); schema.setFormat("float"); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -151,8 +160,9 @@ void type_number_format_float() throws JsonProcessingException { } @Test - void type_number_format_double() throws JsonProcessingException { + void type_number_format_double(TestInfo testInfo) throws JsonProcessingException { Schema schema = new NumberSchema(); + schema.setName(testInfo.getDisplayName()); schema.setFormat("double"); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -162,8 +172,9 @@ void type_number_format_double() throws JsonProcessingException { } @Test - void type_number_example_set() throws JsonProcessingException { + void type_number_example_set(TestInfo testInfo) throws JsonProcessingException { Schema schema = new NumberSchema(); + schema.setName(testInfo.getDisplayName()); schema.setExample(new BigDecimal("123.45")); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -173,8 +184,9 @@ void type_number_example_set() throws JsonProcessingException { } @Test - void type_string() throws JsonProcessingException { + void type_string(TestInfo testInfo) throws JsonProcessingException { StringSchema schema = new StringSchema(); + schema.setName(testInfo.getDisplayName()); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); String actualString = jsonMapper.writeValueAsString(actual); @@ -183,8 +195,9 @@ void type_string() throws JsonProcessingException { } @Test - void type_string_example_set() throws JsonProcessingException { + void type_string_example_set(TestInfo testInfo) throws JsonProcessingException { StringSchema schema = new StringSchema(); + schema.setName(testInfo.getDisplayName()); schema.setExample("custom-example-value"); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -194,8 +207,9 @@ void type_string_example_set() throws JsonProcessingException { } @Test - void type_string_from_enum() throws JsonProcessingException { + void type_string_from_enum(TestInfo testInfo) throws JsonProcessingException { StringSchema schema = new StringSchema(); + schema.setName(testInfo.getDisplayName()); schema.addEnumItem("EnumItem1"); schema.addEnumItem("EnumItem2"); @@ -206,8 +220,9 @@ void type_string_from_enum() throws JsonProcessingException { } @Test - void type_string_format_byte() throws JsonProcessingException { + void type_string_format_byte(TestInfo testInfo) throws JsonProcessingException { StringSchema schema = new StringSchema(); + schema.setName(testInfo.getDisplayName()); schema.setFormat("byte"); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -217,8 +232,9 @@ void type_string_format_byte() throws JsonProcessingException { } @Test - void type_string_format_binary() throws JsonProcessingException { + void type_string_format_binary(TestInfo testInfo) throws JsonProcessingException { BinarySchema schema = new BinarySchema(); + schema.setName(testInfo.getDisplayName()); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); String actualString = jsonMapper.writeValueAsString(actual); @@ -229,8 +245,9 @@ void type_string_format_binary() throws JsonProcessingException { } @Test - void type_string_format_date() throws JsonProcessingException { + void type_string_format_date(TestInfo testInfo) throws JsonProcessingException { DateSchema schema = new DateSchema(); + schema.setName(testInfo.getDisplayName()); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); String actualString = jsonMapper.writeValueAsString(actual); @@ -239,8 +256,9 @@ void type_string_format_date() throws JsonProcessingException { } @Test - void type_string_format_datetime() throws JsonProcessingException { + void type_string_format_datetime(TestInfo testInfo) throws JsonProcessingException { DateTimeSchema schema = new DateTimeSchema(); + schema.setName(testInfo.getDisplayName()); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); String actualString = jsonMapper.writeValueAsString(actual); @@ -249,8 +267,9 @@ void type_string_format_datetime() throws JsonProcessingException { } @Test - void type_string_format_email() throws JsonProcessingException { + void type_string_format_email(TestInfo testInfo) throws JsonProcessingException { EmailSchema schema = new EmailSchema(); + schema.setName(testInfo.getDisplayName()); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); String actualString = jsonMapper.writeValueAsString(actual); @@ -259,8 +278,9 @@ void type_string_format_email() throws JsonProcessingException { } @Test - void type_string_format_password() throws JsonProcessingException { + void type_string_format_password(TestInfo testInfo) throws JsonProcessingException { PasswordSchema schema = new PasswordSchema(); + schema.setName(testInfo.getDisplayName()); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); String actualString = jsonMapper.writeValueAsString(actual); @@ -269,8 +289,9 @@ void type_string_format_password() throws JsonProcessingException { } @Test - void type_string_format_uuid() throws JsonProcessingException { + void type_string_format_uuid(TestInfo testInfo) throws JsonProcessingException { UUIDSchema schema = new UUIDSchema(); + schema.setName(testInfo.getDisplayName()); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); String actualString = jsonMapper.writeValueAsString(actual); @@ -279,8 +300,9 @@ void type_string_format_uuid() throws JsonProcessingException { } @Test - void type_string_format_unknown() throws JsonProcessingException { + void type_string_format_unknown(TestInfo testInfo) throws JsonProcessingException { StringSchema schema = new StringSchema(); + schema.setName(testInfo.getDisplayName()); schema.setFormat("unknown"); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -290,14 +312,15 @@ void type_string_format_unknown() throws JsonProcessingException { } @Test - void type_unknown_schema() throws JsonProcessingException { + void type_unknown_schema(TestInfo testInfo) throws JsonProcessingException { class TestSchema extends Schema { TestSchema() { - super("test-schema", (String) null); + super("test-schema", null); } } TestSchema schema = new TestSchema(); + schema.setName(testInfo.getDisplayName()); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); String actualString = jsonMapper.writeValueAsString(actual); @@ -306,8 +329,9 @@ class TestSchema extends Schema { } @Test - void type_primitive_array() throws JsonProcessingException { + void type_primitive_array(TestInfo testInfo) throws JsonProcessingException { ArraySchema schema = new ArraySchema(); + schema.setName(testInfo.getDisplayName()); schema.setItems(new StringSchema()); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -320,12 +344,13 @@ void type_primitive_array() throws JsonProcessingException { @Nested class TestObjectSchema { @Test - void type_object_array() throws JsonProcessingException { + void type_object_array(TestInfo testInfo) throws JsonProcessingException { ObjectSchema itemSchema = new ObjectSchema(); itemSchema.addProperty("s", new StringSchema()); itemSchema.addProperty("b", new BooleanSchema()); ArraySchema schema = new ArraySchema(); + schema.setName(testInfo.getDisplayName()); schema.setItems(itemSchema); JsonNode actual = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -335,8 +360,9 @@ void type_object_array() throws JsonProcessingException { } @Test - void composite_object_without_references() throws JsonProcessingException { + void composite_object_without_references(TestInfo testInfo) throws JsonProcessingException { ObjectSchema schema = new ObjectSchema(); + schema.setName(testInfo.getDisplayName()); schema.addProperty("s", new StringSchema()); schema.addProperty("b", new BooleanSchema()); @@ -347,11 +373,12 @@ void composite_object_without_references() throws JsonProcessingException { } @Test - void composite_object_with_references() throws JsonProcessingException { + void composite_object_with_references(TestInfo testInfo) throws JsonProcessingException { Schema referenceSchema = new Schema(); referenceSchema.set$ref("#/components/schemas/Nested"); ObjectSchema compositeSchema = new ObjectSchema(); + compositeSchema.setName(testInfo.getDisplayName()); compositeSchema.addProperty("s", new StringSchema()); compositeSchema.addProperty("f", referenceSchema); @@ -365,8 +392,9 @@ void composite_object_with_references() throws JsonProcessingException { } @Test - void object_with_anyOf() throws JsonProcessingException { + void object_with_anyOf(TestInfo testInfo) throws JsonProcessingException { ObjectSchema compositeSchema = new ObjectSchema(); + compositeSchema.setName(testInfo.getDisplayName()); Schema propertySchema = new ObjectSchema(); propertySchema.setAnyOf(List.of(new StringSchema(), new NumberSchema())); @@ -379,8 +407,9 @@ void object_with_anyOf() throws JsonProcessingException { } @Test - void object_with_oneOf() throws JsonProcessingException { + void object_with_oneOf(TestInfo testInfo) throws JsonProcessingException { ObjectSchema compositeSchema = new ObjectSchema(); + compositeSchema.setName(testInfo.getDisplayName()); Schema propertySchema = new ObjectSchema(); propertySchema.setOneOf(List.of(new StringSchema(), new NumberSchema())); @@ -393,8 +422,9 @@ void object_with_oneOf() throws JsonProcessingException { } @Test - void object_with_allOf() throws JsonProcessingException { + void object_with_allOf(TestInfo testInfo) throws JsonProcessingException { ObjectSchema compositeSchema = new ObjectSchema(); + compositeSchema.setName(testInfo.getDisplayName()); ObjectSchema schema1 = new ObjectSchema(); schema1.setProperties(Map.of("field1", new StringSchema())); @@ -413,8 +443,9 @@ void object_with_allOf() throws JsonProcessingException { } @Test - void schema_with_problematic_object_toString_example() throws JsonProcessingException { + void schema_with_problematic_object_toString_example(TestInfo testInfo) throws JsonProcessingException { ObjectSchema schema = new ObjectSchema(); + schema.setName(testInfo.getDisplayName()); schema.setExample(new ClassWithToString()); JsonNode actual = jsonSchemaWalker.fromSchema(schema, Map.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 9b02dda05..587dafca5 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 @@ -20,6 +20,7 @@ import io.swagger.v3.oas.models.media.UUIDSchema; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import java.math.BigDecimal; import java.util.List; @@ -60,8 +61,9 @@ void shouldNotHandleOtherContentType() { class FromSchema { @Test - void build() { + void build(TestInfo testInfo) { StringSchema schema = new StringSchema(); + schema.setName(testInfo.getDisplayName()); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -71,8 +73,9 @@ void build() { } @Test - void failWhenMissingDefinition() { + void failWhenMissingDefinition(TestInfo testInfo) { ObjectSchema compositeSchema = new ObjectSchema(); + compositeSchema.setName(testInfo.getDisplayName()); Schema referenceSchema = new Schema(); referenceSchema.set$ref("#/components/schemas/Nested"); @@ -86,8 +89,9 @@ void failWhenMissingDefinition() { @Nested class TestSimpleSchema { @Test - void type_boolean() { + void type_boolean(TestInfo testInfo) { BooleanSchema schema = new BooleanSchema(); + schema.setName(testInfo.getDisplayName()); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -97,8 +101,9 @@ void type_boolean() { } @Test - void type_boolean_example_set() { + void type_boolean_example_set(TestInfo testInfo) { BooleanSchema schema = new BooleanSchema(); + schema.setName(testInfo.getDisplayName()); schema.setExample(Boolean.FALSE); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -109,8 +114,9 @@ void type_boolean_example_set() { } @Test - void type_integer() { + void type_integer(TestInfo testInfo) { IntegerSchema schema = new IntegerSchema(); + schema.setName(testInfo.getDisplayName()); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -120,8 +126,9 @@ void type_integer() { } @Test - void type_integer_example_set() { + void type_integer_example_set(TestInfo testInfo) { IntegerSchema schema = new IntegerSchema(); + schema.setName(testInfo.getDisplayName()); schema.setExample(Integer.parseInt("123")); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -132,8 +139,9 @@ void type_integer_example_set() { } @Test - void type_integer_format_long() { + void type_integer_format_long(TestInfo testInfo) { IntegerSchema schema = new IntegerSchema(); + schema.setName(testInfo.getDisplayName()); schema.setFormat("int64"); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -144,8 +152,9 @@ void type_integer_format_long() { } @Test - void type_number_format_float() { + void type_number_format_float(TestInfo testInfo) { Schema schema = new NumberSchema(); + schema.setName(testInfo.getDisplayName()); schema.setFormat("float"); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -156,8 +165,9 @@ void type_number_format_float() { } @Test - void type_number_format_double() { + void type_number_format_double(TestInfo testInfo) { Schema schema = new NumberSchema(); + schema.setName(testInfo.getDisplayName()); schema.setFormat("double"); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -168,8 +178,9 @@ void type_number_format_double() { } @Test - void type_number_example_set() { + void type_number_example_set(TestInfo testInfo) { Schema schema = new NumberSchema(); + schema.setName(testInfo.getDisplayName()); schema.setExample(new BigDecimal("123.45")); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -180,8 +191,9 @@ void type_number_example_set() { } @Test - void type_string() { + void type_string(TestInfo testInfo) { StringSchema schema = new StringSchema(); + schema.setName(testInfo.getDisplayName()); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -191,8 +203,9 @@ void type_string() { } @Test - void type_string_example_set() { + void type_string_example_set(TestInfo testInfo) { StringSchema schema = new StringSchema(); + schema.setName(testInfo.getDisplayName()); schema.setExample("custom-example-value"); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -203,8 +216,9 @@ void type_string_example_set() { } @Test - void type_string_from_enum() { + void type_string_from_enum(TestInfo testInfo) { StringSchema schema = new StringSchema(); + schema.setName(testInfo.getDisplayName()); schema.addEnumItem("EnumItem1"); schema.addEnumItem("EnumItem2"); @@ -216,8 +230,9 @@ void type_string_from_enum() { } @Test - void type_string_format_byte() { + void type_string_format_byte(TestInfo testInfo) { StringSchema schema = new StringSchema(); + schema.setName(testInfo.getDisplayName()); schema.setFormat("byte"); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -228,8 +243,9 @@ void type_string_format_byte() { } @Test - void type_string_format_binary() { + void type_string_format_binary(TestInfo testInfo) { BinarySchema schema = new BinarySchema(); + schema.setName(testInfo.getDisplayName()); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -241,8 +257,9 @@ void type_string_format_binary() { } @Test - void type_string_format_date() { + void type_string_format_date(TestInfo testInfo) { DateSchema schema = new DateSchema(); + schema.setName(testInfo.getDisplayName()); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -252,8 +269,9 @@ void type_string_format_date() { } @Test - void type_string_format_datetime() { + void type_string_format_datetime(TestInfo testInfo) { DateTimeSchema schema = new DateTimeSchema(); + schema.setName(testInfo.getDisplayName()); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -264,8 +282,9 @@ void type_string_format_datetime() { } @Test - void type_string_format_email() { + void type_string_format_email(TestInfo testInfo) { EmailSchema schema = new EmailSchema(); + schema.setName(testInfo.getDisplayName()); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -275,8 +294,9 @@ void type_string_format_email() { } @Test - void type_string_format_password() { + void type_string_format_password(TestInfo testInfo) { PasswordSchema schema = new PasswordSchema(); + schema.setName(testInfo.getDisplayName()); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -286,8 +306,9 @@ void type_string_format_password() { } @Test - void type_string_format_uuid() { + void type_string_format_uuid(TestInfo testInfo) { UUIDSchema schema = new UUIDSchema(); + schema.setName(testInfo.getDisplayName()); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -298,8 +319,9 @@ void type_string_format_uuid() { } @Test - void type_string_format_unknown() { + void type_string_format_unknown(TestInfo testInfo) { StringSchema schema = new StringSchema(); + schema.setName(testInfo.getDisplayName()); schema.setFormat("unknown"); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -311,7 +333,7 @@ void type_string_format_unknown() { } @Test - void type_unknown_schema() { + void type_unknown_schema(TestInfo testInfo) { class TestSchema extends Schema { TestSchema() { super("test-schema", null); @@ -319,6 +341,7 @@ class TestSchema extends Schema { } TestSchema schema = new TestSchema(); + schema.setName(testInfo.getDisplayName()); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -329,8 +352,9 @@ class TestSchema extends Schema { } @Test - void type_primitive_array() { + void type_primitive_array(TestInfo testInfo) { ArraySchema schema = new ArraySchema(); + schema.setName(testInfo.getDisplayName()); schema.setItems(new StringSchema()); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -344,12 +368,13 @@ void type_primitive_array() { @Nested class TestObjectSchema { @Test - void type_object_array() { + void type_object_array(TestInfo testInfo) { ObjectSchema itemSchema = new ObjectSchema(); itemSchema.addProperty("s", new StringSchema()); itemSchema.addProperty("b", new BooleanSchema()); ArraySchema schema = new ArraySchema(); + schema.setName(testInfo.getDisplayName()); schema.setItems(itemSchema); String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap()); @@ -363,8 +388,9 @@ void type_object_array() { } @Test - void composite_object_without_references() { + void composite_object_without_references(TestInfo testInfo) { ObjectSchema schema = new ObjectSchema(); + schema.setName(testInfo.getDisplayName()); schema.addProperty("s", new StringSchema()); schema.addProperty("b", new BooleanSchema()); @@ -378,11 +404,12 @@ void composite_object_without_references() { } @Test - void composite_object_with_references() { + void composite_object_with_references(TestInfo testInfo) { Schema referenceSchema = new Schema(); referenceSchema.set$ref("#/components/schemas/Nested"); ObjectSchema compositeSchema = new ObjectSchema(); + compositeSchema.setName(testInfo.getDisplayName()); compositeSchema.addProperty("s", new StringSchema()); compositeSchema.addProperty("f", referenceSchema); @@ -402,8 +429,9 @@ void composite_object_with_references() { } @Test - void object_with_anyOf() { + void object_with_anyOf(TestInfo testInfo) { ObjectSchema compositeSchema = new ObjectSchema(); + compositeSchema.setName(testInfo.getDisplayName()); Schema propertySchema = new ObjectSchema(); propertySchema.setAnyOf(List.of(new StringSchema(), new NumberSchema())); @@ -417,8 +445,9 @@ void object_with_anyOf() { } @Test - void object_with_oneOf() { + void object_with_oneOf(TestInfo testInfo) { ObjectSchema compositeSchema = new ObjectSchema(); + compositeSchema.setName(testInfo.getDisplayName()); Schema propertySchema = new ObjectSchema(); propertySchema.setOneOf(List.of(new StringSchema(), new NumberSchema())); @@ -432,8 +461,9 @@ void object_with_oneOf() { } @Test - void object_with_allOf() { + void object_with_allOf(TestInfo testInfo) { ObjectSchema compositeSchema = new ObjectSchema(); + compositeSchema.setName(testInfo.getDisplayName()); ObjectSchema schema1 = new ObjectSchema(); schema1.setProperties(Map.of("field1", new StringSchema())); @@ -457,8 +487,9 @@ void object_with_allOf() { } @Test - void schema_with_problematic_object_toString_example() { + void schema_with_problematic_object_toString_example(TestInfo testInfo) { ObjectSchema schema = new ObjectSchema(); + schema.setName(testInfo.getDisplayName()); schema.setExample(new ClassWithToString()); String actualString = jsonSchemaWalker.fromSchema(schema, Map.of());