krakenjs / hapi-openapi

Build design-driven apis with OpenAPI (formerly swagger) 2.0 and hapi.
Other
211 stars 75 forks source link

Support for query params array #206

Closed thebrownfox closed 2 years ago

thebrownfox commented 2 years ago

When I try to use array in query parameters, I get this validation error. I think it's because it doesn't check against "search_fields[index]" (search_fields only).

ValidationError: "search_fields[0]" is not allowed

"search_fields": {
    "name": "search_fields",
    "in": "query",
    "schema": {
        "items": {
            "type": "string"
        },
        "type": "array"
    }
}

value:

{
  search: "",
  "search_fields[0]": "id",
  results: "10",
  page: "1",
  "sort[0]": "id",
  "sort[1]": "asc",
}

This might be related: https://github.com/krakenjs/hapi-openapi/issues/199

thebrownfox commented 2 years ago

Ok, my bad. For anyone who cannot find out why it's not working, you need to parse the params beforehand.

const server = new Hapi.Server({
    query: {
        parser: (query) => qs.parse(query),
    },
});
dcharbonnier commented 2 years ago

Maybe we should do somethig similat to this https://github.com/krakenjs/hapi-openapi/pull/211