Skip to content
This repository was archived by the owner on Nov 24, 2022. It is now read-only.

Commit dafa443

Browse files
committed
Merge commit 'v2.0.10' tag into 2.0-OpenAPITools
2 parents daba48f + 80148d2 commit dafa443

9 files changed

Lines changed: 229 additions & 25 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ You can include this library from Sonatype OSS for SNAPSHOTS, or Maven central f
124124
<dependency>
125125
<groupId>io.swagger.parser.v3</groupId>
126126
<artifactId>swagger-parser</artifactId>
127-
<version>2.0.11</version>
127+
<version>2.0.12</version>
128128
</dependency>
129129
```
130130

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import io.swagger.v3.oas.models.media.DateTimeSchema;
2525
import io.swagger.v3.oas.models.media.Discriminator;
2626
import io.swagger.v3.oas.models.media.Encoding;
27+
import io.swagger.v3.oas.models.media.MapSchema;
2728
import io.swagger.v3.oas.models.media.MediaType;
29+
import io.swagger.v3.oas.models.media.ObjectSchema;
2830
import io.swagger.v3.oas.models.media.Schema;
2931
import io.swagger.v3.oas.models.media.XML;
3032
import io.swagger.v3.oas.models.security.OAuthFlow;
@@ -49,7 +51,6 @@
4951
import io.swagger.v3.oas.models.servers.ServerVariables;
5052
import io.swagger.v3.parser.core.models.SwaggerParseResult;
5153
import io.swagger.v3.core.util.Json;
52-
import io.swagger.v3.core.util.RefUtils;
5354

5455
import org.apache.commons.lang3.StringUtils;
5556

@@ -102,7 +103,7 @@ public class OpenAPIDeserializer {
102103
private static final String HEADER_PARAMETER = "header";
103104
private static final Pattern RFC3339_DATE_TIME_PATTERN = Pattern.compile( "^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(\\.\\d+)?((Z)|([+-]\\d{2}:\\d{2}))$");
104105
private static final Pattern RFC3339_DATE_PATTERN = Pattern.compile( "^(\\d{4})-(\\d{2})-(\\d{2})$");
105-
106+
private static final String REFERENCE_SEPARATOR = "#/";
106107
private Components components;
107108
private final Set<String> operationIDs = new HashSet<>();
108109

@@ -1421,9 +1422,17 @@ public List<Parameter> getParameterList(ArrayNode obj, String location, ParseRes
14211422
}
14221423
Set<String> filter = new HashSet<>();
14231424

1425+
14241426
parameters.stream().map(this::getParameterDefinition).forEach(param -> {
1427+
String ref = param.get$ref();
14251428
if(!filter.add(param.getName()+"#"+param.getIn())) {
1426-
result.warning(location,"There are duplicate parameter values");
1429+
if(ref != null) {
1430+
if (ref.startsWith(REFERENCE_SEPARATOR)) {// validate if it's inline param also
1431+
result.warning(location, "There are duplicate parameter values");
1432+
}
1433+
}else{
1434+
result.warning(location, "There are duplicate parameter values");
1435+
}
14271436
}
14281437
});
14291438
return parameters;
@@ -2023,7 +2032,8 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result){
20232032
ArrayNode allOfArray = getArray("allOf", node, false, location, result);
20242033
ArrayNode anyOfArray = getArray("anyOf", node, false, location, result);
20252034
ObjectNode itemsNode = getObject("items", node, false, location, result);
2026-
2035+
ObjectNode additionalPropertiesNode = getObject("additionalProperties", node, false, location, result);
2036+
Boolean additionalPropertiesBoolean = getBoolean("additionalProperties", node, false, location, result);
20272037

20282038

20292039
if((allOfArray != null )||(anyOfArray != null)|| (oneOfArray != null)) {
@@ -2075,6 +2085,32 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result){
20752085
schema = items;
20762086
}
20772087

2088+
if(additionalPropertiesNode != null) {
2089+
MapSchema mapSchema = new MapSchema();
2090+
if (additionalPropertiesNode.getNodeType().equals(JsonNodeType.OBJECT)) {
2091+
ObjectNode additionalPropertiesObj = getObject("additionalProperties", node, false, location, result);
2092+
if (additionalPropertiesObj != null) {
2093+
Schema additionalProperties = getSchema(additionalPropertiesObj, location, result);
2094+
if (additionalProperties != null) {
2095+
mapSchema.setAdditionalProperties(additionalProperties);
2096+
schema = mapSchema;
2097+
}
2098+
}
2099+
}
2100+
} else if(additionalPropertiesBoolean != null){
2101+
MapSchema mapSchema = new MapSchema();
2102+
if (additionalPropertiesBoolean) {
2103+
mapSchema.setAdditionalProperties(additionalPropertiesBoolean);
2104+
schema = mapSchema;
2105+
}else{
2106+
ObjectSchema objectSchema = new ObjectSchema();
2107+
objectSchema.setAdditionalProperties(additionalPropertiesBoolean);
2108+
schema = objectSchema;
2109+
}
2110+
}
2111+
2112+
2113+
20782114
if (schema == null){
20792115
schema = SchemaTypeUtil.createSchemaByType(node);
20802116
}
@@ -2267,24 +2303,6 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result){
22672303
schema.setProperties(properties);
22682304
}
22692305

2270-
2271-
if (node.get("additionalProperties") != null) {
2272-
if (node.get("additionalProperties").getNodeType().equals(JsonNodeType.OBJECT)) {
2273-
ObjectNode additionalPropertiesObj = getObject("additionalProperties", node, false, location, result);
2274-
if (additionalPropertiesObj != null) {
2275-
Schema additionalProperties = getSchema(additionalPropertiesObj, location, result);
2276-
if (additionalProperties != null) {
2277-
schema.setAdditionalProperties(additionalProperties);
2278-
}
2279-
}
2280-
} else if (node.get("additionalProperties").getNodeType().equals(JsonNodeType.BOOLEAN)) {
2281-
Boolean additionalProperties = getBoolean("additionalProperties", node, false, location, result);
2282-
if (additionalProperties != null) {
2283-
schema.setAdditionalProperties(additionalProperties);
2284-
}
2285-
2286-
}
2287-
}
22882306
value = getString("description",node,false,location,result);
22892307
if (StringUtils.isNotBlank(value)) {
22902308
schema.setDescription(value);

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,51 @@ public class OpenAPIV3ParserTest {
6565
protected int serverPort = getDynamicPort();
6666
protected WireMockServer wireMockServer;
6767

68+
@Test
69+
public void testIssue1071() {
70+
71+
ParseOptions options = new ParseOptions();
72+
options.setResolve(true);
73+
74+
SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("issue-1071.yaml", null, options);
75+
OpenAPI apispec = parseResult.getOpenAPI();
76+
assertNotNull(apispec);
77+
Schema test = apispec.getPaths().get("/mapschema").getGet().getResponses().get("200").getContent().get("application/json").getSchema();
78+
assertTrue(test instanceof MapSchema);
79+
80+
}
81+
82+
@Test
83+
public void testIssue1071True() {
84+
85+
ParseOptions options = new ParseOptions();
86+
options.setResolve(true);
87+
88+
SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("issue-1071-true.yaml", null, options);
89+
OpenAPI apispec = parseResult.getOpenAPI();
90+
assertNotNull(apispec);
91+
Schema test = apispec.getPaths().get("/mapschema").getGet().getResponses().get("200").getContent().get("application/json").getSchema();
92+
assertTrue(test instanceof MapSchema);
93+
assertTrue(test.getAdditionalProperties() instanceof Boolean);
94+
assertTrue((Boolean)test.getAdditionalProperties());
95+
96+
}
97+
98+
@Test
99+
public void testIssue1071False() {
100+
101+
ParseOptions options = new ParseOptions();
102+
options.setResolve(true);
103+
104+
SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("issue-1071-false.yaml", null, options);
105+
OpenAPI apispec = parseResult.getOpenAPI();
106+
assertNotNull(apispec);
107+
Schema test = apispec.getPaths().get("/mapschema").getGet().getResponses().get("200").getContent().get("application/json").getSchema();
108+
assertTrue(test instanceof ObjectSchema);
109+
assertTrue(test.getAdditionalProperties() instanceof Boolean);
110+
assertFalse((Boolean)test.getAdditionalProperties());
111+
112+
}
68113

69114
@Test
70115
public void testIssue1039() {
@@ -76,7 +121,7 @@ public void testIssue1039() {
76121
OpenAPI apispec = parseResult.getOpenAPI();
77122
assertNotNull(apispec);
78123
assertEquals(apispec.getPaths().get("/pets").getGet().getParameters().get(0).getSchema().getType(),"array");
79-
124+
80125
}
81126

82127
@Test
@@ -1865,6 +1910,26 @@ public void shouldParseApiWithMultipleParameterReferences() {
18651910

18661911
}
18671912

1913+
@Test
1914+
public void testIssue1063() {
1915+
// given
1916+
String location = "src/test/resources/issue-1063/openapi.yaml";
1917+
ParseOptions options = new ParseOptions();
1918+
options.setResolve(true);
1919+
OpenAPIV3Parser tested = new OpenAPIV3Parser();
1920+
1921+
// when
1922+
SwaggerParseResult result = tested.readLocation(location, emptyList(), options);
1923+
1924+
// then
1925+
OpenAPI api = result.getOpenAPI();
1926+
assertEquals(api.getPaths().get("/anPath").getGet().getParameters().get(0).getName(), "customer-id");
1927+
assertEquals(api.getPaths().get("/anPath").getGet().getParameters().get(1).getName(), "unit-id");
1928+
1929+
assertThat(result.getMessages(), equalTo(emptyList()));
1930+
1931+
}
1932+
18681933
private static int getDynamicPort() {
18691934
return new Random().ints(10000, 20000).findFirst().getAsInt();
18701935
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
openapi: 3.0.0
2+
info:
3+
version: 1.0.0
4+
title: an API
5+
description: An API for reproduce a *There are duplicate parameter values*.
6+
7+
paths:
8+
/anPath:
9+
get:
10+
parameters:
11+
- $ref: './references.oas3.yaml#/components/parameters/ParamQ_One'
12+
- $ref: './references.oas3.yaml#/components/parameters/ParamQ_Two'
13+
responses:
14+
'200':
15+
description: OK
16+
content:
17+
application/json:
18+
schema:
19+
type: array
20+
items:
21+
type: string
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
components:
2+
parameters:
3+
ParamQ_One:
4+
in: query
5+
name: customer-id
6+
required: true
7+
schema:
8+
format: int32
9+
type: integer
10+
ParamQ_Two:
11+
in: query
12+
name: unit-id
13+
schema:
14+
format: int32
15+
type: integer
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification
6+
termsOfService: http://swagger.io/terms/
7+
contact:
8+
name: Swagger API Team
9+
email: apiteam@swagger.io
10+
url: http://swagger.io
11+
license:
12+
name: Apache 2.0
13+
url: https://www.apache.org/licenses/LICENSE-2.0.html
14+
servers:
15+
- url: http://petstore.swagger.io/api
16+
paths:
17+
'/mapschema':
18+
get:
19+
description: MapSchema
20+
operationId: MapSchema
21+
responses:
22+
'200':
23+
description: Successful response.
24+
content:
25+
application/json:
26+
schema:
27+
type: object
28+
additionalProperties: false
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification
6+
termsOfService: http://swagger.io/terms/
7+
contact:
8+
name: Swagger API Team
9+
email: apiteam@swagger.io
10+
url: http://swagger.io
11+
license:
12+
name: Apache 2.0
13+
url: https://www.apache.org/licenses/LICENSE-2.0.html
14+
servers:
15+
- url: http://petstore.swagger.io/api
16+
paths:
17+
'/mapschema':
18+
get:
19+
description: MapSchema
20+
operationId: MapSchema
21+
responses:
22+
'200':
23+
description: Successful response.
24+
content:
25+
application/json:
26+
schema:
27+
type: object
28+
additionalProperties: true
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification
6+
termsOfService: http://swagger.io/terms/
7+
contact:
8+
name: Swagger API Team
9+
email: apiteam@swagger.io
10+
url: http://swagger.io
11+
license:
12+
name: Apache 2.0
13+
url: https://www.apache.org/licenses/LICENSE-2.0.html
14+
servers:
15+
- url: http://petstore.swagger.io/api
16+
paths:
17+
'/mapschema':
18+
get:
19+
description: MapSchema
20+
operationId: MapSchema
21+
responses:
22+
'200':
23+
description: Successful response.
24+
content:
25+
application/json:
26+
schema:
27+
type: object
28+
additionalProperties:
29+
type: string

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
<swagger-parser-v2-version>1.0.44</swagger-parser-v2-version>
326326
<commons-io-version>2.4</commons-io-version>
327327
<slf4j-version>1.6.3</slf4j-version>
328-
<swagger-core-version>2.0.7</swagger-core-version>
328+
<swagger-core-version>2.0.8</swagger-core-version>
329329
<junit-version>4.8.1</junit-version>
330330
<testng-version>6.14.2</testng-version>
331331
<jmockit-version>1.35</jmockit-version>

0 commit comments

Comments
 (0)