Type |聽Version
ts-express-decorators|3.7.0
Question
How to make an optional path parameter using decorators? I used the following code that works well
with postman but doesn;t work with swagger :(
@Get('/:page/:offset')
@Returns(InventoryItem)
async getRecipe(@PathParams('page') page: number, @PathParams('offset') offset: number): Promise<InventoryItem[]> {
return await this.inventoryService.getAllInventoryItems(page, offset);
}
Just add ? to optional param:
@Get('/test/:required/:optional?')
test(@PathParams('required') requiredParam, @PathParams('optional') optionalParam) {
// your code
}
Yup I did that but it doesn't work right with the swagger
here's my code:
@Get('recipe/:page?/:offset?')
@Returns(Recipe)
async getRecipe(@PathParams('page') page: number, @PathParams('offset') offset: number): Promise
}
In swagger it creates 4 parametes, 2 with the names 'page?' and 'offset?' and 2 with the name 'page' and 'offset' (without the ?). Also when I try to execute it from swagger,
it hits the paremters with a '?' for eg.
http://localhost:3000/v1/recipe/0?/1?
Hi @haroon407,
Ok we have a little bug with the swagger description. Need to fix that :)
Thanks for the response :) looking forward to the next release