Repository: swagger-api/swagger-parser
Pull request #1109 (2019-05-29 22:22:15)

fix for Issue #1094


Patch:
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ParameterProcessor.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ParameterProcessor.java
index b2d60b75..07b85bc8 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ParameterProcessor.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ParameterProcessor.java
@@ -2,6 +2,7 @@ package io.swagger.v3.parser.processors;
 
 
 import io.swagger.v3.oas.models.examples.Example;
+import io.swagger.v3.oas.models.media.Content;
 import io.swagger.v3.oas.models.media.MediaType;
 import io.swagger.v3.oas.models.media.Schema;
 import io.swagger.v3.oas.models.parameters.Parameter;
@@ -142,6 +143,23 @@ public class ParameterProcessor {
             Schema schema = parameter.getSchema();
             if(schema != null){
                 schemaProcessor.processSchema(schema);
+            }else if(parameter.getContent() != null){
+                Map<String,MediaType> content = parameter.getContent();
+                for( String mediaName : content.keySet()) {
+                    MediaType mediaType = content.get(mediaName);
+                    if(mediaType.getSchema()!= null) {
+                        schema = mediaType.getSchema();
+                        if (schema != null) {
+                            schemaProcessor.processSchema(schema);
+                        }
+                    }
+                    if(mediaType.getExamples() != null) {
+                        for(Example ex: mediaType.getExamples().values()){
+                            exampleProcessor.processExample(ex);
+                        }
+                    }
+                }
+
             }
         }
 
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/PathsProcessor.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/PathsProcessor.java
index 8c5ce7f0..2e3c4d61 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/PathsProcessor.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/PathsProcessor.java
@@ -75,7 +75,6 @@ public class PathsProcessor {
             final List<Parameter> processedPathParameters = parameterProcessor.processParameters(pathItem.getParameters());
             pathItem.setParameters(processedPathParameters);
 
-            //addParametersToEachOperation(pathItem);
 
             final Map<PathItem.HttpMethod, Operation> operationMap = pathItem.readOperationsMap();
 


Test patch:
diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/processors/ParameterProcessorTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/processors/ParameterProcessorTest.java
index 318c0f0e..7775cea2 100644
--- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/processors/ParameterProcessorTest.java
+++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/processors/ParameterProcessorTest.java
@@ -45,16 +45,24 @@ public class ParameterProcessorTest {
             {
                 headerParameter.getSchema();
                 result = null;
+                headerParameter.getContent();
+                result = null;
                 queryParameter.getSchema();
                 result = null;
+                queryParameter.getContent();
+                result = null;
                 cookieParameter.getSchema();
                 result = null;
+                cookieParameter.getContent();
+                result = null;
                 pathParameter.getSchema();
                 result = null;
+                pathParameter.getContent();
+                result = null;
             }
         };
         final List<Parameter> processedParameters = new ParameterProcessor(cache, openAPI)
-                .processParameters(Arrays.<Parameter>asList(headerParameter,
+                .processParameters(Arrays.asList(headerParameter,
                         queryParameter,
                         cookieParameter,
                         pathParameter));
@@ -78,8 +86,7 @@ public class ParameterProcessorTest {
     }
 
     @Test
-    public void testProcessParameters_RefToHeader(
-            @Injectable final HeaderParameter resolvedHeaderParam) throws Exception {
+    public void testProcessParameters_RefToHeader(@Injectable final HeaderParameter resolvedHeaderParam) throws Exception {
         expectedModelProcessorCreation();
 
         final String ref = "#/components/parameters/foo";
@@ -90,11 +97,12 @@ public class ParameterProcessorTest {
             {
                 resolvedHeaderParam.getSchema();
                 result = null;
+                resolvedHeaderParam.getContent();
+                result = null;
             }
         };
 
-        final List<Parameter> processedParameters = new ParameterProcessor(cache, openAPI)
-                .processParameters(Arrays.<Parameter>asList(refParameter));
+        final List<Parameter> processedParameters = new ParameterProcessor(cache, openAPI).processParameters(Arrays.asList(refParameter));
 
         new FullVerifications(){{}};
 
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 c843d6f8..bae26181 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
@@ -65,6 +65,15 @@ public class OpenAPIV3ParserTest {
     protected int serverPort = getDynamicPort();
     protected WireMockServer wireMockServer;
 
+    @Test
+    public void testRemoteParameterIssue1094(@Injectable final List<AuthorizationValue> auths) throws Exception{
+
+        OpenAPI result = new OpenAPIV3Parser().read("issue-1094/swagger.yaml");
+        Assert.assertNotNull(result);
+        Assert.assertNotNull(result.getComponents().getSchemas().get("PlmnId"));
+
+    }
+
     @Test
     public void testIssue1071() {
 
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-1094/common.yaml b/modules/swagger-parser-v3/src/test/resources/issue-1094/common.yaml
new file mode 100644
index 00000000..f5f0cf0e
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-1094/common.yaml
@@ -0,0 +1,14 @@
+openapi: "3.0.0"
+info:
+  version: 15.3.0
+  title: "Common Data Types"
+paths: {}
+components:
+  schemas:
+    PlmnId:
+      type: object
+      properties:
+        mcc:
+          type: string
+        mnc:
+          type: string
\ No newline at end of file
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-1094/swagger.yaml b/modules/swagger-parser-v3/src/test/resources/issue-1094/swagger.yaml
new file mode 100644
index 00000000..1ca2e0e5
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-1094/swagger.yaml
@@ -0,0 +1,22 @@
+openapi: "3.0.0"
+info:
+  version: 15.3.0
+  title: test
+paths:
+  /my-app:
+    get:
+      parameters:
+        - name: target-plmn-list
+          in: query
+          content:
+            application/json:
+              schema:
+                type: array
+                items:
+                  $ref: 'common.yaml#/components/schemas/PlmnId'
+                  minItems: 1
+      responses:
+        '200':
+          description: Expected response to a valid request
+          schema:
+            type: string
\ No newline at end of file