Skip to content

Commit ef1b987

Browse files
Fix the issue of not merging the extensions in allOf
1 parent 1f0ff86 commit ef1b987

File tree

4 files changed

+79
-3
lines changed

4 files changed

+79
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,10 @@ private void aggregateSchemaCombinators(ComposedSchema sourceSchema, Schema targ
496496
if (resolved.getExample() != null) {
497497
examples.add(resolved.getExample());
498498
}
499-
if (sourceSchema.getExtensions() != null) {
500-
Map<String, Object> extensions = sourceSchema.getExtensions();
499+
if (resolved.getExtensions() != null) {
500+
Map<String, Object> extensions = resolved.getExtensions();
501501
for (String key : extensions.keySet()) {
502-
targetSchema.addExtension(key, sourceSchema.getExtensions().get(key));
502+
targetSchema.addExtension(key, extensions.get(key));
503503
}
504504
}
505505
}

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
@@ -2994,6 +2994,18 @@ public void testIssue1592() throws Exception {
29942994
assertNotNull(openAPI);
29952995
}
29962996

2997+
@Test
2998+
public void testIssue1266() throws Exception{
2999+
String yamlString = FileUtils.readFileToString(new File("src/test/resources/issue-1266/issue-1266.yaml"), "UTF-8");
3000+
String yamlStringResolved = FileUtils.readFileToString(new File("src/test/resources/issue-1266/issue-1266-resolved.yaml"), "UTF-8");
3001+
ParseOptions options = new ParseOptions();
3002+
options.setResolveFully(true);
3003+
options.setResolveCombinators(true);
3004+
OpenAPI openAPI = new OpenAPIV3Parser().readContents(yamlString, null, options).getOpenAPI();
3005+
Assert.assertNotNull(openAPI);
3006+
assertEquals(Yaml.pretty(openAPI), yamlStringResolved);
3007+
}
3008+
29973009
@Test(description = "option true, adds Original Location to messages when ref is relative/local")
29983010
public void testValidateExternalRefsTrue() {
29993011
ParseOptions options = new ParseOptions();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
openapi: 3.0.2
2+
info:
3+
title: Extension not inherited
4+
version: "1"
5+
servers:
6+
- url: /
7+
paths:
8+
/test/extensions/not/inherited:
9+
get:
10+
responses:
11+
"200":
12+
description: A test failing on the merge of extensions in a allOf
13+
content:
14+
application/json:
15+
schema:
16+
required:
17+
- data
18+
properties:
19+
data:
20+
type: string
21+
data2:
22+
type: string
23+
x-extension-ref: 1
24+
components:
25+
schemas:
26+
ResponseModel:
27+
required:
28+
- data
29+
type: object
30+
properties:
31+
data:
32+
type: string
33+
x-extension-ref: 1
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
openapi: "3.0.2"
2+
info:
3+
version: "1"
4+
title: "Extension not inherited"
5+
6+
components:
7+
schemas:
8+
ResponseModel:
9+
x-extension-ref: 1
10+
type: object
11+
required:
12+
- data
13+
properties:
14+
data:
15+
type: "string"
16+
17+
paths:
18+
/test/extensions/not/inherited:
19+
get:
20+
responses:
21+
200:
22+
description: "A test failing on the merge of extensions in a allOf"
23+
content:
24+
application/json:
25+
schema:
26+
allOf:
27+
- $ref: "#/components/schemas/ResponseModel"
28+
- type: "object"
29+
properties:
30+
data2:
31+
type: "string"

0 commit comments

Comments
 (0)