Skip to Content

@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

OptionDescription
entityEntity or factory returning the entity. Required so descriptions embed the entity name.
descriptionField description appended to Swagger docs.
isRequiredAdds/omits IsOptional.
isArray, minItems, maxItems, isUniqueItemsEnables boolean[] with array validation.
isNullableSets Swagger nullable flag.
isResponse, isExposeControls whether ApiResponseProperty, Expose, or Exclude are emitted for response DTOs.

Behavior

  • Adds @ApiProperty metadata with boolean schema details.
  • Applies IsBoolean (with { each: true } for arrays) and optional IsArray, ArrayMinSize, ArrayMaxSize, ArrayNotEmpty.
  • Uses class-transformer Transform to coerce "true"/"false", "1"/"0", numeric values, and arrays of those representations into actual booleans.
  • Handles isResponse differently by adding ApiResponseProperty and 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[]; }
Last updated on