Skip to content

Commit 1670890

Browse files
authored
Merge pull request #1681 from jbbenoist/issue#1266
Fix the issue of not merging the extensions in allOf
2 parents 46b522f + c7bd8fb commit 1670890

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
@@ -3021,6 +3021,18 @@ public void testIssue1592() throws Exception {
30213021
assertNotNull(openAPI);
30223022
}
30233023

3024+
@Test
3025+
public void testIssue1266() throws Exception{
3026+
String yamlString = FileUtils.readFileToString(new File("src/test/resources/issue-1266/issue-1266.yaml"), "UTF-8");
3027+
String yamlStringResolved = FileUtils.readFileToString(new File("src/test/resources/issue-1266/issue-1266-resolved.yaml"), "UTF-8");
3028+
ParseOptions options = new ParseOptions();
3029+
options.setResolveFully(true);
3030+
options.setResolveCombinators(true);
3031+
OpenAPI openAPI = new OpenAPIV3Parser().readContents(yamlString, null, options).getOpenAPI();
3032+
Assert.assertNotNull(openAPI);
3033+
assertEquals(Yaml.pretty(openAPI), yamlStringResolved);
3034+
}
3035+
30243036
@Test(description = "option true, adds Original Location to messages when ref is relative/local")
30253037
public void testValidateExternalRefsTrue() {
30263038
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)