Skip to content

fix(zod): restore file context before each processZodNode call in preprocessAllSchemasInFile#148

Open
daniel-rose wants to merge 1 commit intotazo90:mainfrom
daniel-rose:fix/zod-spread-properties-lost-with-imports
Open

fix(zod): restore file context before each processZodNode call in preprocessAllSchemasInFile#148
daniel-rose wants to merge 1 commit intotazo90:mainfrom
daniel-rose:fix/zod-spread-properties-lost-with-imports

Conversation

@daniel-rose
Copy link
Copy Markdown
Contributor

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, and this.currentImports were set once before the traversal began. When processZodNode resolved an imported schema it triggered a recursive call to preprocessAllSchemasInFile for that imported file, which overwrote those three fields. After returning from the recursive call, subsequent processZodNode invocations in the original file used the wrong file context — resolveConstObjectNode searched in the imported file and found nothing, so every spread was silently dropped.

Fix: Restore this.currentFilePath, this.currentAST, and this.currentImports immediately before each processZodNode call inside both traversal visitors (ExportNamedDeclaration and VariableDeclaration) so the correct context is always active regardless of what recursive preprocessing happened in between.

Closes #147

Type of Change

  • 🐛 fix: Bug fix

Checklist

  • pnpm check passes
  • Tested locally (pnpm test and pnpm build when relevant)
  • Documentation updated (if needed)

…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
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.

Spread properties lost when base shape shares file with imported schemas

1 participant