Skip to content
Merged
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 @@ -109,12 +109,14 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
if (schema.get$ref() != null) {
RefFormat ref = computeRefFormat(schema.get$ref());
if (isAnExternalRefFormat(ref)) {
String schemaFullRef = schema.get$ref();
String parent = file.substring(0, file.lastIndexOf(File.separatorChar));
if (!parent.isEmpty()) {
schemaFullRef = Paths.get(parent, schemaFullRef).normalize().toString();
if (!ref.equals(RefFormat.URL)) {
String schemaFullRef = schema.get$ref();
String parent = file.substring(0, file.lastIndexOf(File.separatorChar));
if (!parent.isEmpty()) {
schemaFullRef = Paths.get(parent, schemaFullRef).normalize().toString();
}
schema.set$ref(processRefToExternalSchema(schemaFullRef, ref));
}
schema.set$ref(processRefToExternalSchema(schemaFullRef, ref));
} else {
processRefToExternalSchema(file + schema.get$ref(), RefFormat.RELATIVE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,30 @@ public class OpenAPIV3ParserTest {
protected int serverPort = getDynamicPort();
protected WireMockServer wireMockServer;

@Test
public void testIssue251() throws IOException {
String pathFile = FileUtils.readFileToString(new File("src/test/resources/domain.yaml"), "UTF-8");
WireMock.stubFor(get(urlPathMatching("/domain"))
.willReturn(aResponse()
.withStatus(HttpURLConnection.HTTP_OK)
.withHeader("Content-type", "application/json")
.withBody(pathFile
.getBytes(StandardCharsets.UTF_8))));

pathFile = FileUtils.readFileToString(new File("src/test/resources/issue251.yaml"), "UTF-8");
pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));

OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);

final SwaggerParseResult parseResult = parser.readContents(pathFile, null, options);

assertEquals(parseResult.getMessages().size(), 0);
assertTrue(parseResult.getOpenAPI().getComponents().getSchemas().size() == 2);
assertTrue(parseResult.getOpenAPI().getPaths().get("/parse").getGet().getParameters().get(0).getSchema().get$ref().equals("#/components/schemas/Parse"));
}

@Test
public void testCantReadDeepProperties() {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
Expand Down
15 changes: 15 additions & 0 deletions modules/swagger-parser-v3/src/test/resources/domain.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
openapi: 3.0.0
info:
title: Parser Test
version: '1.0'
components:
schemas:
Parse:
$ref: '#/components/schemas/ParseEnum'
ParseEnum:
title: Parse It
description: Can it parse it?
type: string
enum:
- Yes
- No
19 changes: 19 additions & 0 deletions modules/swagger-parser-v3/src/test/resources/issue251.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
openapi: 3.0.3
info:
version: "1.0.0"
title: parse-api
description: Test swagger-parser
paths:
/parse:
get:
description: Parser test
operationId: getParse
parameters:
- in: query
name: parse
required: true
schema:
$ref: 'http://localhost:${dynamicPort}/domain#/components/schemas/Parse'
responses:
'200':
description: OK