Skip to content

Commit e3746af

Browse files
authored
Merge pull request #2064 from walaniam/issue_1886_202403
Issue 1886
2 parents 46e3ca9 + 5dc1cf1 commit e3746af

20 files changed

+1152
-1
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import io.swagger.v3.parser.ResolverCache;
3030
import io.swagger.v3.parser.models.RefFormat;
3131
import io.swagger.v3.parser.models.RefType;
32+
import org.apache.commons.io.FilenameUtils;
3233
import org.apache.commons.lang3.StringUtils;
3334
import org.slf4j.LoggerFactory;
3435

@@ -130,10 +131,11 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
130131
String[] parts = schemaFullRef.split("#/");
131132
String schemaFullRefFilePart = parts[0];
132133
String schemaFullRefInternalRefPart = parts[1];
133-
schemaFullRef = Paths.get(parent, schemaFullRefFilePart).normalize().toString() + "#/" + schemaFullRefInternalRefPart;
134+
schemaFullRef = Paths.get(parent, schemaFullRefFilePart).normalize() + "#/" + schemaFullRefInternalRefPart;
134135
} else {
135136
schemaFullRef = Paths.get(parent, schemaFullRef).normalize().toString();
136137
}
138+
schemaFullRef = FilenameUtils.separatorsToUnix(schemaFullRef);
137139
}
138140
schema.set$ref(processRefToExternalSchema(schemaFullRef, ref));
139141
}

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

