Skip to Content

@ApiPropertyNumber

Adds Swagger metadata, validation, and serialization for numeric DTO properties. Supports integers, doubles, arrays, range limits, and multiple-of constraints with automatic example generation.

Signature

@ApiPropertyNumber(properties: TApiPropertyNumberProperties)

Notable options

OptionDescription
formatEApiPropertyNumberType.INTEGER or DOUBLE. Controls Swagger type/format and which validator (IsInt vs IsNumber) runs.
minimum / maximumValue bounds enforced with Min/Max. Required to derive example defaults.
multipleOfValidates divisibility (useful for currency increments).
exampleValueOptional; falls back to a random value within the provided range. Accepts single value or array when isArray is true.
isArray, minItems, maxItems, isUniqueItemsEnables numeric arrays with full validation.
isNullable, isRequired, isResponse, isExposeControl request validation, Swagger metadata, and serialization.

Behavior

  • Registers @ApiProperty with the appropriate type, format, minimum, maximum, and multipleOf.
  • Adds Type(() => Number) and Transform so incoming strings/numbers are coerced into numeric types.
  • Applies IsInt/IsNumber, IsDivisibleBy, IsOptional, IsArray, ArrayMinSize, ArrayMaxSize, and ArrayNotEmpty as needed.
  • Adds ApiResponseProperty plus Expose/Exclude when isResponse is enabled.

Example

class PriceDto { @ApiPropertyNumber({ entity: () => ProductEntity, description: "Price amount", format: EApiPropertyNumberType.DOUBLE, minimum: 0.01, maximum: 999999.99, multipleOf: 0.01, isRequired: true, }) price!: number; }
Last updated on