Repository: swagger-api/swagger-parser
Pull request #926 (2018-11-13 21:32:01)

Issues 901 - 913 to oas3
#901 and #913 in OAS 3


Patch:
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/models/RefType.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/models/RefType.java
index 3626280d..de8673f1 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/models/RefType.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/models/RefType.java
@@ -5,6 +5,7 @@ package io.swagger.v3.parser.models;
  */
 public enum RefType {
     COMPONENTS("#/components/"),
+    SCHEMAS("#/components/schemas/"),
     PATH("#/paths/");
 
     private final String internalPrefix;
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 7c1f057c..1481e081 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
@@ -10,6 +10,7 @@ import io.swagger.v3.oas.models.links.Link;
 import io.swagger.v3.oas.models.media.ArraySchema;
 import io.swagger.v3.oas.models.media.ComposedSchema;
 import io.swagger.v3.oas.models.media.MediaType;
+import io.swagger.v3.oas.models.media.ObjectSchema;
 import io.swagger.v3.oas.models.media.Schema;
 import io.swagger.v3.oas.models.parameters.Parameter;
 import io.swagger.v3.oas.models.parameters.RequestBody;
@@ -18,6 +19,7 @@ import io.swagger.v3.oas.models.responses.ApiResponses;
 import io.swagger.v3.oas.models.security.SecurityScheme;
 import io.swagger.v3.parser.ResolverCache;
 import io.swagger.v3.parser.models.RefFormat;
+import io.swagger.v3.parser.models.RefType;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.LoggerFactory;
 
@@ -199,6 +201,11 @@ public final class ExternalRefProcessor {
                             && StringUtils.isNotBlank(((ArraySchema) mapProp.getAdditionalProperties()).getItems().get$ref())) {
                         processRefSchema(((ArraySchema) mapProp.getAdditionalProperties()).getItems(), file);
                     }
+                }else if (prop.getValue() instanceof ObjectSchema){
+                    ObjectSchema objProp = (ObjectSchema) prop.getValue();
+                    if(objProp.getProperties() != null ){
+                        processProperties(objProp.getProperties(),file);
+                    }
                 }
             }
         }
@@ -674,7 +681,7 @@ public final class ExternalRefProcessor {
         RefFormat format = computeRefFormat(subRef.get$ref());
 
         if (!isAnExternalRefFormat(format)) {
-            subRef.set$ref(processRefToExternalSchema(externalFile + subRef.get$ref(), RefFormat.RELATIVE));
+            subRef.set$ref(RefType.SCHEMAS.getInternalPrefix()+ processRefToExternalSchema(externalFile + subRef.get$ref(), RefFormat.RELATIVE));
             return;
         }
         String $ref = subRef.get$ref();
@@ -682,8 +689,9 @@ public final class ExternalRefProcessor {
         if (format.equals(RefFormat.RELATIVE)) {
             $ref = constructRef(subRef, externalFile);
             subRef.set$ref($ref);
+        }else {
+            processRefToExternalSchema($ref, format);
         }
-        processRefToExternalSchema($ref, computeRefFormat(subRef.get$ref()));
     }
 
 
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/SchemaProcessor.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/SchemaProcessor.java
index cfc3b26f..de489644 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/SchemaProcessor.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/SchemaProcessor.java
@@ -9,6 +9,7 @@ import io.swagger.v3.oas.models.media.Discriminator;
 import io.swagger.v3.oas.models.media.Schema;
 import io.swagger.v3.parser.ResolverCache;
 import io.swagger.v3.parser.models.RefFormat;
+import io.swagger.v3.parser.models.RefType;
 import io.swagger.v3.parser.util.RefUtils;
 
 import java.util.HashMap;
@@ -201,7 +202,7 @@ public class SchemaProcessor {
             final String newRef = externalRefProcessor.processRefToExternalSchema($ref, refFormat);
 
             if (newRef != null) {
-                schema.set$ref(newRef);
+                schema.set$ref(RefType.SCHEMAS.getInternalPrefix() + newRef);
             }
         }
     }


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 8e4754b9..427563ae 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
@@ -58,6 +58,45 @@ public class OpenAPIV3ParserTest {
     protected WireMockServer wireMockServer;
 
 
+    @Test
+    public void testIssue913() {
+        OpenAPIV3Parser parser = new OpenAPIV3Parser();
+        ParseOptions options = new ParseOptions();
+        options.setResolve(true);
+        final OpenAPI openAPI = parser.readLocation("issue-913/BS/ApiSpecification.yaml", null, options).getOpenAPI();
+        Assert.assertNotNull(openAPI);
+        Assert.assertNotNull(openAPI.getComponents().getSchemas().get("indicatorType"));
+        Assert.assertEquals(openAPI.getComponents().getSchemas().get("indicatorType").getProperties().size(),1);
+    }
+
+    @Test
+    public void testIssue901_2() {
+        ParseOptions options = new ParseOptions();
+        options.setResolve(true);
+        OpenAPI openAPI = new OpenAPIV3Parser().readLocation("issue-901/spec2.yaml",null,options).getOpenAPI();
+        assertNotNull(openAPI);
+        assertNotNull(openAPI.getComponents());
+        ArraySchema arraySchema = (ArraySchema) openAPI.getComponents().getSchemas().get("Test.Definition").getProperties().get("stuff");
+        String internalRef = arraySchema.getItems().get$ref();
+        assertEquals(internalRef,"#/components/schemas/TEST.THING.OUT.Stuff");
+
+
+
+
+
+    }
+
+    @Test
+    public void testIssue901() {
+        ParseOptions options = new ParseOptions();
+        options.setResolve(true);
+        OpenAPI openAPI = new OpenAPIV3Parser().readLocation("issue-901/spec.yaml",null,options).getOpenAPI();
+        assertNotNull(openAPI);
+        String internalRef = openAPI.getPaths().get("/test").getPut().getResponses().get("200").getContent().get("application/json").getSchema().get$ref();
+        assertEquals(internalRef,"#/components/schemas/Test.Definition");
+        assertNotNull(openAPI.getComponents());
+    }
+
     @Test
     public void testIssue853() {
         ParseOptions options = new ParseOptions();
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-901/ref.yaml b/modules/swagger-parser-v3/src/test/resources/issue-901/ref.yaml
new file mode 100644
index 00000000..c60d3324
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-901/ref.yaml
@@ -0,0 +1,34 @@
+### Domains, a place to put your reusable components
+
+
+info:
+  title: "aa"
+  description: "swos552"
+  version: '1.0.0'
+
+components:
+  schemas:
+    Test.Definition:
+      type: object
+      properties:
+        stuff:
+          type: array
+          items:
+            $ref: '#/components/schemas/TESTTHING'
+    TESTTHING:
+      type: object
+      properties:
+        prop:
+          type: string
+pathitems:
+  path-test:
+    put:
+      description: test ref
+      operationId: test
+      responses:
+        '200':
+          description: successful operation
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/Test.Definition'
\ No newline at end of file
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-901/ref2.yaml b/modules/swagger-parser-v3/src/test/resources/issue-901/ref2.yaml
new file mode 100644
index 00000000..a219e0b0
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-901/ref2.yaml
@@ -0,0 +1,34 @@
+### Domains, a place to put your reusable components
+
+
+info:
+  title: "aa"
+  description: "swos55"
+  version: '1.0.0'
+
+components:
+  schemas:
+    Test.Definition:
+      type: object
+      properties:
+        stuff:
+          type: array
+          items:
+            $ref: '#/components/schemas/TEST.THING.OUT.Stuff'
+    TEST.THING.OUT.Stuff:
+      type: object
+      properties:
+        prop:
+          type: string
+pathitems:
+  path-test:
+    put:
+      description: test ref
+      operationId: test
+      responses:
+        '200':
+          description: successful operation
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/Test.Definition'
\ No newline at end of file
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-901/spec.yaml b/modules/swagger-parser-v3/src/test/resources/issue-901/spec.yaml
new file mode 100644
index 00000000..abd668bd
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-901/spec.yaml
@@ -0,0 +1,10 @@
+openapi: 3.0.1
+info:
+  title: testswos55
+  description: testswos55
+  version: "1.01"
+servers:
+- url: ///test
+paths:
+  /test:
+    $ref: ref.yaml/#/pathitems/path-test
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-901/spec2.yaml b/modules/swagger-parser-v3/src/test/resources/issue-901/spec2.yaml
new file mode 100644
index 00000000..dfc97d4e
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-901/spec2.yaml
@@ -0,0 +1,10 @@
+openapi: 3.0.1
+info:
+  title: testswos55
+  description: testswos55
+  version: "1.01"
+servers:
+- url: ///test
+paths:
+  /test:
+    $ref: ref2.yaml/#/pathitems/path-test
\ No newline at end of file
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-913/BO/Common/BasicComponents.json b/modules/swagger-parser-v3/src/test/resources/issue-913/BO/Common/BasicComponents.json
new file mode 100644
index 00000000..eebd4035
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-913/BO/Common/BasicComponents.json
@@ -0,0 +1,12 @@
+{
+    "properties": {
+        "indicatorType": {
+            "type": "object",
+            "properties": {
+                "indicator": {
+                    "type": "boolean"
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-913/BO/Resource/ApiSpecificationBO.json b/modules/swagger-parser-v3/src/test/resources/issue-913/BO/Resource/ApiSpecificationBO.json
new file mode 100644
index 00000000..54b85dfa
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-913/BO/Resource/ApiSpecificationBO.json
@@ -0,0 +1,12 @@
+{
+    "properties": {
+        "details": {
+            "type": "object",
+            "properties": {
+                "confirmationCodeRequired": {
+                    "$ref": "../Common/BasicComponents.json#/properties/indicatorType"
+                }
+            }
+        }
+    }
+}
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-913/BS/ApiSpecification.yaml b/modules/swagger-parser-v3/src/test/resources/issue-913/BS/ApiSpecification.yaml
new file mode 100644
index 00000000..aea4b2a9
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-913/BS/ApiSpecification.yaml
@@ -0,0 +1,39 @@
+openapi: 3.0.0
+info:
+    title: Service Model
+    version: 2.4.0
+paths:
+    /networkAccessProfile:
+        get:
+            tags:
+            - AccessProfile
+            operationId: getList
+            parameters:
+            - name: id
+              in: query
+              schema:
+                  type: string
+            responses:
+                '200':
+                    description: OK
+                    content:
+                        application/json:
+                            schema:
+                                type: array
+                                items:
+                                    $ref: '#/components/schemas/accessProfileBO'
+servers:
+- url: 'https://api.com/{access}/accessProfileAPI'
+  variables:
+      access:
+          default: unknown
+components:
+    parameters:
+        fields:
+            name: fields
+            in: query
+            schema:
+                type: string
+    schemas:
+        accessProfileBO:
+            $ref: ../BO/Resource/ApiSpecificationBO.json
\ No newline at end of file
diff --git a/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java b/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java
index d280a916..70ad63c4 100644
--- a/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java
+++ b/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java
@@ -2,6 +2,7 @@ package io.swagger.parser;
 
 
 
+import io.swagger.v3.core.util.Yaml;
 import io.swagger.v3.oas.models.Components;
 import io.swagger.v3.oas.models.OpenAPI;
 import io.swagger.v3.oas.models.media.ArraySchema;
@@ -460,4 +461,5 @@ public class OpenAPIParserTest {
                 .get$ref();
         assertEquals(ref, "#/components/callbacks/callbackEvent");
     }
+
 }