Skip to content

feat: add type definition for format option in @ApiProperty decorator#3697

Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom
ismaildasci:feat/add-format-type-definition
Feb 4, 2026
Merged

feat: add type definition for format option in @ApiProperty decorator#3697
kamilmysliwiec merged 1 commit intonestjs:masterfrom
ismaildasci:feat/add-format-type-definition

Conversation

@ismaildasci
Copy link
Copy Markdown

@ismaildasci ismaildasci commented Jan 17, 2026

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #3508

Currently, the format option 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 OpenAPIFormat union type that provides:

  • IDE autocomplete for all standard OpenAPI and JSON Schema format values
  • Type safety to catch typos at compile time
  • Fallback to (string & {}) to still allow custom formats

Supported formats include:

  • OpenAPI data types: int32, int64, float, double, byte, binary
  • Date/time: date, date-time, time, duration
  • String formats: password, email, idn-email, hostname, idn-hostname, ipv4, ipv6, uri, uri-reference, uri-template, iri, iri-reference, uuid
  • JSON Schema: json-pointer, relative-json-pointer, regex

Does this PR introduce a breaking change?

  • Yes
  • No

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:

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
@kamilmysliwiec kamilmysliwiec merged commit b06e08a into nestjs:master Feb 4, 2026
1 check passed
@kamilmysliwiec
Copy link
Copy Markdown
Member

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants