Repository: swagger-api/swagger-parser
Pull request #1080 (2019-04-18 19:56:08)

fix for Parameter Validation Issue 
refs #1065 #1063


Patch:
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java
index 66140117..03f8b0a1 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java
@@ -52,6 +52,7 @@ import io.swagger.v3.parser.core.models.SwaggerParseResult;
 import io.swagger.v3.core.util.Json;
 import io.swagger.v3.core.util.RefUtils;
 
+import io.swagger.v3.parser.models.RefFormat;
 import org.apache.commons.lang3.StringUtils;
 
 import static io.swagger.v3.core.util.RefUtils.extractSimpleName;
@@ -103,7 +104,7 @@ public class OpenAPIDeserializer {
     private static final String HEADER_PARAMETER = "header";
     private static final Pattern RFC3339_DATE_TIME_PATTERN = Pattern.compile( "^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(\\.\\d+)?((Z)|([+-]\\d{2}:\\d{2}))$");
     private static final Pattern RFC3339_DATE_PATTERN = Pattern.compile( "^(\\d{4})-(\\d{2})-(\\d{2})$");
-
+    private static final String REFERENCE_SEPARATOR = "#/";
     private Components components;
     private final Set<String> operationIDs = new HashSet<>();
 
@@ -1422,9 +1423,17 @@ public class OpenAPIDeserializer {
         }
         Set<String> filter = new HashSet<>();
 
+
         parameters.stream().map(this::getParameterDefinition).forEach(param -> {
+            String ref = param.get$ref();
             if(!filter.add(param.getName()+"#"+param.getIn())) {
-                result.warning(location,"There are duplicate parameter values");
+                if(ref != null) {
+                    if (ref.startsWith(REFERENCE_SEPARATOR)) {// validate if it's inline param also
+                        result.warning(location, "There are duplicate parameter values");
+                    }
+                }else{
+                    result.warning(location, "There are duplicate parameter values");
+                }
             }
         });
         return parameters;


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 a7273287..cf914dc8 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
@@ -1869,6 +1869,26 @@ public class OpenAPIV3ParserTest {
 
     }
 
+    @Test
+    public void testIssue1063() {
+        // given
+        String location = "src/test/resources/issue-1063/openapi.yaml";
+        ParseOptions options = new ParseOptions();
+        options.setResolve(true);
+        OpenAPIV3Parser tested = new OpenAPIV3Parser();
+
+        // when
+        SwaggerParseResult result = tested.readLocation(location, emptyList(), options);
+
+        // then
+        OpenAPI api = result.getOpenAPI();
+        assertEquals(api.getPaths().get("/anPath").getGet().getParameters().get(0).getName(), "customer-id");
+        assertEquals(api.getPaths().get("/anPath").getGet().getParameters().get(1).getName(), "unit-id");
+
+        assertThat(result.getMessages(), equalTo(emptyList()));
+
+    }
+
     private static int getDynamicPort() {
         return new Random().ints(10000, 20000).findFirst().getAsInt();
     }
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-1063/openapi.yaml b/modules/swagger-parser-v3/src/test/resources/issue-1063/openapi.yaml
new file mode 100644
index 00000000..306409ae
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-1063/openapi.yaml
@@ -0,0 +1,21 @@
+openapi: 3.0.0
+info:
+  version: 1.0.0
+  title: an API
+  description: An API for reproduce a *There are duplicate parameter values*.
+
+paths:
+  /anPath:
+    get:
+      parameters:
+        - $ref: './references.oas3.yaml#/components/parameters/ParamQ_One'
+        - $ref: './references.oas3.yaml#/components/parameters/ParamQ_Two'
+      responses:
+        '200':
+          description: OK
+          content:
+            application/json:
+              schema:
+                type: array
+                items:
+                  type: string
\ No newline at end of file
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-1063/references.oas3.yaml b/modules/swagger-parser-v3/src/test/resources/issue-1063/references.oas3.yaml
new file mode 100644
index 00000000..98fbdc94
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-1063/references.oas3.yaml
@@ -0,0 +1,15 @@
+components:
+  parameters:
+    ParamQ_One:
+      in: query
+      name: customer-id
+      required: true
+      schema:
+        format: int32
+        type: integer
+    ParamQ_Two:
+      in: query
+      name: unit-id
+      schema:
+        format: int32
+        type: integer
\ No newline at end of file