I am working on a node.js server that uses the NestJS framework. I want to auto-build API documentation for the app using NestJS's swagger integration.
Documentation generated correctly for my controller methods that the utilized @Body()
approach for controller data exchange. It did not work correctly for controller methods that used the @Param()
approach. An example controller that fails to generate correct documentation:
@Get('/:identifier')
@RouteLogger()
@ApiParam({name: 'identifier', required: true, description: 'either an integer for the project id or a string for the project name', schema: { oneOf: [{type: 'string'}, {type: 'integer'}]}})
async getProject(
@Param('identifier')
identifier: string | number,
@Res() res: Response
) { }
This generates the following in the swagger UI:
You can see that the endpoint in swagger UI fails to show the endpoint having any parameters. What is the correct way of writing a GET endpoint for a nestJS controller with @Param
s such that swagger will correctly generate documentation?