Skip to content

Commit e3ff07d

Browse files
committed
refs #1266 - handle overridden extensions
1 parent f6270d5 commit e3ff07d

File tree

3 files changed

+93
-5
lines changed

3 files changed

+93
-5
lines changed

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

+10-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public ResolverFully(boolean aggregateCombinators) {
5656
private Map<String, Link> links;
5757
private Map<String, Schema> resolvedProperties = new IdentityHashMap<>();
5858
private Map<String, Callback> callbacks;
59-
59+
6060
public void resolveFully(OpenAPI openAPI) {
6161
Components components = openAPI.getComponents();
6262
if (components != null && components.getRequestBodies() != null) {
@@ -85,7 +85,7 @@ public void resolveFully(OpenAPI openAPI) {
8585
if (headers == null) {
8686
headers = new HashMap<>();
8787
}
88-
}
88+
}
8989

9090
if (components != null && components.getParameters() != null) {
9191
parameters = components.getParameters();
@@ -243,7 +243,7 @@ public Header resolveHeader(Header header){
243243
}
244244
return header;
245245
}
246-
246+
247247
public Link resolveLink(Link link){
248248
RefFormat refFormat = computeRefFormat(link.get$ref());
249249
String $ref = link.get$ref();
@@ -272,7 +272,7 @@ public RequestBody resolveRequestBody(RequestBody requestBody){
272272
}
273273
return requestBody;
274274
}
275-
275+
276276
public Callback resolveCallback(Callback callback){
277277
RefFormat refFormat = computeRefFormat(callback.get$ref());
278278
String $ref = callback.get$ref();
@@ -502,6 +502,12 @@ private void aggregateSchemaCombinators(ComposedSchema sourceSchema, Schema targ
502502
targetSchema.addExtension(key, extensions.get(key));
503503
}
504504
}
505+
if (sourceSchema.getExtensions() != null) {
506+
Map<String, Object> extensions = sourceSchema.getExtensions();
507+
for (String key : extensions.keySet()) {
508+
targetSchema.addExtension(key, sourceSchema.getExtensions().get(key));
509+
}
510+
}
505511
}
506512

507513
if (requiredProperties.size() > 0) {

modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266-resolved.yaml

+47
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,42 @@ paths:
2121
data2:
2222
type: string
2323
x-extension-ref: 1
24+
/test/extensions/not/inherited/bothinline:
25+
get:
26+
responses:
27+
"200":
28+
description: "A test failing on the merge of extensions in a allOf, with\
29+
\ same extension defined in referencing and referenced"
30+
content:
31+
application/json:
32+
schema:
33+
required:
34+
- data
35+
properties:
36+
data:
37+
type: string
38+
data2:
39+
type: string
40+
x-extension-ref: 3
41+
/test/extensions/not/inherited/both:
42+
get:
43+
responses:
44+
"200":
45+
description: "A test failing on the merge of extensions in a allOf, with\
46+
\ same extension defined in referencing and referenced"
47+
content:
48+
application/json:
49+
schema:
50+
required:
51+
- data
52+
- gps
53+
type: object
54+
properties:
55+
data:
56+
type: string
57+
gps:
58+
type: string
59+
x-extension-ref: 2
2460
components:
2561
schemas:
2662
ResponseModel:
@@ -31,3 +67,14 @@ components:
3167
data:
3268
type: string
3369
x-extension-ref: 1
70+
ExtendedResponseModel:
71+
required:
72+
- data
73+
- gps
74+
type: object
75+
properties:
76+
data:
77+
type: string
78+
gps:
79+
type: string
80+
x-extension-ref: 2

modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266.yaml

+36-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ components:
1313
properties:
1414
data:
1515
type: "string"
16+
ExtendedResponseModel:
17+
type: object
18+
x-extension-ref: 2
19+
allOf:
20+
- $ref: '#/components/schemas/ResponseModel'
21+
- type: object
22+
required:
23+
- gps
24+
properties:
25+
gps:
26+
type: string
1627

1728
paths:
1829
/test/extensions/not/inherited:
@@ -28,4 +39,28 @@ paths:
2839
- type: "object"
2940
properties:
3041
data2:
31-
type: "string"
42+
type: "string"
43+
/test/extensions/not/inherited/bothinline:
44+
get:
45+
responses:
46+
200:
47+
description: "A test failing on the merge of extensions in a allOf, with same extension defined in referencing and referenced"
48+
content:
49+
application/json:
50+
schema:
51+
allOf:
52+
- $ref: "#/components/schemas/ResponseModel"
53+
- type: "object"
54+
x-extension-ref: 3
55+
properties:
56+
data2:
57+
type: "string"
58+
/test/extensions/not/inherited/both:
59+
get:
60+
responses:
61+
200:
62+
description: "A test failing on the merge of extensions in a allOf, with same extension defined in referencing and referenced"
63+
content:
64+
application/json:
65+
schema:
66+
$ref: "#/components/schemas/ExtendedResponseModel"

0 commit comments

Comments
 (0)