Skip to content

Commit

Permalink
fix(core): testing with nested class and PascalCase properties (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
timonback authored and sam0r040 committed May 24, 2024
1 parent bc5b24d commit 2136f10
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private List<PropertyExample<T>> buildPropertyExampleListFromSchema(
Map<String, Schema> properties, Map<String, Schema> definitions, Set<Schema> visited) {
return properties.entrySet().stream()
.map(propertySchema -> {
String propertyKey = propertySchema.getKey();
String propertyKey = exampleValueGenerator.lookupSchemaName(propertySchema.getValue());
Optional<T> propertyValue =
buildExample(propertyKey, propertySchema.getValue(), definitions, visited);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Nullable;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -238,7 +239,6 @@ private static class MyClass {
}

@Nested
@XmlRootElement(name = "SchemaWithOneOf")
class SchemaWithOneOf {
@Test
void testSchemaWithOneOf() throws IOException {
Expand Down Expand Up @@ -337,6 +337,47 @@ private static class MyClassWithAttribute {
}
}

@Nested
class TimonTesting {
@Test
void testSchemaWithOneOf() throws IOException {
componentsService.registerSchema(TimonTesting.ClassB.class, "text/xml");
componentsService.registerSchema(TimonTesting.ClassA.class, "text/xml");

String actualDefinitions = objectMapper.writer(printer).writeValueAsString(componentsService.getSchemas());
String expected = jsonResource("/schemas/xml/tback.json");

System.out.println("Got: " + actualDefinitions);
assertEquals(expected, actualDefinitions);
}

@Data
@NoArgsConstructor
@XmlRootElement(name = "ClassA")
private static class ClassA {
@XmlElement(name = "Reference")
private Reference reference;

@XmlElement(name = "ClassB")
private ClassB classB;
}

@Data
@NoArgsConstructor
@XmlRootElement(name = "ClassB")
private static class ClassB {
@XmlElement(name = "Reference")
private Reference reference;
}

@XmlRootElement(name = "Reference")
public class Reference {

@XmlAttribute
private final String value = "test";
}
}

@Nested
class AsyncApiPayloadTest {
@Test
Expand Down
27 changes: 27 additions & 0 deletions springwolf-core/src/test/resources/schemas/xml/tback.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"io.github.springwolf.core.asyncapi.components.DefaultXmlComponentsServiceTest$TimonTesting$ClassA" : {
"type" : "string",
"properties" : {
"classB" : {
"$ref" : "#/components/schemas/io.github.springwolf.core.asyncapi.components.DefaultXmlComponentsServiceTest$TimonTesting$ClassB"
},
"reference" : {
"$ref" : "#/components/schemas/io.github.springwolf.core.asyncapi.components.DefaultXmlComponentsServiceTest$TimonTesting$Reference"
}
},
"examples" : [ "<ClassA><ClassB><Reference/></ClassB><Reference/></ClassA>" ]
},
"io.github.springwolf.core.asyncapi.components.DefaultXmlComponentsServiceTest$TimonTesting$ClassB" : {
"type" : "string",
"properties" : {
"reference" : {
"$ref" : "#/components/schemas/io.github.springwolf.core.asyncapi.components.DefaultXmlComponentsServiceTest$TimonTesting$Reference"
}
},
"examples" : [ "<ClassB><Reference/></ClassB>" ]
},
"io.github.springwolf.core.asyncapi.components.DefaultXmlComponentsServiceTest$TimonTesting$Reference" : {
"type" : "string",
"examples" : [ "<Reference/>" ]
}
}

0 comments on commit 2136f10

Please sign in to comment.