#ApiParam rename id property

5 messages · Page 1 of 1 (latest)

tall orchid
#

Hello everyone. I'm new to nestjs and I faced an interesting issue that I struggle with.
I want to use a dto to validate params id property. The problem is that not every route handler uses its own id. I have a settings route that returns settings for a given facility by facilityId. The problem is that nestjs/swagger generates docs with the /id instead of the /facilityId. Is there any way to rename this property in each route handler or provide a description to swagger. Because DTO is reusable, but it's not obvious what exact id you should provide. I know that its probably the bad practice to structure your endpoint like this, but still.

export class FindOneParams {
  @IsNumberString()
  id: number;
}

@Get(':id')
@ApiParam({ name: 'id', type: String })
async findOne(@Param() { id: facilityId }: FindOneParams) {}
#

Here's an example. I want to use a single DTO for validation of the id, but rename it to whatever id based on the endpoint, for better communication of which exact id the user needs to provide.

light estuary
#

Try this

@ApiParam({ name: 'facilityId', type: String })
tall orchid
light estuary
#
@Get(':facilityId')
@ApiParam({ name: 'facilityId', type: String })
async findOne(@Param() { facilityId }: FindOneParams) {}