Skip to content

Commit

Permalink
fix AnonymousModelIssue
Browse files Browse the repository at this point in the history
  • Loading branch information
gracekarina committed Aug 29, 2021
1 parent c1c6c4e commit 523c8e3
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@
</dependency>
</dependencies>
<properties>
<swagger-core-version>1.6.0</swagger-core-version>
<swagger-core-version>1.6.3-SNAPSHOT</swagger-core-version>
<swagger-parser-version>1.0.48</swagger-parser-version>
<jackson.version>2.10.1</jackson.version>
<joda-time-version>2.9.1</joda-time-version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public static Example fromProperty(Property property, Map<String, Model> definit
if (name != null) {
output.setWrappedName(name);
}
} else if (name != null) {
}else if (name != null) {
output.setName(name);
}
output.setNamespace(namespace);
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 12 additions & 12 deletions src/test/java/io/swagger/test/examples/ExampleBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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, "<?xml version='1.1' encoding='UTF-8'?><products><product><id>1</id><product>Lump Sum</product></product></products>");
}

@Test
public void testReadModel() throws Exception {
Map<String, Model> definitions = ModelConverters.getInstance().readAll(User.class);
Expand Down
41 changes: 41 additions & 0 deletions src/test/swagger/AnonymousTagExpected.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 523c8e3

Please sign in to comment.