Skip to content

fix(swagger-explorer): prevent enum schema mutation across multiple document generations#3799

Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom
maruthang:fix/issue-2182-enum-schema-multi-doc
Apr 9, 2026
Merged

fix(swagger-explorer): prevent enum schema mutation across multiple document generations#3799
kamilmysliwiec merged 1 commit intonestjs:masterfrom
maruthang:fix/issue-2182-enum-schema-multi-doc

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

Summary

Fixes #2182

Bug: When generating two separate Swagger documents in the same process, enum query parameters were missing their schema ($ref pointed to an undefined component) in the second document.

Root Cause: SchemaObjectFactory.createEnumParam assigned directly to param.schema, mutating the object that is stored by reference inside Reflect decorator metadata. On the second document generation the metadata already had param.schema = { $ref } with no enum values, so the enum schema was never re-registered.

Fix: Instead of mutating param.schema in place, a shallow copy of param is spread with the new schema property before passing to omit. The original metadata object is never modified.

Changes

  • lib/services/schema-object-factory.ts: Replace param.schema = newSchema mutation with omit({ ...param, schema: newSchema }, [...]) spread to avoid mutating shared Reflect metadata.
  • test/explorer/swagger-explorer.spec.ts: Add regression test that runs exploreController twice with two separate SwaggerExplorer instances and asserts the enum schema is fully populated in both resulting documents.

Testing

  • Added regression test should generate enum schema on second document generation (multi-doc regression) in test/explorer/swagger-explorer.spec.ts that verifies the QueryEnum schema (with enum: [1, 2, 3]) is present after both the first and second document generation.
  • All 159 existing tests pass.

@kamilmysliwiec kamilmysliwiec merged commit 849cdaf into nestjs:master Apr 9, 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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enum schema missing information on multiple specifications

2 participants