Skip to content

fix(document-builder): accept multi-digit OpenAPI version segments#3874

Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom
yogeshwaran-c:fix/document-builder-version-multi-digit
Apr 22, 2026
Merged

fix(document-builder): accept multi-digit OpenAPI version segments#3874
kamilmysliwiec merged 1 commit intonestjs:masterfrom
yogeshwaran-c:fix/document-builder-version-multi-digit

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix (DocumentBuilder).

What is the current behavior?

DocumentBuilder.setOpenAPIVersion validates its argument with:

if (version.match(/^\d\.\d\.\d$/)) {  }

The regex requires exactly one digit per segment. OpenAPI Specification versions follow semver — 3.0.x has already reached 3.0.4, a future 3.0.10 or 3.10.0 would be entirely valid — but any of those would be silently rejected today with only a warn-level log, and the default version on the document would be kept.

Minimal repro:

const builder = new DocumentBuilder().setOpenAPIVersion('3.0.10');
// builder.build().openapi is still the default (3.0.0), no error,
// only a WARN-level log: 'The OpenApi version is invalid. Expecting format \"x.x.x\"'

What is the new behavior?

Widened the regex to /^\d+\.\d+\.\d+$/, so each segment may contain any non-negative integer. Genuinely malformed inputs (3.0, 3.0.0-beta, …) still fall through to the existing warning.

Additional context

Added three unit-test cases to test/document-builder.spec.ts covering:

  • The previously-accepted single-digit case (3.1.0) — regression guard.
  • Multi-digit segments (3.0.10, 3.10.0, 10.20.30).
  • Malformed inputs, to confirm they still leave the default in place.

setOpenAPIVersion validated the argument with `/^\d\.\d\.\d$/`, which
requires exactly one digit per segment. OpenAPI spec versions follow
semver (e.g. `3.0.10`, `3.10.0`, and hypothetically `10.x.x`), so a
caller trying to set `3.0.10` was silently rejected and the default
was kept, with only a warn-level log to signal the failure.

Switch to `/^\d+\.\d+\.\d+$/` so each segment may have any number of
digits. Malformed inputs (`3.0`, `3.0.0-beta`, …) still fall through
to the existing warning.
@kamilmysliwiec kamilmysliwiec merged commit 188a043 into nestjs:master Apr 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants