Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,8 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
if (isAnExternalRefFormat(ref)) {
if (!ref.equals(RefFormat.URL)) {
String schemaFullRef = schema.get$ref();
String parent = (file.contains("/")) ? file.substring(0, file.lastIndexOf('/')) : "";
if (!parent.isEmpty() && !schemaFullRef.startsWith("/")) {
if (schemaFullRef.contains("#/")) {
String[] parts = schemaFullRef.split("#/");
String schemaFullRefFilePart = parts[0];
String schemaFullRefInternalRefPart = parts[1];
schemaFullRef = Paths.get(parent, schemaFullRefFilePart).normalize() + "#/" + schemaFullRefInternalRefPart;
} else {
schemaFullRef = Paths.get(parent, schemaFullRef).normalize().toString();
}
schemaFullRef = FilenameUtils.separatorsToUnix(schemaFullRef);
if (!schemaFullRef.startsWith("/")) {
schemaFullRef = join(file, schemaFullRef);
}
schema.set$ref(processRefToExternalSchema(schemaFullRef, ref));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.testng.Assert.*;
import static org.testng.Assert.assertEqualsNoOrder;


public class OpenAPIV3ParserTest {
Expand Down Expand Up @@ -562,6 +563,16 @@ public void testIssue1518StackOverFlow() {
}
}

@Test
public void testIssue1518NestedExternalRefs() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("issue-1518-nested-ref/api.yaml", null, options);
OpenAPI openAPI = result.getOpenAPI();
Set<String> schemaKeys = openAPI.getComponents().getSchemas().keySet();
assertEqualsNoOrder(schemaKeys, Arrays.asList("SharedModel", "shared-model", "Wrapper", "Leaf"));
}

@Test
public void testCantReadDeepProperties() {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
Expand Down Expand Up @@ -3292,7 +3303,7 @@ public void testIssue1886() {
OpenAPI openAPI = parseResult.getOpenAPI();
assertEqualsNoOrder(
openAPI.getComponents().getSchemas().keySet(),
Arrays.asList("ArrayPojo", "Enum1", "Enum1_1", "Enum2", "Enum3", "MapPojo", "SetPojo", "SimplePojo",
Arrays.asList("ArrayPojo", "Enum1", "Enum2", "Enum3", "MapPojo", "SetPojo", "SimplePojo",
"TransactionsPatchRequestBody", "additional-properties", "array-pojo", "locale-translation-item",
"map-pojo", "set-pojo", "simple-pojo", "translation-item")
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
openapi: 3.0.3
info:
title: Duplicate Schema Repro
version: 1.0.0

paths:
/shared-directly:
$ref: "./paths/direct.yaml"
/shared-nested:
$ref: "./paths/nested.yaml"

components:
schemas:
SharedModel:
$ref: "./schemas/shared-model.yaml"
Wrapper:
$ref: "./schemas/wrapper.yaml"
Leaf:
$ref: "./schemas/leaf.yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
get:
tags: [Repro]
operationId: getSharedDirectly
responses:
'200':
description: Path that returns the shared model directly.
content:
application/json:
schema:
$ref: "../api.yaml#/components/schemas/SharedModel"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
get:
tags: [Repro]
operationId: getSharedNested
responses:
'200':
description: Path that returns a wrapper whose items are the shared model.
content:
application/json:
schema:
$ref: "../api.yaml#/components/schemas/Wrapper"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: object
required:
- id
properties:
id:
type: string
format: uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type: object
required:
- name
- leaf
properties:
name:
type: string
leaf:
$ref: "../api.yaml#/components/schemas/Leaf"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type: object
required:
- items
properties:
items:
type: array
items:
$ref: "../api.yaml#/components/schemas/SharedModel"