Inaccurate reporting of duplicate parameter values when parsing schema

Issue #307 new
Gordon Cooke created an issue

When parsing a schema that uses $ref for parameters we are seeing an inaccurate parse failure reporting duplicate parameters.

minimal sample :

{
  "openapi": "3.0.0",
  "info": {
    "title": "Test",
    "version": "1.0"
  },
  "paths": {
    "/foo": {
      "post": {
        "operationId": "foo",
        "parameters": [
          {
            "in": "header",
            "name": "x-something",
            "schema": {
              "type": "string"
            },
            "required": true
          },
          {
            "in": "header",
            "name": "x-something-else",
            "schema": {
              "type": "string"
            },
            "required": false
          }
        ],
        "responses": {
          "201": {
            "description": "Success–resource created."
          }
        }
      }
    },
    "/foo/bar": {
      "post": {
        "operationId": "foo2",
        "parameters": [
          {
            "$ref": "#/paths/~1foo/post/parameters/0"
          },
          {
            "$ref": "#/paths/~1foo/post/parameters/1"
          }
        ],
        "responses": {
          "201": {
            "description": "Success–resources created."
          }
        }
      }
    }
  }
}

Note that the parameters in the second path use $ref to point to two different array indexes in the first path (lines 36 and 38). When attempting to parse this schema an error is returned :

Caused by: com.atlassian.oai.validator.OpenApiInteractionValidator$ApiLoadException: Unable to load API spec from provided URL or payload:
    - attribute paths.'/foo/bar'(post).parameters.There are duplicate parameter values
    at com.atlassian.oai.validator.util.OpenApiLoader.loadApi(OpenApiLoader.java:42)
    at com.atlassian.oai.validator.OpenApiInteractionValidator$Builder.build(OpenApiInteractionValidator.java:541)
    at com.atlassian.oai.validator.restassured.OpenApiValidationFilter.<init>(OpenApiValidationFilter.java:41)
    at TestCatalogue.<clinit>(TestCatalogue.java:30)

If you copy/paste the referenced parameters into the 2nd path verbatim the error is corrected.

Comments (3)

  1. Sven Döring

    The named Swagger-Parser bug has been fixed in 2.0.12 and the Swagger-Request-Validator uses 2.0.20. However I’ve updated the version to 2.0.23 and nothing changed. Your Test API still fails to load.

    Please raise an issue on: https://github.com/swagger-api/swagger-parser/issues

    Until then this is a working workaround.

    {
      "openapi": "3.0.0",
      "info": {
        "title": "Test",
        "version": "1.0"
      },
      "paths": {
        "/foo": {
          "post": {
            "operationId": "foo",
            "parameters": [
              {
                "$ref": "#/components/parameters/XSomething"
              },
              {
                "$ref": "#/components/parameters/XSomethingElse"
              }
            ],
            "responses": {
              "201": {
                "description": "Success–resource created."
              }
            }
          }
        },
        "/foo/bar": {
          "post": {
            "operationId": "foo2",
            "parameters": [
              {
                "$ref": "#/components/parameters/XSomething"
              },
              {
                "$ref": "#/components/parameters/XSomethingElse"
              }
            ],
            "responses": {
              "201": {
                "description": "Success–resources created."
              }
            }
          }
        }
      },
      "components": {
        "parameters": {
          "XSomething": {
            "in": "header",
            "name": "x-something",
            "schema": {
              "type": "string"
            },
            "required": true
          },
          "XSomethingElse": {
            "in": "header",
            "name": "x-something-else",
            "schema": {
              "type": "string"
            },
            "required": false
          }
        }
      }
    }
    

  2. Log in to comment