Skip to content

Multidimensional arrays as parameters. #412

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

Closed
IvanGoncharov opened this issue Jul 15, 2015 · 5 comments
Closed

Multidimensional arrays as parameters. #412

IvanGoncharov opened this issue Jul 15, 2015 · 5 comments

Comments

@IvanGoncharov
Copy link
Contributor

Currently Swagger 2.0 support specs like that:

{
    "swagger": "2.0",
    "info": {
        "version": "0.0.0",
        "title": "Simple API"
    },
    "paths": {
        "/{foo}": {
            "parameters": [
                {
                    "name": "foo",
                    "in": "path",
                    "type": "array",
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                }
            ],
            "get": {
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    }
}

By default collectionFormat is csv and this create problems with interpreting strings like 'a,b,c,d'.
Should it be interpreted like:

[
  ["a","b","c","d"]
]

Or maybe like this:

[
  ["a", "b"],
  ["c", "d"]
]

It should be forbidden to create nested arrays with same collectionFormat.
This change will prevent undefined behaviour situation and could be done in 2.0 as bugfix.
JSON Schema couldn't enforce such constraints, but it could be specified in spec.

@jharmn
Copy link
Contributor

jharmn commented Feb 12, 2016

Link to parent #565

@fehguy
Copy link
Contributor

fehguy commented Feb 1, 2017

Done in #804

@fehguy fehguy closed this as completed Feb 1, 2017
@ePaul
Copy link
Contributor

ePaul commented Mar 28, 2017

@fehguy I don't actually see this in the specification ... where do we forbid this (which would be the corresponding structure to what @IvanGoncharov posted)?

parameters:
  - in: path
    name: foo
    schema:
      type: array
      items:
        type: array
        items:
          type: string
    example: 'a,b,c,d'
    required: true

@fehguy
Copy link
Contributor

fehguy commented Mar 28, 2017

we don't forbid this, we support it by allowing a schema object as the type for the parameter.

@ePaul
Copy link
Contributor

ePaul commented Mar 28, 2017

The original issue said

It should be forbidden to create nested arrays with same collectionFormat.

While the original code was not actually valid in OpenAPI 2.0, I think, its transformed version is valid in OpenAPI 3.0-RC0 due to the introduction of schemas for parameters.

Now there isn't a collectionFormat anymore, but the style property, which only applies on top level.

So for style: simple (which is the default for path parameters) there is still no way of knowing whether /a,b,c,d would be parsed as [["a","b"],["c","d"]], as [["a","b","c","d"]] or as any other structure.

There doesn't even seem to be a way of using different styles for both levels of array (which could solve this potentially).

So I think the issue is still open.

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

5 participants