Skip to content

Commit

Permalink
Merge pull request #412 from swagger-api/anonymous-xml
Browse files Browse the repository at this point in the history
Remove AnonymousModel from fromModel Call
  • Loading branch information
gracekarina authored Nov 25, 2021
2 parents dfc11e2 + d9b76f6 commit f2def36
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 15 additions & 1 deletion src/test/java/io/swagger/test/examples/ExampleBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -73,6 +75,18 @@ public void testAnonymousModel() throws Exception{
assertEquals(output, "<?xml version='1.1' encoding='UTF-8'?><products><product><id>1</id><product>Lump Sum</product></product></products>");
}

@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();

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, "<?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
39 changes: 39 additions & 0 deletions src/test/swagger/allOfExample.yaml
Original file line number Diff line number Diff line change
@@ -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: { }

0 comments on commit f2def36

Please sign in to comment.