Skip to content

Commit 2fcf4fd

Browse files
committed
fix for issue 1169 that works without explicit separators
1 parent 9370bca commit 2fcf4fd

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,12 @@ public Paths getPaths(ObjectNode obj, String location, ParseResult result) {
621621
}
622622
ObjectNode path = (ObjectNode) pathValue;
623623
PathItem pathObj = getPathItem(path, String.format("%s.'%s'", location, pathName), result);
624-
String[] eachPart = pathName.split("[-/.]+");
625-
Arrays.stream(eachPart)
626-
.filter(part -> part.startsWith("{") && part.endsWith("}") && part.length() > 2)
624+
List<String> eachPart = new ArrayList<>();
625+
Matcher m = Pattern.compile("\\{(.+?)\\}").matcher(pathName);
626+
while (m.find()) {
627+
eachPart.add(m.group());
628+
}
629+
eachPart.stream()
627630
.forEach(part -> {
628631
String pathParam = part.substring(1, part.length() - 1);
629632
boolean definedInPathLevel = isPathParamDefined(pathParam,

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,18 @@ public void testIssue1169() {
806806
assertNotNull(apispec);
807807
}
808808

809+
@Test
810+
public void testIssue1169noSplit() {
811+
ParseOptions options = new ParseOptions();
812+
options.setResolve(true);
813+
SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("issue1169.yaml", null, options);
814+
assertTrue(parseResult.getMessages().size() == 0);
815+
OpenAPI apispec = parseResult.getOpenAPI();
816+
assertNotNull(apispec);
817+
}
818+
819+
820+
809821
@Test
810822
public void testIssue339() throws Exception {
811823
OpenAPIV3Parser openAPIV3Parser = new OpenAPIV3Parser();
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: {}

0 commit comments

Comments
 (0)