Skip to content

Commit 69748da

Browse files
authored
Merge branch 'master' into preserve-body-parameter-name
2 parents 14e9c90 + 100c912 commit 69748da

File tree

69 files changed

+4664
-1531
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+4664
-1531
lines changed

README.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,13 @@ 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.8-SNAPSHOT</version>
102+
<version>2.0.12</version>
103103
</dependency>
104-
105104
```
106105

107-
or
108-
109-
```xml
110-
<dependency>
111-
<groupId>io.swagger.parser.v3</groupId>
112-
<artifactId>swagger-parser</artifactId>
113-
<version>2.0.8-SNAPSHOT</version>
114-
</dependency>
115-
116-
```
106+
## Security contact
117107

108+
Please disclose any security-related issues or vulnerabilities by emailing [[email protected]](mailto:[email protected]), instead of using the public issue tracker.
118109

119110
License
120111
-------

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.8-SNAPSHOT</version>
6+
<version>2.0.13-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.8-SNAPSHOT</version>
6+
<version>2.0.13-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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import java.util.ArrayList;
7272
import java.util.Arrays;
7373
import java.util.HashMap;
74+
import java.util.LinkedHashMap;
7475
import java.util.List;
7576
import java.util.Map;
7677
import java.util.Optional;
@@ -139,6 +140,10 @@ public SwaggerParseResult convert(SwaggerDeserializationResult parse) {
139140

140141
Swagger swagger = parse.getSwagger();
141142

143+
if (swagger.getVendorExtensions() != null) {
144+
openAPI.setExtensions(convert(swagger.getVendorExtensions()));
145+
}
146+
142147
if (swagger.getExternalDocs() != null) {
143148
openAPI.setExternalDocs(convert(swagger.getExternalDocs()));
144149
}
@@ -415,7 +420,7 @@ private List<Server> convert(List<Scheme> schemes, String host, String basePath)
415420
servers.add(server);
416421
}
417422
} else {
418-
if (!"/".equals(baseUrl)) {
423+
if (!StringUtils.startsWith(baseUrl, "/") && !"/".equals(baseUrl)) {
419424
baseUrl = "//" + baseUrl;
420425
}
421426
Server server = new Server();
@@ -917,7 +922,7 @@ private Schema convert(Property schema) {
917922
result.setExample(schema.getExample());
918923

919924
if ("object".equals(schema.getType()) && (result.getProperties() != null) && (result.getProperties().size() > 0)) {
920-
Map<String, Schema> properties = new HashMap<>();
925+
Map<String, Schema> properties = new LinkedHashMap<>();
921926

922927
((ObjectProperty) schema).getProperties().forEach((k, v) -> properties.put(k, convert(v)));
923928

@@ -1056,7 +1061,7 @@ public Parameter convert(io.swagger.models.parameters.Parameter v2Parameter) {
10561061

10571062
schema = a;
10581063
} else {
1059-
schema = new Schema();
1064+
schema = SchemaTypeUtil.createSchema(sp.getType(), sp.getFormat());
10601065
schema.setType(sp.getType());
10611066
schema.setFormat(sp.getFormat());
10621067

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

Lines changed: 38 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,8 @@ 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";
93+
private static final String ISSUE_1113_YAML = "issue-1113.yaml";
9194

9295
private static final String API_BATCH_PATH = "/api/batch/";
9396
private static final String PETS_PATH = "/pets";
@@ -153,6 +156,9 @@ public class V2ConverterTest {
153156
private static final String ARRAY_VALUES = "[{\"id\":-1,\"name\":\"Marvin the Paranoid Android\"}," +
154157
"{\"id\":1000000,\"name\":\"Zaphod Beeblebrox\",\"friends\":[15]}]";
155158
private static final String SCHEMAS_A_REF = "#/components/schemas/A";
159+
private static final String UNIX_TIMESTAMP_QUERY_PARAM = "unixTimestampQuery";
160+
private static final String INTEGER_TYPE = "integer";
161+
private static final String INT64_FORMAT = "int64";
156162

157163
private static final int MAX_LENGTH = 60;
158164
private static final int REQUIRED_SIZE = 2;
@@ -164,7 +170,7 @@ public class V2ConverterTest {
164170
private static final int MIN_LENGTH = 3;
165171
private static final int NUMBER_VALUE_TWENTY = 20;
166172
private static final double MULTIPLE_OF_VALUE = 0.01D;
167-
private static final long DEFAULT_VALUE = 11L;
173+
private static final int DEFAULT_VALUE = 11;
168174
private static final int EXAMPLE_8_NUMBER = 8;
169175
private static final int EXAMPLE_42_NUMBER = 42;
170176

@@ -734,6 +740,13 @@ public void testIssue755() throws Exception {
734740
final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_755_YAML);
735741
assertNotNull(oas);
736742
}
743+
744+
@Test(description = "OpenAPI v2 converter - top-level extensions should be preserved")
745+
public void testTopLevelExtensions() throws Exception {
746+
final OpenAPI oas = getConvertedOpenAPIFromJsonFile(PARAMETER_CONVERSION_JSON);
747+
assertNotNull(oas);
748+
assertEquals((String)oas.getExtensions().get("x-some-extensions"), "hello");
749+
}
737750

738751
@Test(description = "OpenAPI v2 converter - Conversion param extensions should be preserved")
739752
public void testIssue820() throws Exception {
@@ -762,6 +775,29 @@ public void testIssue820() throws Exception {
762775
assertEquals(baz.getNullable(), Boolean.FALSE);
763776
}
764777

778+
@Test(description = "OpenAPI v2 converter - proper IntegerSchema parsing")
779+
public void testIssue1032() throws Exception {
780+
final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1032_YAML);
781+
assertNotNull(oas);
782+
Parameter unixTimestampQueryParameter = oas.getComponents().getParameters().get(UNIX_TIMESTAMP_QUERY_PARAM);
783+
assertNotNull(unixTimestampQueryParameter);
784+
Schema s = unixTimestampQueryParameter.getSchema();
785+
assertTrue((s instanceof IntegerSchema), "actual type: " + s);
786+
IntegerSchema integerSchema = (IntegerSchema) s;
787+
assertEquals(INTEGER_TYPE, integerSchema.getType());
788+
assertEquals(INT64_FORMAT, integerSchema.getFormat());
789+
}
790+
791+
@Test(description = "OpenAPI v2 converter - converts URL correctly when it begins with forward slash")
792+
public void testIssue1113() throws Exception {
793+
final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1113_YAML);
794+
assertNotNull(oas);
795+
assertNotNull(oas.getServers());
796+
assertFalse(oas.getServers().isEmpty());
797+
assertNotNull(oas.getServers().get(0));
798+
assertEquals(oas.getServers().get(0).getUrl(), "/test");
799+
}
800+
765801
private OpenAPI getConvertedOpenAPIFromJsonFile(String file) throws IOException, URISyntaxException {
766802
SwaggerConverter converter = new SwaggerConverter();
767803
String swaggerAsString = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource(file).toURI())));
@@ -771,4 +807,4 @@ private OpenAPI getConvertedOpenAPIFromJsonFile(String file) throws IOException,
771807
assertNotNull(result);
772808
return result.getOpenAPI();
773809
}
774-
}
810+
}
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
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
swagger: '2.0'
2+
info:
3+
title: Test for Issue 1113
4+
version: 1.0.0
5+
basePath: /test
6+
paths:
7+
/ping:
8+
get:
9+
summary: test
10+
description: 'test'
11+
operationId: pingOp
12+
responses:
13+
'200':
14+
description: OK

modules/swagger-parser-v2-converter/src/test/resources/parameter-conversion.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"swagger": "2.0",
3+
"x-some-extensions": "hello",
34
"info": {
45
"version": "1.0",
56
"title": "x-example"

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.8-SNAPSHOT</version>
6+
<version>2.0.13-SNAPSHOT</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIV3Parser.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,36 @@ public SwaggerParseResult readContents(String swaggerAsString, List<Authorizatio
197197
return result;
198198
}
199199

200-
protected List<SwaggerParserExtension> getExtensions() {
200+
/**
201+
* Locates extensions on the current thread class loader and then, if it differs
202+
* from this class classloader (as in OSGi), locates extensions from this
203+
* class classloader as well.
204+
*
205+
* @return a list of extensions
206+
*/
207+
public static List<SwaggerParserExtension> getExtensions() {
208+
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
209+
List<SwaggerParserExtension> extensions = getExtensions(tccl);
210+
ClassLoader cl = SwaggerParserExtension.class.getClassLoader();
211+
if (cl != tccl) {
212+
extensions.addAll(getExtensions(cl));
213+
}
214+
extensions.add(0, new OpenAPIV3Parser());
215+
return extensions;
216+
}
217+
218+
protected static List<SwaggerParserExtension> getExtensions(ClassLoader cl) {
201219
List<SwaggerParserExtension> extensions = new ArrayList<>();
202220

203-
ServiceLoader<SwaggerParserExtension> loader = ServiceLoader.load(SwaggerParserExtension.class);
221+
ServiceLoader<SwaggerParserExtension> loader = ServiceLoader.load(SwaggerParserExtension.class, cl);
204222
Iterator<SwaggerParserExtension> itr = loader.iterator();
205223
while (itr.hasNext()) {
206224
extensions.add(itr.next());
207225
}
208-
extensions.add(0, new OpenAPIV3Parser());
209226
return extensions;
210227
}
211228

212-
/**
229+
/**
213230
* Transform the swagger-model version of AuthorizationValue into a parser-specific one, to avoid
214231
* dependencies across extensions
215232
*

0 commit comments

Comments
 (0)