Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class V2ConverterTest {
private static final String ISSUE_540_JSON = "issue-540.json";
private static final String ISSUE_647_JSON = "issue-647.yaml";
private static final String ISSUE_662_JSON = "issue-662.yaml";
private static final String ISSUE_673_YAML = "issue-673.yaml";
private static final String ISSUE_676_JSON = "issue-676.json";

private static final String API_BATCH_PATH = "/api/batch/";
Expand Down Expand Up @@ -382,7 +383,7 @@ public void testIssue23() throws Exception {
OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_23_JSON);
assertTrue(oas.getComponents().getSchemas().get(MAP_OBJECTS_MODEL).getAdditionalProperties() instanceof Schema);
Schema additionalProperties = (Schema) oas.getComponents().getSchemas().get(MAP_OBJECTS_MODEL).getAdditionalProperties();
assertEquals(OBJECT_REF,additionalProperties.get$ref());
assertEquals(OBJECT_REF, additionalProperties.get$ref());
}

@Test(description = "Covert path item $refs")
Expand Down Expand Up @@ -575,6 +576,26 @@ public void testIssue676() throws Exception {
assertEquals(anEnum.get(1), false);
}

@Test(description = "OpenAPI v2 converter - Error in BodyParameter convertion")
public void testIssue673() throws Exception {
final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_673_YAML);
assertNotNull(oas);
Schema schema = oas.getPaths().get("/integer").getPost().getRequestBody().getContent().get("application/json").getSchema();
assertNotNull(schema);
assertTrue(schema.getUniqueItems());
assertTrue(schema.getExclusiveMaximum());
assertTrue(schema.getExclusiveMinimum());
assertEquals(3, schema.getMultipleOf().toBigInteger().intValue());
assertEquals(new BigDecimal(5), schema.getMinimum());
assertEquals(new BigDecimal(7), schema.getMaximum());

schema = oas.getPaths().get("/string").getPost().getRequestBody().getContent().get("application/json").getSchema();
assertEquals(2, schema.getMinLength().intValue());
assertEquals(7, schema.getMaxLength().intValue());
assertEquals("aaa", schema.getPattern());

}

private OpenAPI getConvertedOpenAPIFromJsonFile(String file) throws IOException, URISyntaxException {
SwaggerConverter converter = new SwaggerConverter();
String swaggerAsString = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource(file).toURI())));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
swagger: '2.0'
info:
version: 1.0.0
title: Test
paths:
"/integer":
post:
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: body
required: true
schema:
type: integer
format: int32
multipleOf: 3
minimum: 5
maximum: 7
exclusiveMinimum: true
exclusiveMaximum: true
uniqueItems: true
"/array":
post:
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: body
required: true
schema:
type: array
items:
type: string
uniqueItems: true
"/string":
post:
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: body
required: true
schema:
type: string
minLength: 2
maxLength: 7
pattern: aaa
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
</repository>
</repositories>
<properties>
<swagger-parser-v2-version>1.0.35</swagger-parser-v2-version>
<swagger-parser-v2-version>1.0.36-SNAPSHOT</swagger-parser-v2-version>
<commons-io-version>2.4</commons-io-version>
<slf4j-version>1.6.3</slf4j-version>
<swagger-core-version>2.0.1</swagger-core-version>
Expand Down