fix(zod): restore file context before each processZodNode call in preprocessAllSchemasInFile#148
Open
daniel-rose wants to merge 1 commit intotazo90:mainfrom
Conversation
…processAllSchemasInFile Resolves a bug where spread properties from a non-exported base shape were silently dropped when the same file imported external schemas. Recursive calls to preprocessAllSchemasInFile (triggered by resolving imported schemas) overwrote this.currentFilePath, this.currentAST, and this.currentImports. Subsequent processZodNode calls then searched for const objects in the wrong file context and returned null, causing all spread properties to be omitted from the generated OpenAPI output. Fixes tazo90#147
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.
Description
Fixes a bug where spread properties from a non-exported base shape were silently dropped from the generated OpenAPI output when the same schema file also imported external schemas.
Root cause: In
preprocessAllSchemasInFile,this.currentFilePath,this.currentAST, andthis.currentImportswere set once before the traversal began. WhenprocessZodNoderesolved an imported schema it triggered a recursive call topreprocessAllSchemasInFilefor that imported file, which overwrote those three fields. After returning from the recursive call, subsequentprocessZodNodeinvocations in the original file used the wrong file context —resolveConstObjectNodesearched in the imported file and found nothing, so every spread was silently dropped.Fix: Restore
this.currentFilePath,this.currentAST, andthis.currentImportsimmediately before eachprocessZodNodecall inside both traversal visitors (ExportNamedDeclarationandVariableDeclaration) so the correct context is always active regardless of what recursive preprocessing happened in between.Closes #147
Type of Change
Checklist
pnpm checkpassespnpm testandpnpm buildwhen relevant)