Repository: swagger-api/swagger-parser
Pull request #1106 (2019-05-24 21:42:19)

Resolving Remote Ref Response with ArraySchema Ref Items  issue #1105
Resolving Remote Ref Response with ArraySchema Ref Items


Patch:
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java
index 9f5f3b39..94e203f9 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java
@@ -182,7 +182,7 @@ public final class ExternalRefProcessor {
         return newRef;
     }
 
-    private void processProperty(Schema property, String file) {
+    private void processSchema(Schema property, String file) {
         if (property != null) {
             if (StringUtils.isNotBlank(property.get$ref())) {
                 processRefSchema(property, file);
@@ -191,10 +191,10 @@ public final class ExternalRefProcessor {
                 processProperties(property.getProperties(), file);
             }
             if (property instanceof ArraySchema) {
-                processProperty(((ArraySchema) property).getItems(), file);
+                processSchema(((ArraySchema) property).getItems(), file);
             }
             if (property.getAdditionalProperties() instanceof Schema) {
-                processProperty(((Schema) property.getAdditionalProperties()), file);
+                processSchema(((Schema) property.getAdditionalProperties()), file);
             }
             if (property instanceof ComposedSchema) {
                 ComposedSchema composed = (ComposedSchema) property;
@@ -208,7 +208,7 @@ public final class ExternalRefProcessor {
     private void processProperties(Collection<Schema> properties, String file) {
         if (properties != null) {
             for (Schema property : properties) {
-                processProperty(property, file);
+                processSchema(property, file);
             }
         }
     }
@@ -269,6 +269,8 @@ public final class ExternalRefProcessor {
                             } else {
                                 processRefToExternalSchema(file + schema.get$ref(), RefFormat.RELATIVE);
                             }
+                        }else{
+                            processSchema(schema,file);
                         }
                     }
                 }


Test patch:
diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
index c5cd8d1d..c40a1105 100644
--- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
+++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
@@ -560,8 +560,6 @@ public class OpenAPIV3ParserTest {
     @Test
     public void test30NoOptions(@Injectable final List<AuthorizationValue> auths) throws Exception{
 
-
-
         String pathFile = FileUtils.readFileToString(new File("src/test/resources/oas3.yaml.template"));
         pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));
 
@@ -610,6 +608,13 @@ public class OpenAPIV3ParserTest {
         assertNotNull(userAddress.getProperties().get("street"));
     }
 
+    @Test
+    public void testIssue1105() throws Exception {
+        OpenAPI openAPI = new OpenAPIV3Parser().read("issue-1105/swagger-api.yaml");
+        Assert.assertNotNull(openAPI);
+        Assert.assertNotNull(openAPI.getComponents().getSchemas().get("ErrorCodeDescription"));
+    }
+
     @Test
     public void testRefAdditionalProperties() throws Exception {
         OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/relative/additionalProperties.yaml");
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-1105/domain.yaml b/modules/swagger-parser-v3/src/test/resources/issue-1105/domain.yaml
new file mode 100644
index 00000000..67d37f94
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-1105/domain.yaml
@@ -0,0 +1,30 @@
+openapi: 3.0.2
+info:
+  title: API Components
+  description: Common components
+  version: '1.0'
+components:
+  schemas:
+    ErrorCodeDescription:
+      type: object
+      properties:
+        code:
+          format: int32
+          type: integer
+          description: HTTP error code.
+        description:
+          type: string
+          description: Brief description of the error.
+        details:
+          type: string
+          description: Details about the error.
+  responses:
+    401:
+      description: User is not authorized for this action
+      content:
+        application/json:
+          schema:
+            uniqueItems: false
+            type: array
+            items:
+              $ref: "#/components/schemas/ErrorCodeDescription"
\ No newline at end of file
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-1105/swagger-api.yaml b/modules/swagger-parser-v3/src/test/resources/issue-1105/swagger-api.yaml
new file mode 100644
index 00000000..58d806e2
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-1105/swagger-api.yaml
@@ -0,0 +1,14 @@
+openapi: "3.0.2"
+info:
+  title: User and Session
+  description: Admin API endpoints.
+  version: "0.1"
+paths:
+  /users:
+    get:
+      responses:
+        "401":
+          $ref: "./domain.yaml#/components/responses/401"
+components: {
+  schemas: {}
+}
\ No newline at end of file