Skip to content
This repository was archived by the owner on Nov 24, 2022. It is now read-only.

Commit 591d27b

Browse files
committed
Merge remote-tracking branch 'origin/master' into 2.0-OpenAPITools
2 parents f033a5e + ad9c3fe commit 591d27b

4 files changed

Lines changed: 90 additions & 1 deletion

File tree

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/ResolverCache.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.fasterxml.jackson.databind.node.ObjectNode;
55
import io.swagger.v3.oas.models.OpenAPI;
66
import io.swagger.v3.oas.models.media.Schema;
7+
import io.swagger.v3.oas.models.parameters.Parameter;
78
import io.swagger.v3.oas.models.responses.ApiResponse;
89
import io.swagger.v3.parser.core.models.AuthorizationValue;
910
import io.swagger.v3.parser.models.RefFormat;
@@ -165,6 +166,12 @@ protected <T> void updateLocalRefs(String file, T result) {
165166
}
166167
}
167168
}
169+
if(result instanceof Parameter){
170+
Parameter parameter = (Parameter)result;
171+
if (parameter.getSchema() != null){
172+
updateLocalRefs(file,parameter.getSchema());
173+
}
174+
}
168175
if(result instanceof Schema && ((Schema)(result)).get$ref() != null) {
169176
Schema prop = (Schema) result;
170177
updateLocalRefs(file, prop);
@@ -194,11 +201,12 @@ protected String merge(String host, String ref) {
194201
if(StringUtils.isBlank(host)) {
195202
return ref;
196203
}
204+
197205
if(ref.startsWith("http:") || ref.startsWith("https:")) {
198206
// already an absolute ref
199207
return ref;
200208
}
201-
if(!host.startsWith("http:") && !host.startsWith("https:")) {
209+
if(!host.startsWith("http:") && !host.startsWith("https:") && !ref.startsWith("#/components")) {
202210
return ref;
203211
}
204212
if(ref.startsWith(".")) {

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ public class OpenAPIV3ParserTest {
5757
protected int serverPort = getDynamicPort();
5858
protected WireMockServer wireMockServer;
5959

60+
@Test
61+
public void testIssue983() {
62+
OpenAPIV3Parser parser = new OpenAPIV3Parser();
63+
ParseOptions options = new ParseOptions();
64+
options.setResolve(true);
65+
final OpenAPI openAPI = parser.readLocation("issue-983.yaml", null, options).getOpenAPI();
66+
Assert.assertNotNull(openAPI);
67+
Yaml.prettyPrint(openAPI);
68+
Assert.assertNotNull(openAPI.getComponents().getSchemas().get("InventoryId"));
69+
70+
}
71+
6072

6173
@Test
6274
public void testIssue913() {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
openapi: 3.0.0
2+
3+
info:
4+
title: Sample-Domain
5+
description: 'Reusable components for the Notification domain.'
6+
contact:
7+
url: https://www.url.com/
8+
email: url.api.support@url.com
9+
license:
10+
name: Sample
11+
version: "1.0.0"
12+
13+
paths:
14+
/na-domain-only:
15+
summary: n/a
16+
description: n/a
17+
18+
19+
components:
20+
schemas:
21+
InventoryId:
22+
description: 'Key information uniquely identifying a inventory. May be a composite of information'
23+
type: string
24+
25+
parameters:
26+
inventory-id:
27+
in: path
28+
name: inventory-id
29+
description: 'Could be composite key'
30+
required: true
31+
schema:
32+
$ref: '#/components/schemas/InventoryId'
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
openapi: 3.0.0
2+
servers: []
3+
info:
4+
description: This is a simple API
5+
version: "1.0.0"
6+
title: Simple Inventory API
7+
contact:
8+
email: you@your-company.com
9+
license:
10+
name: Apache 2.0
11+
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
12+
13+
paths:
14+
/inventory/{inventory-id}:
15+
get:
16+
operationId: getInventoryItem
17+
description: Sample
18+
parameters:
19+
# path
20+
- $ref: 'issue-983-domain.yaml/#/components/parameters/inventory-id'
21+
responses:
22+
'200':
23+
description: search results matching criteria
24+
content:
25+
application/json:
26+
schema:
27+
type: array
28+
items:
29+
$ref: '#/components/schemas/InventoryItem'
30+
'400':
31+
description: bad input parameter
32+
33+
34+
components:
35+
schemas:
36+
InventoryItem:
37+
type: string

0 commit comments

Comments
 (0)