@ApiPropertyBoolean
Applies Swagger metadata, validation decorators, and serialization logic for boolean DTO properties. Supports single values, arrays, nullable flags, and automatic coercion from strings or numbers.
Signature
@ApiPropertyBoolean(properties: TApiPropertyBaseProperties)Notable options
| Option | Description |
|---|---|
entity | Entity or factory returning the entity. Required so descriptions embed the entity name. |
description | Field description appended to Swagger docs. |
isRequired | Adds/omits IsOptional. |
isArray, minItems, maxItems, isUniqueItems | Enables boolean[] with array validation. |
isNullable | Sets Swagger nullable flag. |
isResponse, isExpose | Controls whether ApiResponseProperty, Expose, or Exclude are emitted for response DTOs. |
Behavior
- Adds
@ApiPropertymetadata with boolean schema details. - Applies
IsBoolean(with{ each: true }for arrays) and optionalIsArray,ArrayMinSize,ArrayMaxSize,ArrayNotEmpty. - Uses
class-transformerTransformto coerce"true"/"false","1"/"0", numeric values, and arrays of those representations into actual booleans. - Handles
isResponsedifferently by addingApiResponsePropertyand skipping request validators.
Example
class UserFilterDto {
@ApiPropertyBoolean({
entity: () => UserEntity,
description: "Active flag",
isRequired: false,
})
isActive?: boolean;
@ApiPropertyBoolean({
entity: () => UserEntity,
description: "Permission flags",
isArray: true,
minItems: 1,
maxItems: 5,
})
flags!: boolean[];
}Related resources
Last updated on