routing-controllers-openapi
routing-controllers-openapi copied to clipboard
Not able to parse @QueryParams()
class SortOrder {
[index: string]: 'ASC' | 'DESC'
}
class Query {
@IsNumber()
readonly offset: number = 0;
@IsNumber()
readonly limit: number = 10;
@ValidateNested()
readonly order: SortOrder;
}
class Controller {
getAll(@QueryParams() query: Query) {
}
}
This example creates one field called query and displays it as json field.
Expected behavior is to have 3 query parameters: offset, limit and order. Order parameter should be of deepObject style.
Example query string:
?limit=10&offset=0&order[firstName]=DESC&order[lastName]=ASC
More info https://swagger.io/docs/specification/serialization/
Hi, that's bit of a tricky one. So we need to pass a style: "deepObject"
property to your Parameter object, and the library is currently lacking this feature, right? One option would be to add a global configuration parameter for defining query parameter style
and explode
, how'd that work out for you? Or can you think of a way of setting them per-parameter?
Also your SortOrder
class might be a problem since I'm not sure whether class-validator
can handle index signatures like [index: string]: ...
.
Thanks for taking the time to open up an issue!
This should actually be the default behavior. QueryParams
should be expanded because it represents the whole query object (or at least part of it) not just one query parameter. I'll take a look and maybe create a PR.
This is not possible now because routing-controllers-openapi
doesn't have information about schemas.
Do any work arounds exist for this at the moment?
I regenerate the parameters after the spec is generated. In short go through the whole spec and if I find a "query" parameter that has "$ref" set I lookup the schema and replace the parameter.
I regenerate the parameters after the spec is generated. In short go through the whole spec and if I find a "query" parameter that has "$ref" set I lookup the schema and replace the parameter.
Well that's the best option for now I guess. Thanks a lot.