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 @@ -4,6 +4,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.parser.core.models.AuthorizationValue;
import io.swagger.v3.parser.models.RefFormat;
Expand Down Expand Up @@ -165,6 +166,12 @@ protected <T> void updateLocalRefs(String file, T result) {
}
}
}
if(result instanceof Parameter){
Parameter parameter = (Parameter)result;
if (parameter.getSchema() != null){
updateLocalRefs(file,parameter.getSchema());
}
}
if(result instanceof Schema && ((Schema)(result)).get$ref() != null) {
Schema prop = (Schema) result;
updateLocalRefs(file, prop);
Expand Down Expand Up @@ -194,11 +201,12 @@ protected String merge(String host, String ref) {
if(StringUtils.isBlank(host)) {
return ref;
}

if(ref.startsWith("http:") || ref.startsWith("https:")) {
// already an absolute ref
return ref;
}
if(!host.startsWith("http:") && !host.startsWith("https:")) {
if(!host.startsWith("http:") && !host.startsWith("https:") && !ref.startsWith("#/components")) {
return ref;
}
if(ref.startsWith(".")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public class OpenAPIV3ParserTest {
protected int serverPort = getDynamicPort();
protected WireMockServer wireMockServer;

@Test
public void testIssue983() {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
final OpenAPI openAPI = parser.readLocation("issue-983.yaml", null, options).getOpenAPI();
Assert.assertNotNull(openAPI);
Yaml.prettyPrint(openAPI);
Assert.assertNotNull(openAPI.getComponents().getSchemas().get("InventoryId"));

}


@Test
public void testIssue913() {
Expand Down
32 changes: 32 additions & 0 deletions modules/swagger-parser-v3/src/test/resources/issue-983-domain.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
openapi: 3.0.0

info:
title: Sample-Domain
description: 'Reusable components for the Notification domain.'
contact:
url: https://www.url.com/
email: url.api.support@url.com
license:
name: Sample
version: "1.0.0"

paths:
/na-domain-only:
summary: n/a
description: n/a


components:
schemas:
InventoryId:
description: 'Key information uniquely identifying a inventory. May be a composite of information'
type: string

parameters:
inventory-id:
in: path
name: inventory-id
description: 'Could be composite key'
required: true
schema:
$ref: '#/components/schemas/InventoryId'
37 changes: 37 additions & 0 deletions modules/swagger-parser-v3/src/test/resources/issue-983.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
openapi: 3.0.0
servers: []
info:
description: This is a simple API
version: "1.0.0"
title: Simple Inventory API
contact:
email: you@your-company.com
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'

paths:
/inventory/{inventory-id}:
get:
operationId: getInventoryItem
description: Sample
parameters:
# path
- $ref: 'issue-983-domain.yaml/#/components/parameters/inventory-id'
responses:
'200':
description: search results matching criteria
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/InventoryItem'
'400':
description: bad input parameter


components:
schemas:
InventoryItem:
type: string