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

Query string parameter validation of Arrays with style: form and explode: false #38

Closed
digilist opened this issue Jul 4, 2019 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@digilist
Copy link
Contributor

digilist commented Jul 4, 2019

Consider this swagger parameter definition (in YAML):

    -
        name: filter
        in: query
        description: Filter something
        explode: false
        style: form
        schema:
            type: array
            items:
                type: string

According to the Open Api Specification this will result in a query parameter ?filter=a,b,c (which is also generated by Swagger UI)

However, the validation does not consider a URL of that format as an array, but as a string:

OpenAPI spec does not match the query argument 'with' of the request [/test,get]: Value expected to be 'array', 'string' given.
@lezhnev74
Copy link
Owner

Yeah, true. At this point, parameters serialization and deserialization are not supported at all in this package.

@willchambers99
Copy link

Yeah, true. At this point, parameters serialization and deserialization are not supported at all in this package.

I also have ran into this issue today.

Would this not be something that could be possibly fixed with the changes that were added here just recently? -> #36

@lezhnev74
Copy link
Owner

Well, serialization is not so straightforward to me, as there are many supported serialization patterns: https://swagger.io/docs/specification/serialization/

#36 incorporates much simpler things like typecasting (it uses just type keyword and basically validates the query argument based on that).

@judgej
Copy link

judgej commented Jul 11, 2019

In case it is of any use for ideas, we are generating clients from OpenAPI descriptions using the OpenAPI Code Generation project. Are using heavily customised templates (and still WIP) but this function converts an array of strings passed into an operation method, into a serialised parameter string suitable for a query parameters:

https://github.com/consilience/xero-api-sdk/blob/master/apis/accounting/src/ObjectSerializer.php#L209

This is one big we haven't touched yet, so probably needs some work, but I'm guessing deserialising a parameter will be the reverse of this. The serialisation looks fairly simple on the face of it, at least for query parameters (path parameters though, yikes).

Would takling simple serialisation on just query parameters, effectively casting them to arrays using different joining patterns, be a relatively simple first step? I suspect that will be the most common use-case anyway.

@lezhnev74 lezhnev74 added the help wanted Extra attention is needed label Jul 16, 2019
@lezhnev74
Copy link
Owner

closed in favor of #47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants