@Field
Use @Field for properties exposed in request or response schemas. The decorator infers primitive types from TypeScript metadata and accepts Swagger property options such as description, example, nullable, minLength, maxLength, minimum, maximum, and enum.
todo-item-input.dto.ts
Automatic validation
@Field adds the following class-validator decorators. Enable Nest’s request transformation and validation with ValidationPipe({ transform: true }) to apply them to incoming requests.
Set
nullable: true on optional update properties. An explicit required option overrides the required/optional behavior inferred from nullable and default. A default documents the default and supplies a Swagger example; it does not assign a value to the DTO property at runtime.
Use these options to customize the automatic behavior:
skipRequired: trueomits bothIsNotEmpty()andIsOptional(). Other validators still run, including on missing values.skipIsEnum: trueomitsIsEnum(). Type and other validators still apply.forceArray: truewraps a non-null scalar in an array before validation when the return type is an array. Without it,IsArray()rejects scalar input.
each: true for arrays. The length and numeric-bound validators do not; add your own class-validator decorators with { each: true } when you need those constraints on individual elements. To require a nonempty array, use minItems: 1.
Validation runs on transformed values. The decorator adds class-transformer’s Type() for resolved types other than Boolean, so numeric strings and date strings can become numbers and Date instances before validation. Boolean fields explicitly convert the strings 'true' and 'false' to booleans.
Other Swagger options describe the schema without necessarily adding runtime checks. Add decorators such as @IsEmail(), @IsUUID(), or @Matches() when you need those validations; setting format or pattern alone does not add them.
@FilterableField
@FilterableField includes the property in the schema just like @Field and exposes it as an equality query parameter on collection and export endpoints.
todo-item.dto.ts
filterRequired: truemakes the query parameter mandatory whenever the generated filter is used.filterOnly: trueaccepts the property as a filter but excludes it from serialized response fields.filterDecoratorsapplies additional decorators to the generated query property.- Standard
Field/Swagger options control transformation and validation.
@IDField
@IDField identifies the property used by GET, PUT, and DELETE single-record routes. Declare it on the response DTO so the generated :id parameter is transformed to the correct type.
idOnly: true when an identifier should be accepted as a route parameter but omitted from generated mutation bodies.
@QueryOptions
Use @QueryOptions to set collection defaults on the DTO. Endpoint-level options override decorator options.