From 523c8e312d47847effd27f2697fee5d52d70ce33 Mon Sep 17 00:00:00 2001 From: gracekarina Date: Sun, 29 Aug 2021 07:50:54 -0500 Subject: [PATCH] fix AnonymousModelIssue --- pom.xml | 2 +- .../inflector/examples/ExampleBuilder.java | 5 ++- .../test/examples/ExampleBuilderTest.java | 24 +++++------ src/test/swagger/AnonymousTagExpected.yaml | 41 +++++++++++++++++++ 4 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 src/test/swagger/AnonymousTagExpected.yaml diff --git a/pom.xml b/pom.xml index 2dce2f2e..824a026a 100644 --- a/pom.xml +++ b/pom.xml @@ -446,7 +446,7 @@ - 1.6.0 + 1.6.3-SNAPSHOT 1.0.48 2.10.1 2.9.1 diff --git a/src/main/java/io/swagger/inflector/examples/ExampleBuilder.java b/src/main/java/io/swagger/inflector/examples/ExampleBuilder.java index f43529a6..d4040602 100644 --- a/src/main/java/io/swagger/inflector/examples/ExampleBuilder.java +++ b/src/main/java/io/swagger/inflector/examples/ExampleBuilder.java @@ -396,7 +396,7 @@ public static Example fromProperty(Property property, Map definit if (name != null) { output.setWrappedName(name); } - } else if (name != null) { + }else if (name != null) { output.setName(name); } output.setNamespace(namespace); @@ -735,7 +735,8 @@ else if(model instanceof RefModel) { if (name != null) { output.setWrappedName(name); } - } else if (name != null) { + } + if (name != null) { output.setName(name); } output.setNamespace(namespace); diff --git a/src/test/java/io/swagger/test/examples/ExampleBuilderTest.java b/src/test/java/io/swagger/test/examples/ExampleBuilderTest.java index 9cbec466..4554454e 100644 --- a/src/test/java/io/swagger/test/examples/ExampleBuilderTest.java +++ b/src/test/java/io/swagger/test/examples/ExampleBuilderTest.java @@ -38,18 +38,7 @@ import io.swagger.models.Response; import io.swagger.models.Swagger; import io.swagger.models.Xml; -import io.swagger.models.properties.AbstractProperty; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.BaseIntegerProperty; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DecimalProperty; -import io.swagger.models.properties.DoubleProperty; -import io.swagger.models.properties.FloatProperty; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.LongProperty; -import io.swagger.models.properties.MapProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.models.properties.*; import io.swagger.parser.SwaggerParser; import io.swagger.test.models.User; import io.swagger.util.Json; @@ -73,6 +62,17 @@ public class ExampleBuilderTest { Yaml.mapper().registerModule(simpleModule); } + @Test + public void testAnonymousModel() throws Exception{ + Swagger swagger = new SwaggerParser().read("src/test/swagger/AnonymousTagExpected.yaml"); + + Property property = swagger.getPaths().get("/products.xml").getGet().getResponses().get("200").getSchema(); + Example example = ExampleBuilder.fromProperty(property, swagger.getDefinitions()); + + String output = new XmlExampleSerializer().serialize(example); + assertEquals(output, "1Lump Sum"); + } + @Test public void testReadModel() throws Exception { Map definitions = ModelConverters.getInstance().readAll(User.class); diff --git a/src/test/swagger/AnonymousTagExpected.yaml b/src/test/swagger/AnonymousTagExpected.yaml new file mode 100644 index 00000000..ffcac4f9 --- /dev/null +++ b/src/test/swagger/AnonymousTagExpected.yaml @@ -0,0 +1,41 @@ +swagger: "2.0" +info: + version: v0.1 + title: KFI quote engine and product listings API + description: "" +schemes: + - https +paths: + /products.xml: + get: + summary: Get a list of public products in XML format + operationId: getProductsXML + tags: + - Product List Service + produces: + - application/xml + responses: + 200: + description: OK + schema: + xml: + wrapped: true + name: products + type: array + items: + $ref: "#/definitions/product" +tags: + - name: Product List Service +definitions: + product: + type: object + xml: + name: product + wrapped: true + properties: + id: + type: integer + example: 1 + product: + type: string + example: Lump Sum