Skip to content

Commit f15c7f7

Browse files
authored
Merge pull request #573 from gibson042/swagger-codegen-6896-untyped
Handle untyped schemas
2 parents d7da4ca + fbf7042 commit f15c7f7

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

modules/swagger-parser/src/test/java/io/swagger/parser/util/SwaggerDeserializerTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,4 +1419,39 @@ public void testIssue360() {
14191419
Swagger rebuilt = result.getSwagger();
14201420
assertNotNull(rebuilt);
14211421
}
1422+
1423+
@Test(description = "it should deserialize untyped additionalProperties")
1424+
public void testUntypedAdditionalProperties() {
1425+
String json = "{\n" +
1426+
" \"paths\": {\n" +
1427+
" \"/store/inventory\": {\n" +
1428+
" \"get\": {\n" +
1429+
" \"responses\": {\n" +
1430+
" \"200\": {\n" +
1431+
" \"description\": \"successful operation\",\n" +
1432+
" \"schema\": {\n" +
1433+
" \"type\": \"object\",\n" +
1434+
" \"description\": \"map of anything\",\n" +
1435+
" \"additionalProperties\": {}\n" +
1436+
" }\n" +
1437+
" }\n" +
1438+
" }\n" +
1439+
" }\n" +
1440+
" }\n" +
1441+
" }\n" +
1442+
"}";
1443+
1444+
SwaggerParser parser = new SwaggerParser();
1445+
1446+
SwaggerDeserializationResult result = parser.readWithInfo(json);
1447+
List<String> messageList = result.getMessages();
1448+
Set<String> messages = new HashSet<String>(messageList);
1449+
Swagger swagger = result.getSwagger();
1450+
1451+
Property response = swagger.getPath("/store/inventory").getGet().getResponses().get("200").getSchema();
1452+
assertTrue(response instanceof MapProperty);
1453+
Property additionalProperties = ((MapProperty) response).getAdditionalProperties();
1454+
assertTrue(additionalProperties instanceof UntypedProperty);
1455+
assertEquals(additionalProperties.getType(), null);
1456+
}
14221457
}

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@
197197
<artifactId>swagger-core</artifactId>
198198
<version>${swagger-core-version}</version>
199199
</dependency>
200+
<dependency>
201+
<groupId>io.swagger</groupId>
202+
<artifactId>swagger-models</artifactId>
203+
<version>${swagger-core-version}</version>
204+
</dependency>
200205
<dependency>
201206
<groupId>org.testng</groupId>
202207
<artifactId>testng</artifactId>

0 commit comments

Comments
 (0)