@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
| Option | Type | Description |
|---|---|---|
entity | Type<T> | Entity used for automatic summary/description generation. |
action | EApiAction | Optional semantic hint that drives autogenerated summary and description strings. |
method | RequestMethod | HTTP method applied to the route. |
path | string | Route path passed to @Get, @Post, etc. |
httpCode | HttpStatus | Status code used for @HttpCode and default @ApiResponse. |
responseType | Type<unknown> | DTO or class used for the success response schema. |
authentication | IApiControllerPropertiesRouteAuthentication | Guard configuration (bearer strategies, @UseGuards, additional ApiSecurity/ApiBearerAuth decorators). |
responses | IApiResponseType | Enables standard error responses (401, 403, 404, 429, 400, 409, 500). |
throttler | IApiMethodThrottlerProperties | Adds @Throttle with limit and ttl. |
description | string | Overrides 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
ApiAuthorizationGuardalong with any custom guards specified inauthentication.guard. - Generates human-readable summaries/descriptions when
actionis 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);
}Related resources
Last updated on