fix(swagger-explorer): prevent enum schema mutation across multiple document generations#3799
Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom Apr 9, 2026
Conversation
…ocument generations Closes nestjs#2182
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.
Summary
Fixes #2182
Bug: When generating two separate Swagger documents in the same process, enum query parameters were missing their schema (
$refpointed to an undefined component) in the second document.Root Cause:
SchemaObjectFactory.createEnumParamassigned directly toparam.schema, mutating the object that is stored by reference insideReflectdecorator metadata. On the second document generation the metadata already hadparam.schema = { $ref }with noenumvalues, so the enum schema was never re-registered.Fix: Instead of mutating
param.schemain place, a shallow copy ofparamis spread with the newschemaproperty before passing toomit. The original metadata object is never modified.Changes
lib/services/schema-object-factory.ts: Replaceparam.schema = newSchemamutation withomit({ ...param, schema: newSchema }, [...])spread to avoid mutating shared Reflect metadata.test/explorer/swagger-explorer.spec.ts: Add regression test that runsexploreControllertwice with two separateSwaggerExplorerinstances and asserts the enum schema is fully populated in both resulting documents.Testing
should generate enum schema on second document generation (multi-doc regression)intest/explorer/swagger-explorer.spec.tsthat verifies theQueryEnumschema (withenum: [1, 2, 3]) is present after both the first and second document generation.