Closed VayKekaz closed 9 months ago
Providing default values for query parameters using myParam: HttpQuery<integer> = 0 syntax causes a bug where ValidationError is returned.
myParam: HttpQuery<integer> = 0
@http.controller() export class Controller { @http.GET() endpoint( limit?: HttpQuery<integer & Positive & Maximum<100>>, offset: HttpQuery<integer & Positive> = 0, ) { // invoking this endpoint without query params causes error: const errorCaused = { "message": "Validation error:\noffset(type): Cannot convert undefined to HttpQuery<number>", "errors": [ { "path": "offset", "code": "type", "message": "Cannot convert undefined to HttpQuery<number>" } ] } } }
Here is some workaround that i found is to use HttpQueries along with object deconstruction:
HttpQueries
@http.controller() export class Controller { @http.GET() endpoint( { limit = 10, offset = 0, }: HttpQueries<{ limit?: integer & Positive & Maximum<100> offset?: integer & Positive }>, ) { } }
Thanks for the report @VayKekaz , fixed in https://github.com/deepkit/deepkit-framework/commit/fa74d166d5421f8459f64c9b2339b9cf272a1b18
Providing default values for query parameters using
myParam: HttpQuery<integer> = 0
syntax causes a bug where ValidationError is returned.Here is some workaround that i found is to use
HttpQueries
along with object deconstruction: