Repository: swagger-api/swagger-parser
Pull request #992 (2019-01-15 13:50:13)

ref - #983 fixes remote reference parameter schemas in components
External Schemas inside parameters were not being solved from external location 


Patch:
diff --git a/README.md b/README.md
index 7504ea3f..1411fa02 100644
--- a/README.md
+++ b/README.md
@@ -99,7 +99,7 @@ You can include this library from Sonatype OSS for SNAPSHOTS, or Maven central f
 <dependency>
   <groupId>io.swagger.parser.v3</groupId>
   <artifactId>swagger-parser</artifactId>
-  <version>2.0.9-SNAPSHOT</version>
+  <version>2.0.8-SNAPSHOT</version>
 </dependency>
 
 ```
@@ -110,7 +110,7 @@ or
 <dependency>
   <groupId>io.swagger.parser.v3</groupId>
   <artifactId>swagger-parser</artifactId>
-  <version>2.0.9-SNAPSHOT</version>
+  <version>2.0.8-SNAPSHOT</version>
 </dependency>
 
 ```
diff --git a/modules/swagger-parser-core/pom.xml b/modules/swagger-parser-core/pom.xml
index d2f3897e..c2b1646d 100644
--- a/modules/swagger-parser-core/pom.xml
+++ b/modules/swagger-parser-core/pom.xml
@@ -3,7 +3,7 @@
     <parent>
         <groupId>io.swagger.parser.v3</groupId>
         <artifactId>swagger-parser-project</artifactId>
-        <version>2.0.9-SNAPSHOT</version>
+        <version>2.0.8-SNAPSHOT</version>
         <relativePath>../..</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
diff --git a/modules/swagger-parser-v2-converter/pom.xml b/modules/swagger-parser-v2-converter/pom.xml
index f519781f..3a297736 100644
--- a/modules/swagger-parser-v2-converter/pom.xml
+++ b/modules/swagger-parser-v2-converter/pom.xml
@@ -3,7 +3,7 @@
     <parent>
         <groupId>io.swagger.parser.v3</groupId>
         <artifactId>swagger-parser-project</artifactId>
-        <version>2.0.9-SNAPSHOT</version>
+        <version>2.0.8-SNAPSHOT</version>
         <relativePath>../..</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
diff --git a/modules/swagger-parser-v3/pom.xml b/modules/swagger-parser-v3/pom.xml
index 529dca31..7e6702aa 100644
--- a/modules/swagger-parser-v3/pom.xml
+++ b/modules/swagger-parser-v3/pom.xml
@@ -3,7 +3,7 @@
     <parent>
         <groupId>io.swagger.parser.v3</groupId>
         <artifactId>swagger-parser-project</artifactId>
-        <version>2.0.9-SNAPSHOT</version>
+        <version>2.0.8-SNAPSHOT</version>
         <relativePath>../..</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/ResolverCache.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/ResolverCache.java
index 2d9aeb5f..e2d1bc75 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/ResolverCache.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/ResolverCache.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
 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;
@@ -165,6 +166,12 @@ public class ResolverCache {
                 }
             }
         }
+        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);
@@ -194,11 +201,12 @@ public class ResolverCache {
         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(".")) {
diff --git a/modules/swagger-parser/pom.xml b/modules/swagger-parser/pom.xml
index 0c6a9d29..4c9dcf27 100644
--- a/modules/swagger-parser/pom.xml
+++ b/modules/swagger-parser/pom.xml
@@ -3,7 +3,7 @@
     <parent>
         <groupId>io.swagger.parser.v3</groupId>
         <artifactId>swagger-parser-project</artifactId>
-        <version>2.0.9-SNAPSHOT</version>
+        <version>2.0.8-SNAPSHOT</version>
         <relativePath>../..</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
diff --git a/pom.xml b/pom.xml
index 09a06396..392c5f0f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>io.swagger.parser.v3</groupId>
     <artifactId>swagger-parser-project</artifactId>
-    <version>2.0.9-SNAPSHOT</version>
+    <version>2.0.8-SNAPSHOT</version>
     <packaging>pom</packaging>
     <name>swagger-parser-project</name>
     <developers>
@@ -263,7 +263,7 @@
         </repository>
     </repositories>
     <properties>
-        <swagger-parser-v2-version>1.0.41</swagger-parser-v2-version>
+        <swagger-parser-v2-version>1.0.41-SNAPSHOT</swagger-parser-v2-version>
         <commons-io-version>2.4</commons-io-version>
         <slf4j-version>1.6.3</slf4j-version>
         <swagger-core-version>2.0.6</swagger-core-version>


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 8a1c31cc..ca4e39c0 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
@@ -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() {
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-983-domain.yaml b/modules/swagger-parser-v3/src/test/resources/issue-983-domain.yaml
new file mode 100644
index 00000000..fcf2d320
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-983-domain.yaml
@@ -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'
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-983.yaml b/modules/swagger-parser-v3/src/test/resources/issue-983.yaml
new file mode 100644
index 00000000..51719bb7
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-983.yaml
@@ -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
\ No newline at end of file