Skip to content

feat(decorators): support RegExp instances in @ApiProperty({ pattern })#3787

Open
temrjan wants to merge 1 commit intonestjs:masterfrom
temrjan:feat/support-regexp-pattern-in-api-property
Open

feat(decorators): support RegExp instances in @ApiProperty({ pattern })#3787
temrjan wants to merge 1 commit intonestjs:masterfrom
temrjan:feat/support-regexp-pattern-in-api-property

Conversation

@temrjan
Copy link
Copy Markdown

@temrjan temrjan commented Mar 28, 2026

Summary

  • Automatically convert RegExp instances to their .source string when passed to @ApiProperty({ pattern })
  • Extend SchemaObjectCommonMetadata to accept pattern?: string | RegExp
  • Fully backward compatible — string values work as before

Test plan

  • All 158 tests pass (16 suites)
  • Build (tsc) passes with no new errors
  • Zero new any types introduced
  • Edge cases verified: null, undefined, string, empty RegExp — all safe via instanceof RegExp

Fixes #3719

🤖 Generated with Claude Code

Automatically extract .source from RegExp values passed to the pattern
option, so developers can use @ApiProperty({ pattern: /^[a-z]+$/ })
instead of manually calling .source.

Fixes nestjs#3719

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support RegExp instances in @ApiProperty({ pattern })

1 participant