Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when the same component used in two different places in two different apis then parser fails #1627

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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 @@ -569,6 +569,52 @@ public void testIssueSameRefsDifferentModelValid() {
assertEquals(openAPI.getMessages().size(), 0);
}

@Test
public void testSameComponentInRequestAndResponseHeaders() throws IOException {
String pathFile = FileUtils.readFileToString(new File("src/test/resources/same-header-different-place-domain.yaml"), "UTF-8");
WireMock.stubFor(get(urlPathMatching("/issue-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/same-header-different-place.yaml"), "UTF-8");
pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));

OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
final SwaggerParseResult openAPI = parser.readContents(pathFile, null, options);
Yaml.prettyPrint(openAPI);

assertEquals(openAPI.getMessages().size(), 0);
}

@Test
public void testSameComponentInRequestAndResponseHeadersValid() throws IOException {
String pathFile = FileUtils.readFileToString(new File("src/test/resources/same-header-different-place-domain.yaml"), "UTF-8");
WireMock.stubFor(get(urlPathMatching("/issue-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/same-header-different-place-valid.yaml"), "UTF-8");
pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));

OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
final SwaggerParseResult openAPI = parser.readContents(pathFile, null, options);
Yaml.prettyPrint(openAPI);

assertEquals(openAPI.getMessages().size(), 0);
}

@Test
public void testIssue1398() {
ParseOptions options = new ParseOptions();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
openapi: 3.0.0

components:
parameters:
testHeader:
name: testHeader
in: header
schema:
type: string

anotherHeader:
name: testHeader
in: header
schema:
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
openapi: 3.0.0
info:
version: "1.0.0"
title: Simple Inventory API
paths:
/api:
get:
parameters:
- $ref: 'http://localhost:${dynamicPort}/issue-domain/#/components/parameters/testHeader'
responses:
'200':
description: yet another success
headers:
testHeader:
$ref: 'http://localhost:${dynamicPort}/issue-domain/#/components/parameters/anotherHeader'
/api2:
get:
parameters:
- $ref: 'http://localhost:${dynamicPort}/issue-domain/#/components/parameters/testHeader'
responses:
'200':
description: yet another success
headers:
testHeader:
$ref: 'http://localhost:${dynamicPort}/issue-domain/#/components/parameters/testHeader'
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
openapi: 3.0.0
info:
version: "1.0.0"
title: Simple Inventory API
paths:
/api:
get:
parameters:
- $ref: 'http://localhost:${dynamicPort}/issue-domain/#/components/parameters/testHeader'
responses:
'200':
description: yet another success
headers:
testHeader:
$ref: 'http://localhost:${dynamicPort}/issue-domain/#/components/parameters/testHeader'
/api2:
get:
parameters:
- $ref: 'http://localhost:${dynamicPort}/issue-domain/#/components/parameters/testHeader'
responses:
'200':
description: yet another success
headers:
testHeader:
$ref: 'http://localhost:${dynamicPort}/issue-domain/#/components/parameters/testHeader'
Loading