Skip to content

Add support for query parameter serialization styles #2077

@jakub-bacic

Description

@jakub-bacic

While implementing filtering API recently and I came across a problem with parsing list of comma-separated ids from query string:

Example:

GET /api/items?id=1,3,5

I know this type of parsing can be easily done by declaring id parameter as str and parsing it inside the function but then we're missing awesome OpenAPI doc features.

Please find the PR #2078 with proposed solution.

OpenAPI Docs: https://swagger.io/docs/specification/serialization/

Comments regarding code changes:

  • all changes should be backward compatible
  • there's no support for style=deepObject as it would require more changes (because query params cannot be non-scalar values at the moment)
  • in case multiple values are present (e.g. ?id=1&id=2,3) and explode=False, only last value is parsed (in this case 2,3); it's consistent with the currently implemented behaviour in case of declaring parameter as non-sequence (e.g. str) and receiving more than one value in query string

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions