Closed
Description
Using @QueryParams()
decorator doesn't trigger any type conversion (notice the number
type) nor returns 400 for malformed/missing parameters:
class PagingOptions {
limit = 10;
}
@JsonController('/test')
export class TestController {
@Get('/foo')
getAll(@QueryParams() params: PagingOptions) {
console.log(params);
return {};
}
}
Call test/foo?limit=20
and console shows PagingOptions { limit: '20' }
(notice the string
type).
VS:
@JsonController('/test')
export class TestController {
@Get('/bar')
getAll2(@QueryParam('limit', { required: true }) limit: number) {
console.log(limit);
return {};
}
}
Returns 400: Bad request when limit
is missing; when present, it is converted to number
.