@ApiPropertyEnum
Documents and validates DTO fields that map to TypeScript enums. Supports string or numeric enums, single values or arrays, and automatically lists all enum members in Swagger.
Signature
@ApiPropertyEnum(properties: TApiPropertyEnumProperties)Required configuration
| Option | Description |
|---|---|
enum | The enum object (e.g., UserRole). Used for Swagger enum values and validation. |
enumName | Optional explicit name shown in Swagger schema when using barrel exports. |
description, entity, isRequired, isNullable | Same semantics as other property decorators. |
exampleValue | Optional; defaults to the first enum value (or an array if isArray is true). |
isArray, minItems, maxItems, isUniqueItems | Enable enum arrays with array validation. |
Behavior
- Adds
@ApiPropertywith the enum schema and example value. Arrays automatically exposeitems. - Applies
IsEnum,IsOptional, and array validators for request DTOs. - Emits
ApiResponseProperty,Expose, orExcludewhenisResponseistrue.
Example
enum UserRole {
ADMIN = "admin",
USER = "user",
}
class UserDto {
@ApiPropertyEnum({
entity: () => UserEntity,
description: "User role",
enum: UserRole,
enumName: "UserRole",
isRequired: true,
})
role!: UserRole;
}Related resources
Last updated on