Skip to content

Commit 88c3d85

Browse files
committed
fix: examples not resolved when path parameter in reference chain (#2244)
1 parent 5625506 commit 88c3d85

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ private void processRefExamples(Map<String, Example> examples, String $ref) {
968968
if (example.get$ref() != null) {
969969
RefFormat ref = computeRefFormat(example.get$ref());
970970
if (isAnExternalRefFormat(ref)) {
971-
processRefExample(example, $ref);
971+
processRefExample(example, file);
972972
} else {
973973
processRefToExternalExample(file + example.get$ref(), RefFormat.RELATIVE);
974974
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,6 +3315,20 @@ public void testIssue2081() {
33153315
assertEquals(openAPI.getComponents().getSchemas().get("PetCreate").getProperties().size(), 2);
33163316
}
33173317

3318+
@Test(description = "should resolve nested referenced examples even when parent reference contains path parameter")
3319+
public void testIssue2244() {
3320+
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
3321+
ParseOptions options = new ParseOptions();
3322+
options.setResolve(true);
3323+
SwaggerParseResult parseResult = openApiParser.readLocation("issue-2244/openapi.yaml", null, options);
3324+
OpenAPI openAPI = parseResult.getOpenAPI();
3325+
3326+
assertNotNull(openAPI.getComponents().getExamples(), "should have resolved the component examples");
3327+
Set<String> exampleNames = new HashSet<>();
3328+
exampleNames.add("ReproducerExample");
3329+
assertEquals(openAPI.getComponents().getExamples().keySet(), exampleNames);
3330+
}
3331+
33183332
@Test(description = "responses should be inline")
33193333
public void testFullyResolveResponses() {
33203334
ParseOptions options = new ParseOptions();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
openapi: 3.0.3
2+
3+
components:
4+
schemas:
5+
ReproducerObject:
6+
type: object
7+
properties:
8+
id:
9+
type: integer
10+
examples:
11+
ReproducerExample:
12+
value:
13+
id: 1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
openapi: 3.0.3
2+
3+
info:
4+
title: Reproducer
5+
description: Reproducer for the issue
6+
version: 1.0.0
7+
8+
paths:
9+
/reproducers/{id}:
10+
$ref: "operations.yaml#/paths/~1reproducers~1{id}"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
openapi: 3.0.3
2+
3+
paths:
4+
/reproducers/{id}:
5+
post:
6+
description: Reproducer
7+
responses:
8+
"200":
9+
description: Success
10+
content:
11+
application/json:
12+
schema:
13+
$ref: "components.yaml#/components/schemas/ReproducerObject"
14+
examples:
15+
normal:
16+
$ref: "components.yaml#/components/examples/ReproducerExample"

0 commit comments

Comments
 (0)