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

Validation error in query params of type array #567

Open
DavidGonzalezPineiro opened this issue Nov 2, 2023 · 0 comments · May be fixed by #568
Open

Validation error in query params of type array #567

DavidGonzalezPineiro opened this issue Nov 2, 2023 · 0 comments · May be fixed by #568

Comments

@DavidGonzalezPineiro
Copy link

When validating the query params of an endpoint with parameters of type array we get a validation error:

Example:

GET /api/users?ids[]=1&ids[]=2

Operation param defined as:

Operation.parameter(
:"ids[]",
:query,
%Schema{type: :array, items: %Schema{type: :integer}},
"IDs"
)

We get the following error:

[
  %OpenApiSpex.Cast.Error{
    reason: :invalid_type,
    value: "2",
    format: nil,
    type: :array,
    name: nil,
    path: [:ids],
    length: 0,
    meta: %{}
  }
]

This is because Plug.Conn.fetch_query_params removes the "[]" part by grouping the property and returning an array of results. Following the example above, the result of this function would be %{ids: [1,2]} which causes an error, because in the Schema "ids[]" has been defined as a possible parameter and not "ids".

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

Successfully merging a pull request may close this issue.

1 participant