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

Array parameter in path #123

Closed
Nico87LBS opened this issue Apr 11, 2018 · 3 comments
Closed

Array parameter in path #123

Nico87LBS opened this issue Apr 11, 2018 · 3 comments
Labels

Comments

@Nico87LBS
Copy link
Contributor

Nico87LBS commented Apr 11, 2018

Hello,

I have a problem (bug?) with an array parameter in path.

My swagger spec file looks like:

/foo/{bar}:
    get:
      summary: exemple of array parameter
      parameters:
        - in: path
          name: bar
          type: array
          minItems: 1
          uniqueItems: true
          items:
            type: string
            enum: [black, white]

If I make a request to this url;
http://localhost:3000/foo/white
Everything is all right.

But if I request:
http://localhost:3000/foo/white,black
I have a 400 bad request, invalid request params input.

If I add collectionFormat: csv, it changes nothing. And it seems that it is not take into account because if I add collectionFormat: ssv, swagger ui continue to generate the same url with comas!

Furthermore, if I remove the enum line, so my items are only of type string and do the following request:
http://localhost:3000/foo/white,black
In my handlers, if I display request.params, I obtain:
{bar: [ 'white,black' ] }
Instead of:
{bar: ['white', 'black'] }

Could you help me to find the solution?

Thank you

Ref: https://swagger.io/docs/specification/2-0/describing-parameters/#path-parameters

@Nico87LBS
Copy link
Contributor Author

It seems that collectionFormat is not used even if present in the swagger def file. Not in query nor path parameters.

In hapi-openapi/test/test-hapi-openapi.js, in query validation we have only multi collectionFormat

const queryStringToStatusCode = {
                'limit=2': 200,
                'tags=some_tag&tags=some_other_tag': 200,
                'tags=single_tag': 200,
                'limit=2&tags=some_tag&tags=some_other_tag': 200,
                'limit=a_string': 400
}

even if in the defs file, collectionFormat is defined to csv.

We should have:

const queryStringToStatusCode = {
                'limit=2': 200,
                'tags=some_tag&tags=some_other_tag': 200,
                'tags=some_tag,some_other_tag': 200,
                'tags=single_tag': 200,
                'limit=2&tags=some_tag&tags=some_other_tag': 200,
                'limit=a_string': 400
}

@tlivings
Copy link
Contributor

You might use multi as a collectionFormat in your API as the work around, as by default this is what hapi expects.

Add tests to the PR and I will look at merging.

@tlivings
Copy link
Contributor

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants