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

Commit 266b89d

Browse files
authored
Merge pull request swagger-api#1106 from swagger-api/issue-1105
Resolving Remote Ref Response with ArraySchema Ref Items issue swagger-api#1105
2 parents 89d59b4 + 7b10ac4 commit 266b89d

4 files changed

Lines changed: 57 additions & 6 deletions

File tree

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
182182
return newRef;
183183
}
184184

185-
private void processProperty(Schema property, String file) {
185+
private void processSchema(Schema property, String file) {
186186
if (property != null) {
187187
if (StringUtils.isNotBlank(property.get$ref())) {
188188
processRefSchema(property, file);
@@ -191,10 +191,10 @@ private void processProperty(Schema property, String file) {
191191
processProperties(property.getProperties(), file);
192192
}
193193
if (property instanceof ArraySchema) {
194-
processProperty(((ArraySchema) property).getItems(), file);
194+
processSchema(((ArraySchema) property).getItems(), file);
195195
}
196196
if (property.getAdditionalProperties() instanceof Schema) {
197-
processProperty(((Schema) property.getAdditionalProperties()), file);
197+
processSchema(((Schema) property.getAdditionalProperties()), file);
198198
}
199199
if (property instanceof ComposedSchema) {
200200
ComposedSchema composed = (ComposedSchema) property;
@@ -208,7 +208,7 @@ private void processProperty(Schema property, String file) {
208208
private void processProperties(Collection<Schema> properties, String file) {
209209
if (properties != null) {
210210
for (Schema property : properties) {
211-
processProperty(property, file);
211+
processSchema(property, file);
212212
}
213213
}
214214
}
@@ -269,6 +269,8 @@ public String processRefToExternalResponse(String $ref, RefFormat refFormat) {
269269
} else {
270270
processRefToExternalSchema(file + schema.get$ref(), RefFormat.RELATIVE);
271271
}
272+
}else{
273+
processSchema(schema,file);
272274
}
273275
}
274276
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,6 @@ public void testInlineModelResolver(@Injectable final List<AuthorizationValue> a
560560
@Test
561561
public void test30NoOptions(@Injectable final List<AuthorizationValue> auths) throws Exception{
562562

563-
564-
565563
String pathFile = FileUtils.readFileToString(new File("src/test/resources/oas3.yaml.template"));
566564
pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));
567565

@@ -610,6 +608,13 @@ public void testInlineModelResolverByUrl(){
610608
assertNotNull(userAddress.getProperties().get("street"));
611609
}
612610

611+
@Test
612+
public void testIssue1105() throws Exception {
613+
OpenAPI openAPI = new OpenAPIV3Parser().read("issue-1105/swagger-api.yaml");
614+
Assert.assertNotNull(openAPI);
615+
Assert.assertNotNull(openAPI.getComponents().getSchemas().get("ErrorCodeDescription"));
616+
}
617+
613618
@Test
614619
public void testRefAdditionalProperties() throws Exception {
615620
OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/relative/additionalProperties.yaml");
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
openapi: 3.0.2
2+
info:
3+
title: API Components
4+
description: Common components
5+
version: '1.0'
6+
components:
7+
schemas:
8+
ErrorCodeDescription:
9+
type: object
10+
properties:
11+
code:
12+
format: int32
13+
type: integer
14+
description: HTTP error code.
15+
description:
16+
type: string
17+
description: Brief description of the error.
18+
details:
19+
type: string
20+
description: Details about the error.
21+
responses:
22+
401:
23+
description: User is not authorized for this action
24+
content:
25+
application/json:
26+
schema:
27+
uniqueItems: false
28+
type: array
29+
items:
30+
$ref: "#/components/schemas/ErrorCodeDescription"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
openapi: "3.0.2"
2+
info:
3+
title: User and Session
4+
description: Admin API endpoints.
5+
version: "0.1"
6+
paths:
7+
/users:
8+
get:
9+
responses:
10+
"401":
11+
$ref: "./domain.yaml#/components/responses/401"
12+
components: {
13+
schemas: {}
14+
}

0 commit comments

Comments
 (0)