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

Commit 85e1169

Browse files
author
Jakub Małek
committed
Merge remote-tracking branch 'upstream/master'
# Conflicts: # modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/RefUtilsTest.java
2 parents ccf2e39 + f94d751 commit 85e1169

18 files changed

Lines changed: 571 additions & 33 deletions

File tree

README.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,8 @@ You can include this library from Sonatype OSS for SNAPSHOTS, or Maven central f
9999
<dependency>
100100
<groupId>io.swagger.parser.v3</groupId>
101101
<artifactId>swagger-parser</artifactId>
102-
<version>2.0.10-SNAPSHOT</version>
102+
<version>2.0.11</version>
103103
</dependency>
104-
105-
```
106-
107-
or
108-
109-
```xml
110-
<dependency>
111-
<groupId>io.swagger.parser.v3</groupId>
112-
<artifactId>swagger-parser</artifactId>
113-
<version>2.0.10-SNAPSHOT</version>
114-
</dependency>
115-
116104
```
117105

118106

modules/swagger-parser-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>io.swagger.parser.v3</groupId>
55
<artifactId>swagger-parser-project</artifactId>
6-
<version>2.0.10-SNAPSHOT</version>
6+
<version>2.0.12-SNAPSHOT</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>

modules/swagger-parser-v2-converter/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>io.swagger.parser.v3</groupId>
55
<artifactId>swagger-parser-project</artifactId>
6-
<version>2.0.10-SNAPSHOT</version>
6+
<version>2.0.12-SNAPSHOT</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>

modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ public Parameter convert(io.swagger.models.parameters.Parameter v2Parameter) {
10601060

10611061
schema = a;
10621062
} else {
1063-
schema = new Schema();
1063+
schema = SchemaTypeUtil.createSchema(sp.getType(), sp.getFormat());
10641064
schema.setType(sp.getType());
10651065
schema.setFormat(sp.getFormat());
10661066

modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.swagger.v3.oas.models.info.Info;
99
import io.swagger.v3.oas.models.media.ArraySchema;
1010
import io.swagger.v3.oas.models.media.ComposedSchema;
11+
import io.swagger.v3.oas.models.media.IntegerSchema;
1112
import io.swagger.v3.oas.models.media.Schema;
1213
import io.swagger.v3.oas.models.parameters.Parameter;
1314
import io.swagger.v3.oas.models.parameters.RequestBody;
@@ -88,6 +89,7 @@ public class V2ConverterTest {
8889
private static final String ISSUE_765_YAML = "issue-765.yaml";
8990
private static final String ISSUE_768_JSON = "issue-786.json";
9091
private static final String ISSUE_820_YAML = "issue-820.yaml";
92+
private static final String ISSUE_1032_YAML = "issue-1032.yaml";
9193

9294
private static final String API_BATCH_PATH = "/api/batch/";
9395
private static final String PETS_PATH = "/pets";
@@ -153,6 +155,9 @@ public class V2ConverterTest {
153155
private static final String ARRAY_VALUES = "[{\"id\":-1,\"name\":\"Marvin the Paranoid Android\"}," +
154156
"{\"id\":1000000,\"name\":\"Zaphod Beeblebrox\",\"friends\":[15]}]";
155157
private static final String SCHEMAS_A_REF = "#/components/schemas/A";
158+
private static final String UNIX_TIMESTAMP_QUERY_PARAM = "unixTimestampQuery";
159+
private static final String INTEGER_TYPE = "integer";
160+
private static final String INT64_FORMAT = "int64";
156161

157162
private static final int MAX_LENGTH = 60;
158163
private static final int REQUIRED_SIZE = 2;
@@ -164,7 +169,7 @@ public class V2ConverterTest {
164169
private static final int MIN_LENGTH = 3;
165170
private static final int NUMBER_VALUE_TWENTY = 20;
166171
private static final double MULTIPLE_OF_VALUE = 0.01D;
167-
private static final long DEFAULT_VALUE = 11L;
172+
private static final int DEFAULT_VALUE = 11;
168173
private static final int EXAMPLE_8_NUMBER = 8;
169174
private static final int EXAMPLE_42_NUMBER = 42;
170175

@@ -762,6 +767,19 @@ public void testIssue820() throws Exception {
762767
assertEquals(baz.getNullable(), Boolean.FALSE);
763768
}
764769

770+
@Test(description = "OpenAPI v2 converter - proper IntegerSchema parsing")
771+
public void testIssue1032() throws Exception {
772+
final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1032_YAML);
773+
assertNotNull(oas);
774+
Parameter unixTimestampQueryParameter = oas.getComponents().getParameters().get(UNIX_TIMESTAMP_QUERY_PARAM);
775+
assertNotNull(unixTimestampQueryParameter);
776+
Schema s = unixTimestampQueryParameter.getSchema();
777+
assertTrue((s instanceof IntegerSchema), "actual type: " + s);
778+
IntegerSchema integerSchema = (IntegerSchema) s;
779+
assertEquals(INTEGER_TYPE, integerSchema.getType());
780+
assertEquals(INT64_FORMAT, integerSchema.getFormat());
781+
}
782+
765783
private OpenAPI getConvertedOpenAPIFromJsonFile(String file) throws IOException, URISyntaxException {
766784
SwaggerConverter converter = new SwaggerConverter();
767785
String swaggerAsString = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource(file).toURI())));
@@ -771,4 +789,4 @@ private OpenAPI getConvertedOpenAPIFromJsonFile(String file) throws IOException,
771789
assertNotNull(result);
772790
return result.getOpenAPI();
773791
}
774-
}
792+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
swagger: '2.0'
2+
basePath: "/"
3+
info:
4+
version: "1"
5+
title: "x"
6+
7+
schemes:
8+
- https
9+
consumes:
10+
- application/json
11+
produces:
12+
- application/json
13+
paths:
14+
/data:
15+
get:
16+
operationId: "getData"
17+
parameters:
18+
- $ref: '#/parameters/unixTimestampQuery'
19+
responses:
20+
'403':
21+
description: Forbidden
22+
parameters:
23+
unixTimestampQuery:
24+
in: query
25+
name: unixTimestamp
26+
type: integer
27+
format: int64

modules/swagger-parser-v3/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>io.swagger.parser.v3</groupId>
55
<artifactId>swagger-parser-project</artifactId>
6-
<version>2.0.10-SNAPSHOT</version>
6+
<version>2.0.12-SNAPSHOT</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
7777
Schema existingModel = schemas.get(possiblyConflictingDefinitionName);
7878

7979
if (existingModel != null) {
80-
LOGGER.debug("A model for " + existingModel + " already exists");
80+
LOGGER.warn("A model for " + existingModel + " already exists");
8181
if(existingModel.get$ref() != null) {
8282
// use the new model
8383
existingModel = null;

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,8 @@ public Map<String, Parameter> getParameters(ObjectNode obj, String location, Par
13671367
return null;
13681368
}
13691369
Map<String, Parameter> parameters = new LinkedHashMap<>();
1370+
Set<String> filter = new HashSet<>();
1371+
Parameter parameter=null;
13701372

13711373
Set<String> parameterKeys = getKeys(obj);
13721374
for(String parameterName : parameterKeys) {
@@ -1379,12 +1381,13 @@ public Map<String, Parameter> getParameters(ObjectNode obj, String location, Par
13791381
if (parameterValue.getNodeType().equals(JsonNodeType.OBJECT)) {
13801382
ObjectNode parameterObj = (ObjectNode) parameterValue;
13811383
if(parameterObj != null) {
1382-
Parameter parameter = getParameter(parameterObj, String.format("%s.%s", location, parameterName), result);
1384+
parameter = getParameter(parameterObj, String.format("%s.%s", location, parameterName), result);
13831385
if (parameter != null) {
13841386
parameters.put(parameterName, parameter);
13851387
}
13861388
}
13871389
}
1390+
13881391
}
13891392
return parameters;
13901393
}
@@ -1403,6 +1406,13 @@ public List<Parameter> getParameterList(ArrayNode obj, String location, ParseRes
14031406
}
14041407
}
14051408
}
1409+
Set<String> filter = new HashSet<>();
1410+
1411+
for(Parameter param:parameters) {
1412+
if(!filter.add(param.getName()+"#"+param.getIn())) {
1413+
result.warning(location,"There are duplicate parameter values");
1414+
}
1415+
}
14061416
return parameters;
14071417
}
14081418

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ public static String buildUrl(String rootPath, String relativePath) {
132132
if(!"".equals(rootPathParts[rootPathParts.length - 1])) {
133133
trimRoot = 1;
134134
}
135+
if("".equals(relPathParts[0])) {
136+
trimRel = 1; trimRoot = rootPathParts.length-3;
137+
}
135138
for(int i = 0; i < rootPathParts.length; i++) {
136139
if("".equals(rootPathParts[i])) {
137140
trimRel += 1;
@@ -145,7 +148,7 @@ public static String buildUrl(String rootPath, String relativePath) {
145148
trimRel += 1;
146149
}
147150
else if ("..".equals(relPathParts[i])) {
148-
trimRel += 1;
151+
trimRel += 1; trimRoot += 1;
149152
}
150153
}
151154

@@ -154,7 +157,7 @@ else if ("..".equals(relPathParts[i])) {
154157
System.arraycopy(relPathParts,
155158
trimRel,
156159
outputParts,
157-
rootPathParts.length - trimRoot + trimRel - 1,
160+
rootPathParts.length - trimRoot,
158161
relPathParts.length - trimRel);
159162

160163
return StringUtils.join(outputParts, "/");

0 commit comments

Comments
 (0)