From f9970b195abd03628cf53f027f08f6b3115df471 Mon Sep 17 00:00:00 2001 From: Joel Jonsson Date: Tue, 23 Nov 2021 21:43:25 +0100 Subject: [PATCH 1/2] Test calling ExampleBuilder our way --- .../test/examples/ExampleBuilderTest.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/swagger/test/examples/ExampleBuilderTest.java b/src/test/java/io/swagger/test/examples/ExampleBuilderTest.java index 4554454e..4e3c58cc 100644 --- a/src/test/java/io/swagger/test/examples/ExampleBuilderTest.java +++ b/src/test/java/io/swagger/test/examples/ExampleBuilderTest.java @@ -46,8 +46,10 @@ import org.testng.Assert; import org.testng.annotations.Test; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import static org.testng.Assert.assertEquals; @@ -73,6 +75,19 @@ public void testAnonymousModel() throws Exception{ assertEquals(output, "1Lump Sum"); } + @Test + public void testAnonymousModelFromModel() throws Exception{ + String swaggerString = new String(Files.readAllBytes(Paths.get("src/test/swagger/AnonymousTagExpected.yaml")), StandardCharsets.UTF_8); + Swagger swagger = new SwaggerParser().readWithInfo(swaggerString, false).getSwagger(); + new ResolverUtil().resolveFully(swagger); + + Model model = swagger.getPaths().get("/products.xml").getGet().getResponses().get("200").getResponseSchema(); + Example example = ExampleBuilder.fromModel(null, model, swagger.getDefinitions(), new HashMap<>()); + + String output = new XmlExampleSerializer().serialize(example); + assertEquals(output, "1Lump Sum"); + } + @Test public void testReadModel() throws Exception { Map definitions = ModelConverters.getInstance().readAll(User.class); From d9b76f668b992680f29b68e6df1e226ddcc451c8 Mon Sep 17 00:00:00 2001 From: gracekarina Date: Thu, 25 Nov 2021 11:15:00 -0500 Subject: [PATCH 2/2] Adds xml validation for ArraySchema --- .../inflector/examples/ExampleBuilder.java | 9 ++++- .../test/examples/ExampleBuilderTest.java | 1 - src/test/swagger/allOfExample.yaml | 39 +++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/test/swagger/allOfExample.yaml diff --git a/src/main/java/io/swagger/inflector/examples/ExampleBuilder.java b/src/main/java/io/swagger/inflector/examples/ExampleBuilder.java index d4040602..fa9905d1 100644 --- a/src/main/java/io/swagger/inflector/examples/ExampleBuilder.java +++ b/src/main/java/io/swagger/inflector/examples/ExampleBuilder.java @@ -699,7 +699,14 @@ else if(model instanceof ArrayModel) { } } else { ArrayModel am = (ArrayModel) model; - + if (am.getXml() != null) { + Xml xml = am.getXml(); + name = xml.getName(); + namespace = xml.getNamespace(); + prefix = xml.getPrefix(); + attribute = xml.getAttribute(); + wrapped = xml.getWrapped() != null ? xml.getWrapped() : false; + } Property inner = am.getItems(); if (inner != null) { Example innerExample = fromProperty(inner, definitions, processedModels); diff --git a/src/test/java/io/swagger/test/examples/ExampleBuilderTest.java b/src/test/java/io/swagger/test/examples/ExampleBuilderTest.java index 4e3c58cc..e890755f 100644 --- a/src/test/java/io/swagger/test/examples/ExampleBuilderTest.java +++ b/src/test/java/io/swagger/test/examples/ExampleBuilderTest.java @@ -79,7 +79,6 @@ public void testAnonymousModel() throws Exception{ public void testAnonymousModelFromModel() throws Exception{ String swaggerString = new String(Files.readAllBytes(Paths.get("src/test/swagger/AnonymousTagExpected.yaml")), StandardCharsets.UTF_8); Swagger swagger = new SwaggerParser().readWithInfo(swaggerString, false).getSwagger(); - new ResolverUtil().resolveFully(swagger); Model model = swagger.getPaths().get("/products.xml").getGet().getResponses().get("200").getResponseSchema(); Example example = ExampleBuilder.fromModel(null, model, swagger.getDefinitions(), new HashMap<>()); diff --git a/src/test/swagger/allOfExample.yaml b/src/test/swagger/allOfExample.yaml new file mode 100644 index 00000000..32efdf38 --- /dev/null +++ b/src/test/swagger/allOfExample.yaml @@ -0,0 +1,39 @@ +openapi: 3.0.0 +info: + version: 0.1.0 + title: Example of Nested SubSchemas using allOf +paths: + /foo: + get: + responses: + '200': + description: ok + content: + application/json: + schema: + allOf: + - type: object + properties: + data1: # <---- IGNORED + type: object + properties: + id: + type: integer + example: 5 + attributes: + type: object + properties: + foo: + type: string + - type: object + properties: + data2: # <---- The mock uses this one instead + type: object + properties: + attributes: + type: object + properties: + bar: + type: string +components: + schemas: { } \ No newline at end of file