feat: add type definition for format option in @ApiProperty decorator#3697
Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom Feb 4, 2026
Merged
Conversation
Add OpenAPIFormat union type that includes all standard OpenAPI and JSON Schema format values. This provides better IDE autocomplete and type safety when using the format option in @ApiProperty decorator. The type includes: - OpenAPI data type formats (int32, int64, float, double, byte, binary) - Date/time formats (date, date-time, time, duration) - String formats (password, email, hostname, ipv4, ipv6, uri, uuid, etc.) - JSON Schema formats (json-pointer, relative-json-pointer, regex) - Fallback to (string & {}) to allow custom formats while preserving autocomplete Fixes nestjs#3508
Member
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #3508
Currently, the
formatoption in@ApiProperty()accepts any string, which can lead to typos or unsupported formats being used without any TypeScript warning.What is the new behavior?
Added
OpenAPIFormatunion type that provides:(string & {})to still allow custom formatsSupported formats include:
int32,int64,float,double,byte,binarydate,date-time,time,durationpassword,email,idn-email,hostname,idn-hostname,ipv4,ipv6,uri,uri-reference,uri-template,iri,iri-reference,uuidjson-pointer,relative-json-pointer,regexDoes this PR introduce a breaking change?
Other information
The
(string & {})pattern is used to allow custom formats while still providing autocomplete suggestions for standard formats. This is a common TypeScript pattern for "string with suggestions".References: