Skip to content

Commit 5ba68ee

Browse files
committed
fix: examples not resolved when path parameter in reference chain (#2244)
1 parent 676c821 commit 5ba68ee

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
@@ -969,7 +969,7 @@ private void processRefExamples(Map<String, Example> examples, String $ref) {
969969
if (example.get$ref() != null) {
970970
RefFormat ref = computeRefFormat(example.get$ref());
971971
if (isAnExternalRefFormat(ref)) {
972-
processRefExample(example, $ref);
972+
processRefExample(example, file);
973973
} else {
974974
processRefToExternalExample(file + example.get$ref(), RefFormat.RELATIVE);
975975
}

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
@@ -3313,6 +3313,20 @@ public void testIssue2081() {
33133313
assertEquals(openAPI.getComponents().getSchemas().get("PetCreate").getProperties().size(), 2);
33143314
}
33153315

3316+
@Test(description = "should resolve nested referenced examples even when parent reference contains path parameter")
3317+
public void testIssue2244() {
3318+
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
3319+
ParseOptions options = new ParseOptions();
3320+
options.setResolve(true);
3321+
SwaggerParseResult parseResult = openApiParser.readLocation("issue-2244/openapi.yaml", null, options);
3322+
OpenAPI openAPI = parseResult.getOpenAPI();
3323+
3324+
assertNotNull(openAPI.getComponents().getExamples(), "should have resolved the component examples");
3325+
Set<String> exampleNames = new HashSet<>();
3326+
exampleNames.add("ReproducerExample");
3327+
assertEquals(openAPI.getComponents().getExamples().keySet(), exampleNames);
3328+
}
3329+
33163330
@Test(description = "responses should be inline")
33173331
public void testFullyResolveResponses() {
33183332
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)