Skip to content

Commit 2292e45

Browse files
authored
Merge pull request #1353 from kerrykimbrough/issue-1352
ResolverFully: Ensure any header schema $ref is resolved
2 parents a95f13b + ce8874a commit 2292e45

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ private void resolveHeaders(Map<String, Header> headers) {
217217
Map<String,Example> resolved = resolveExample(examples);
218218
resolvedValue.setExamples(resolved);
219219
}
220+
Schema schema = resolvedValue.getSchema();
221+
if(schema != null) {
222+
Schema resolvedSchema = resolveSchema( schema);
223+
if(resolvedSchema != null) {
224+
resolvedValue.setSchema( resolvedSchema);
225+
}
226+
}
220227
header.setValue(resolvedValue);
221228
}
222229
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,17 @@ public void testIssue85(@Injectable final List<AuthorizationValue> auths) {
492492
assertTrue(prop instanceof Schema);
493493
}
494494

495+
@Test
496+
public void testIssue1352(@Injectable final List<AuthorizationValue> auths) {
497+
ParseOptions options = new ParseOptions();
498+
options.setResolve(true);
499+
options.setResolveFully(true);
500+
501+
OpenAPI openAPI= new OpenAPIV3Parser().readLocation("issue-1352.json", auths, options).getOpenAPI();
502+
assertNull(openAPI.getPaths().get("/responses").getPatch().getResponses().get("200").getHeaders().get("x-my-secret-header").getSchema().get$ref());
503+
504+
}
505+
495506
@Test
496507
public void testIssue1157(@Injectable final List<AuthorizationValue> auths) {
497508
ParseOptions options = new ParseOptions();
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"title": "Responses",
5+
"version": "0.0.0"
6+
},
7+
"paths": {
8+
"/responses": {
9+
"patch": {
10+
"responses": {
11+
"200": {
12+
"description": "It's a secret",
13+
"headers": {
14+
"x-my-secret-header": {
15+
"required": true,
16+
"schema": {
17+
"$ref": "#/components/schemas/secrets"
18+
}
19+
}
20+
},
21+
"content": {
22+
"application/json": {
23+
"schema": {
24+
"type": "object",
25+
"maxProperties": 1,
26+
"additionalProperties": {
27+
"type": "number"
28+
}
29+
}
30+
},
31+
"text/javascript": {
32+
"schema": {
33+
"type": "object",
34+
"minProperties": 1,
35+
"additionalProperties": {
36+
"type": "boolean"
37+
}
38+
}
39+
}
40+
}
41+
},
42+
"4XX": {
43+
"$ref": "#/components/responses/failure"
44+
}
45+
}
46+
}
47+
}
48+
},
49+
"components": {
50+
"responses": {
51+
"success": {
52+
"description": "Success",
53+
"content": {
54+
"application/json": {
55+
"schema": {
56+
"$ref": "#/components/schemas/successContent"
57+
}
58+
}
59+
}
60+
},
61+
"failure": {
62+
"description": "Error",
63+
"content": {
64+
"application/json": {
65+
"schema": {
66+
"type": "object"
67+
}
68+
}
69+
}
70+
}
71+
},
72+
"schemas": {
73+
"secrets": {
74+
"type": "array",
75+
"items": {
76+
"type": "integer",
77+
"format": "int64"
78+
}
79+
}
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)