nurikabe
nurikabe

Reputation: 4010

Reusable parameters NestJS OpenAPI

Does the NestJS OpenAPI/Swagger implementation support reuse of common parameters?

This would save me from having to litter my endpoint with identical @ApiImplicitQuery decorators.

Upvotes: 0

Views: 452

Answers (1)

Kim Kern
Kim Kern

Reputation: 60357

You could just create your own reusable decorator:

const ApiRoleQuery = ApiImplicitQuery({
  name: 'role',
  enum: ['Admin', 'Moderator', 'User'],
});

and then use it in your controller:

@ApiRoleQuery
@Get()
async filterByRole(@Query('role') role) {
  // ...
}

Upvotes: 2

Related Questions