Skip to Content

@ApiMethod

@ApiMethod wraps NestJS route metadata, throttling, guards, and Swagger decorators into a single helper for bespoke controller methods. Use it when you need endpoints that fall outside the auto-generated CRUD set but must preserve the same documentation and guard conventions.

Signature

@ApiMethod<T extends IApiBaseEntity>(options: IApiMethodProperties<T>)

Options

OptionTypeDescription
entityType<T>Entity used for automatic summary/description generation.
actionEApiActionOptional semantic hint that drives autogenerated summary and description strings.
methodRequestMethodHTTP method applied to the route.
pathstringRoute path passed to @Get, @Post, etc.
httpCodeHttpStatusStatus code used for @HttpCode and default @ApiResponse.
responseTypeType<unknown>DTO or class used for the success response schema.
authenticationIApiControllerPropertiesRouteAuthenticationGuard configuration (bearer strategies, @UseGuards, additional ApiSecurity/ApiBearerAuth decorators).
responsesIApiResponseTypeEnables standard error responses (401, 403, 404, 429, 400, 409, 500).
throttlerIApiMethodThrottlerPropertiesAdds @Throttle with limit and ttl.
descriptionstringOverrides the auto-generated description.

Behavior

  • Applies NestJS HTTP method decorators plus @HttpCode.
  • Emits Swagger decorators for the success response and any enabled error responses.
  • Automatically applies ApiAuthorizationGuard along with any custom guards specified in authentication.guard.
  • Generates human-readable summaries/descriptions when action is provided.

Example

@Get("users/:id/activate") @ApiMethod<UserEntity>({ entity: UserEntity, action: EApiAction.CONFIRMATION, description: "Activates a pending user account.", method: RequestMethod.POST, path: "users/:id/activate", httpCode: HttpStatus.OK, responseType: ActivateUserResponseDto, authentication: { type: EApiAuthenticationType.BEARER, guard: JwtAuthGuard, bearerStrategies: ["access-token"], }, throttler: { limit: 5, ttl: 60 }, responses: { hasBadRequest: true, hasUnauthorized: true, hasForbidden: true }, }) activate(@Param("id") id: string) { return this.service.activate(id); }
Last updated on