Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swagger-parser does not parse the collectionFormat of query parameters if it is defined before the type #291

Closed
michaelkourlas opened this issue Aug 24, 2016 · 2 comments
Milestone

Comments

@michaelkourlas
Copy link

michaelkourlas commented Aug 24, 2016

When swagger-parser parses the following spec, it thinks that the testParam query parameter has a collectionFormat of "multi", even though it is explicitly defined as having a collectionFormat of "csv":

{
  "swagger": "2.0",
  "info": {
    "title": "test spec",
    "version": "1.0"
  },
  "parameters": {
    "testParam": {
      "collectionFormat": "csv",
      "name": "test",
      "in": "query",
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  },
  "paths": {
    "/test": {
      "get": {
        "description": "test get",
        "parameters": [
          {
            "$ref": "#/parameters/testParam"
          }
        ],
        "responses": {
          "default": {
             "description": "test response"
          }
        }
      }
    }
  }
}

It correctly parses the collectionFormat if it is defined after the type, like so:

"testParam": {
  "name": "test",
  "in": "query",
  "type": "array",
  "collectionFormat": "csv",
  "items": {
    "type": "string"
}

The ordering of JSON properties is irrelevant, so this is definitely a bug.

@fehguy
Copy link
Contributor

fehguy commented Aug 26, 2016

Got it, thanks for reporting. Looks like the parsing of parameters at the top-level is taking a different path than inside an operation.

@fehguy
Copy link
Contributor

fehguy commented Aug 26, 2016

ok @michaelkourlas I see what was going on. The issue was only when parameters were shared from the top-level, the code took a different path. This was fixed in ac8b4e5

My test cases here didn't hit that path, but the above commit should ensure it does the right thing.

@fehguy fehguy modified the milestone: v1.0.23 Oct 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants