Skip to content

Commit 8152ae4

Browse files
authored
Merge pull request #2 from swagger-api/master
Pull changes from master
2 parents 5684579 + 737e881 commit 8152ae4

File tree

7 files changed

+174
-6
lines changed

7 files changed

+174
-6
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import io.swagger.parser.SwaggerResolver;
3333
import io.swagger.parser.util.SwaggerDeserializationResult;
3434
import io.swagger.v3.core.util.Json;
35+
import io.swagger.v3.core.util.PrimitiveType;
3536
import io.swagger.v3.oas.models.Components;
3637
import io.swagger.v3.oas.models.ExternalDocumentation;
3738
import io.swagger.v3.oas.models.OpenAPI;
@@ -692,9 +693,20 @@ private Schema convert(SerializableParameter sp) {
692693
}
693694
schema = as;
694695
} else {
695-
schema = new Schema();
696-
schema.setType(sp.getType());
697-
schema.setFormat(sp.getFormat());
696+
PrimitiveType ptype = PrimitiveType.fromTypeAndFormat(sp.getType(), sp.getFormat());
697+
if (ptype != null) {
698+
schema = ptype.createProperty();
699+
} else {
700+
ptype = PrimitiveType.fromTypeAndFormat(sp.getType(), null);
701+
if (ptype != null) {
702+
schema = ptype.createProperty();
703+
schema.setFormat(sp.getFormat());
704+
} else {
705+
schema = new Schema();
706+
schema.setType(sp.getType());
707+
schema.setFormat(sp.getFormat());
708+
}
709+
}
698710
}
699711