+16
Original file line numberDiff line numberDiff line change
@@ -3269,4 +3269,20 @@ public void test31SafeURLResolvingWithLocalhost() {
32693269
}
32703270
}
32713271
}
3272+
3273+
@Test
3274+
public void testIssue1886() {
3275+
ParseOptions options = new ParseOptions();
3276+
options.setResolve(true);
3277+
options.setFlatten(true);
3278+
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
3279+
SwaggerParseResult parseResult = openApiParser.readLocation("issue-1886/openapi.yaml", null, options);
3280+
OpenAPI openAPI = parseResult.getOpenAPI();
3281+
assertEqualsNoOrder(
3282+
openAPI.getComponents().getSchemas().keySet(),
3283+
Arrays.asList("ArrayPojo", "Enum1", "Enum1_1", "Enum2", "Enum3", "MapPojo", "SetPojo", "SimplePojo",
3284+
"TransactionsPatchRequestBody", "additional-properties", "array-pojo", "locale-translation-item",
3285+
"map-pojo", "set-pojo", "simple-pojo", "translation-item")
3286+
);
3287+
}
32723288
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Enum1:
2+
$ref: schemas/enum1.yaml
3+
Enum2:
4+
type: string
5+
enum: [a, b, c]
6+
nullable: false
7+
Enum3:
8+
type: string
9+
enum: [x, y, z]
10+
nullable: true
11+
12+
SimplePojo:
13+
$ref: schemas/simple-pojo.yaml
14+
ArrayPojo:
15+
$ref: schemas/array-pojo.yaml
16+
MapPojo:
17+
$ref: schemas/map-pojo.yaml
18+
SetPojo:
19+
$ref: schemas/set-pojo.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
openapi: 3.0.3
2+
3+
info:
4+
title: Arrangement Support
5+
version: '1.0'
6+
7+
paths:
8+
/simple-types:
9+
$ref: paths/simple-types.yaml
10+
/simple-types/{id}/{ids}:
11+
$ref: paths/simple-types-ids.yaml
12+
/array-types:
13+
$ref: paths/array-types.yaml
14+
/array-types/{id}/{ids}:
15+
$ref: paths/array-types-ids.yaml
16+
/set-types:
17+
$ref: paths/set-types.yaml
18+
/set-types/{id}/{ids}:
19+
$ref: paths/set-types-ids.yaml
20+
/map-types:
21+
$ref: paths/map-types.yaml
22+
/map-types/{id}/{ids}:
23+
$ref: paths/map-types-ids.yaml
24+
/transactions:
25+
patch:
26+
tags:
27+
- transactions
28+
summary: patch
29+
description: Updates list of transactions
30+
operationId: patchTransactions
31+
requestBody:
32+
description: Updates list of transactions
33+
content:
34+
application/json:
35+
schema:
36+
type: array
37+
items:
38+
$ref: '#/components/schemas/TransactionsPatchRequestBody'
39+
responses:
40+
"204":
41+
description: OK
42+
43+
components:
44+
schemas:
45+
TransactionsPatchRequestBody:
46+
required:
47+
- id
48+
type: object
49+
properties:
50+
id:
51+
maxLength: 300
52+
type: string
53+
description: Unique identification for the transaction as used in the external
54+
system
55+
arrangementId:
56+
maxLength: 50
57+
type: string
58+
description: An external reference to the arrangement the transaction belongs
59+
to
60+
category:
61+
maxLength: 50
62+
type: string
63+
description: Transaction category
64+
billingStatus:
65+
maxLength: 8
66+
type: string
67+
creationTime:
68+
type: string
69+
format: date-time
70+
x-java-type: java.time.OffsetDateTime
71+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
parameters:
2+
- name: id
3+
required: true
4+
in: path
5+
schema:
6+
type: string
7+
minLength: 1
8+
maxLength: 36
9+
pattern: '^[A-Z]+$'
10+
- name: ids
11+
in: path
12+
required: true
13+
schema:
14+
type: array
15+
items:
16+
type: string
17+
minLength: 1
18+
maxLength: 36
19+
pattern: '^[A-Z]+$'
20+
delete:
21+
tags:
22+
- array-types
23+
x-content-language: application/json
24+
requestBody:
25+
required: true
26+
content:
27+
application/json:
28+
schema:
29+
type: array
30+
items:
31+
$ref: '../components.yaml#/ArrayPojo'
32+
responses:
33+
200:
34+
description: OK
35+
content:
36+
application/json:
37+
schema:
38+
type: array
39+
items:
40+
$ref: '../components.yaml#/ArrayPojo'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
get:
2+
tags:
3+
- array-types
4+
x-content-language: application/json
5+
parameters:
6+
- name: h-param
7+
in: header
8+
schema:
9+
type: string
10+
minLength: 1
11+
maxLength: 36
12+
pattern: '^[A-Z]+$'
13+
- name: h-params
14+
in: header
15+
schema:
16+
type: array
17+
items:
18+
type: string
19+
minLength: 1
20+
maxLength: 36
21+
pattern: '^[A-Z]+$'
22+
- name: c-param
23+
in: cookie
24+
schema:
25+
type: string
26+
minLength: 1
27+
maxLength: 36
28+
pattern: '^[A-Z]+$'
29+
- name: c-params
30+
in: cookie
31+
schema:
32+
type: array
33+
items:
34+
type: string
35+
minLength: 1
36+
maxLength: 36
37+
pattern: '^[A-Z]+$'
38+
- name: q-param
39+
in: query
40+
required: false
41+
schema:
42+
type: string
43+
minLength: 1
44+
maxLength: 36
45+
pattern: '^[A-Z]+$'
46+
- name: q-param-enum
47+
in: query
48+
required: false
49+
schema:
50+
$ref: '../components.yaml#/Enum1'
51+
- name: q-param-req
52+
in: query
53+
required: true
54+
schema:
55+
type: string
56+
minLength: 1
57+
maxLength: 36
58+
pattern: '^[A-Z]+$'
59+
- name: q-param-enum-req
60+
in: query
61+
required: true
62+
schema:
63+
$ref: '../components.yaml#/Enum2'
64+
- name: q-params
65+
in: query
66+
schema:
67+
type: array
68+
items:
69+
type: string
70+
minLength: 1
71+
maxLength: 36
72+
pattern: '^[A-Z]+$'
73+
- name: q-params-enum
74+
in: query
75+
schema:
76+
type: array
77+
items:
78+
$ref: '../components.yaml#/Enum3'
79+
- name: q-params-req
80+
in: query
81+
required: true
82+
schema:
83+
type: array
84+
items:
85+
type: string
86+
minLength: 1
87+
maxLength: 36
88+
pattern: '^[A-Z]+$'
89+
- name: q-params-set
90+
in: query
91+
required: false
92+
schema:
93+
type: array
94+
uniqueItems: true
95+
items:
96+
type: string
97+
minLength: 1
98+
maxLength: 36
99+
pattern: '^[A-Z]+$'
100+
- name: q-params-set-req
101+
in: query
102+
required: true
103+
schema:
104+
type: array
105+
uniqueItems: true
106+
items:
107+
type: string
108+
minLength: 1
109+
maxLength: 36
110+
pattern: '^[A-Z]+$'
111+
responses:
112+
200:
113+
description: OK
114+
content:
115+
application/json:
116+
schema:
117+
$ref: '../components.yaml#/ArrayPojo'
118+
post:
119+
tags:
120+
- array-types
121+
x-content-language: application/json
122+
requestBody:
123+
required: true
124+
content:
125+
application/json:
126+
schema:
127+
$ref: '../components.yaml#/ArrayPojo'
128+
responses:
129+
200:
130+
description: OK
131+
content:
132+
application/json:
133+
schema:
134+
$ref: '../components.yaml#/ArrayPojo'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
parameters:
2+
- name: id
3+
required: true
4+
in: path
5+
schema:
6+
type: string
7+
minLength: 1
8+
maxLength: 36
9+
pattern: '^[A-Z]+$'
10+
- name: ids
11+
in: path
12+
required: true
13+
schema:
14+
type: array
15+
items:
16+
type: string
17+
minLength: 1
18+
maxLength: 36
19+
pattern: '^[A-Z]+$'
20+
delete:
21+
tags:
22+
- simple-types
23+
x-content-language: application/json
24+
requestBody:
25+
required: true
26+
content:
27+
application/json:
28+
schema:
29+
type: array
30+
items:
31+
$ref: '../components.yaml#/SimplePojo'
32+
responses:
33+
200:
34+
description: OK
35+
content:
36+
application/json:
37+
schema:
38+
type: array
39+
items:
40+
$ref: '../components.yaml#/SimplePojo'

0 commit comments

Comments
 (0)