700712
schema.setDescription(sp.getDescription());

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import io.swagger.v3.oas.models.headers.Header;
88
import io.swagger.v3.oas.models.info.Info;
99
import io.swagger.v3.oas.models.media.ArraySchema;
10+
import io.swagger.v3.oas.models.media.BooleanSchema;
1011
import io.swagger.v3.oas.models.media.ComposedSchema;
1112
import io.swagger.v3.oas.models.media.IntegerSchema;
13+
import io.swagger.v3.oas.models.media.StringSchema;
1214
import io.swagger.v3.oas.models.media.Schema;
1315
import io.swagger.v3.oas.models.parameters.Parameter;
1416
import io.swagger.v3.oas.models.parameters.RequestBody;
@@ -91,6 +93,7 @@ public class V2ConverterTest {
9193
private static final String ISSUE_820_YAML = "issue-820.yaml";
9294
private static final String ISSUE_1032_YAML = "issue-1032.yaml";
9395
private static final String ISSUE_1113_YAML = "issue-1113.yaml";
96+
private static final String ISSUE_1164_YAML = "issue-1164.yaml";
9497

9598
private static final String API_BATCH_PATH = "/api/batch/";
9699
private static final String PETS_PATH = "/pets";
@@ -790,7 +793,37 @@ public void testIssue1113() throws Exception {
790793
assertNotNull(oas.getServers().get(0));
791794
assertEquals(oas.getServers().get(0).getUrl(), "/test");
792795
}
793-
796+
797+
@Test(description = "OpenAPI v2 converter - uses specialized schema subclasses where available")
798+
public void testIssue1164() throws Exception {
799+
final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1164_YAML);
800+
assertNotNull(oas);
801+
assertNotNull(oas.getPaths());
802+
assertNotNull(oas.getPaths().get("/foo"));
803+
assertNotNull(oas.getPaths().get("/foo").getGet());
804+
assertNotNull(oas.getPaths().get("/foo").getGet().getRequestBody());
805+
assertNotNull(oas.getPaths().get("/foo").getGet().getRequestBody().getContent());
806+
assertNotNull(oas.getPaths().get("/foo").getGet().getRequestBody().getContent().get("multipart/form-data"));
807+
Schema formSchema = oas.getPaths().get("/foo").getGet().getRequestBody().getContent().get("multipart/form-data").getSchema();
808+
assertNotNull(formSchema);
809+
assertNotNull(formSchema.getProperties());
810+
assertEquals(4, formSchema.getProperties().size());
811+
assertTrue(formSchema.getProperties().get("first") instanceof StringSchema);
812+
813+
assertTrue(formSchema.getProperties().get("second") instanceof BooleanSchema);
814+
815+
assertTrue(formSchema.getProperties().get("third") instanceof StringSchema);
816+
StringSchema third = (StringSchema) formSchema.getProperties().get("third");
817+
assertNotNull(third.getFormat());
818+
assertTrue("password".equals(third.getFormat()));
819+
820+
assertTrue(formSchema.getProperties().get("fourth") instanceof BooleanSchema);
821+
Schema fourth = (Schema) formSchema.getProperties().get("fourth");
822+
assertNotNull(fourth.getType());
823+
assertNotNull(fourth.getFormat());
824+
assertTrue("completely-custom".equals(fourth.getFormat()));
825+
}
826+
794827
private OpenAPI getConvertedOpenAPIFromJsonFile(String file) throws IOException, URISyntaxException {
795828
SwaggerConverter converter = new SwaggerConverter();
796829
String swaggerAsString = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource(file).toURI())));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
swagger: '2.0'
2+
info:
3+
title: Test for Issue 1164
4+
version: 1.0.0
5+
paths:
6+
/foo:
7+
get:
8+
operationId: doFoo
9+
parameters:
10+
- in: formData
11+
name: first
12+
type: string
13+
required: true
14+
- in: formData
15+
name: second
16+
type: boolean
17+
required: true
18+
- in: formData
19+
name: third
20+
type: string
21+
format: password
22+
required: true
23+
- in: formData
24+
name: fourth
25+
type: boolean
26+
format: completely-custom
27+
required: true
28+
responses:
29+
'200':
30+
description: OK

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ public Paths getPaths(ObjectNode obj, String location, ParseResult result) {
546546
}
547547
ObjectNode path = (ObjectNode) pathValue;
548548
PathItem pathObj = getPathItem(path,String.format("%s.'%s'", location,pathName), result);
549-
String[] eachPart = pathName.split("/");
549+
String[] eachPart = pathName.split("[-/.]+");
550550
Arrays.stream(eachPart)
551551
.filter(part -> part.startsWith("{") && part.endsWith("}") && part.length() > 2)
552552
.forEach(part -> {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ public class OpenAPIV3ParserTest {
6767
protected WireMockServer wireMockServer;
6868

6969

70+
@Test
71+
public void testIssue1169() {
72+
ParseOptions options = new ParseOptions();
73+
options.setResolve(true);
74+
SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("issue1169.yaml", null, options);
75+
assertTrue(parseResult.getMessages().size() == 0);
76+
OpenAPI apispec = parseResult.getOpenAPI();
77+
assertNotNull(apispec);
78+
}
79+
7080

7181
@Test
7282
public void testIssue339() throws Exception {
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
openapi: 3.0.0
3+
servers:
4+
- description: Production
5+
url: https://apps.gov.bc.ca/pub/bcgnws
6+
- description: Test
7+
url: https://test.apps.gov.bc.ca/pub/bcgnws
8+
- description: Delivery
9+
url: https://delivery.apps.gov.bc.ca/pub/bcgnws
10+
info:
11+
contact:
12+
13+
name: BC Geographical Names Office
14+
url: https://www2.gov.bc.ca/gov/content?id=A3C60F17CE934B1ABFA366F28C66E370
15+
description: "This REST API provides searchable access to information about geographical
16+
names in the province of British Columbia, including name status and details about
17+
the corresponding geographic feature. \n\nPlease note that you may experience
18+
issues when submitting requests to the delivery or test environment if using this
19+
[OpenAPI specification](https://github.com/bcgov/api-specs) in other API console
20+
viewers."
21+
license:
22+
name: Crown Copyright
23+
url: https://www2.gov.bc.ca/gov/content?id=1AAACC9C65754E4D89A118B875E0FBDA
24+
title: BC Geographical Names Web Service -
25+
version: 3.x.x
26+
x-apisguru-categories:
27+
- open_data
28+
x-logo:
29+
url: https://api.apis.guru/v2/cache/logo/https_avatars1.githubusercontent.com_u_916280.jpeg
30+
x-origin:
31+
- converter:
32+
url: https://github.com/lucybot/api-spec-converter
33+
version: 2.7.31
34+
format: openapi
35+
url: https://raw.githubusercontent.com/bcgov/api-specs/master/bcgnws/bcgnws.json
36+
version: '3.0'
37+
x-preferred: true
38+
x-providerName: gov.bc.ca
39+
x-serviceName: bcgnws
40+
tags:
41+
- name: search
42+
- name: name
43+
- name: feature
44+
- name: feature taxonomy
45+
- name: name authority
46+
paths:
47+
"/names/{nameId}.{outputFormat}":
48+
get:
49+
description: Get information about the geographical name with the specified
50+
nameId.
51+
parameters:
52+
- description: The unique identifier for a name
53+
example: 22474
54+
in: path
55+
name: nameId
56+
required: true
57+
schema:
58+
type: integer
59+
- description: The format of the output.
60+
example: json
61+
in: path
62+
name: outputFormat
63+
required: true
64+
schema:
65+
default: json
66+
enum:
67+
- json
68+
- xml
69+
- kml
70+
- csv
71+
- html
72+
type: string
73+
responses:
74+
'200':
75+
description: Information about the name with the specified nameId
76+
'404':
77+
description: The name with the given nameId doesn't exist, or the output
78+
format is invalid.
79+
summary: Get a name by its nameId
80+
tags:
81+
- name
82+
components:
83+
schemas: {}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@
287287
<properties>
288288
<swagger-parser-v2-version>1.0.46-SNAPSHOT</swagger-parser-v2-version>
289289
<commons-io-version>2.4</commons-io-version>
290-
<slf4j-version>1.6.3</slf4j-version>
290+
<slf4j-version>1.7.28</slf4j-version>
291291
<swagger-core-version>2.0.9-SNAPSHOT</swagger-core-version>
292292
<junit-version>4.8.1</junit-version>
293293
<testng-version>6.14.2</testng-version>

0 commit comments

Comments
 (0)