fix(docs): parse Zod 4 function schemas in node API reference generator#23798
Merged
Conversation
critesjosh
approved these changes
Jun 2, 2026
Collaborator
Author
Flakey Tests🤖 says: This CI run detected 1 tests that failed, but were tolerated due to a .test_patterns.yml entry. |
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.
Motivation
The Node JSON-RPC API reference generator (
docs/scripts/node_api_reference_generation/generate_node_api_reference.ts) does not instantiate Zod at runtime — it string-parses the schema source (AztecNodeApiSchema = { ... }) via the TypeScript compiler API.parseZodFunctionExpronly recognized the Zod 3 DSL:After the repo-wide Zod 3 → 4 migration, every schema moved to the Zod 4 form:
There is no
.args(/.returns(left, soargsStart/returnsStartare-1and every method is emitted withParameters: NoneandReturns: void. It does not throw — it silently produces a useless reference. This is the breakage referenced in #23660 ("the node-api-reference generator is currently incompatible with the repo's Zod 4 schemas — a pre-existing issue affecting all methods"); it predates that PR and stems from the Zod 4 migration (the generator last regenerated cleanly in #22934, when schemas were still Zod 3).Approach
Rewrote
parseZodFunctionExprto read the Zod 4z.function({ input: z.tuple([...]), output: <expr> })object: it extracts theinputtuple elements as the parameter list and theoutputexpression as the return type, reusing the existingsimplifyZodTypemapping. The legacy.args().returns()path is kept as a fallback so older versioned-docs schemas still regenerate. Added small helpersfindMatchingBracket,findTopLevelColon, andparseInputArgs.Verification
The only changed logic is the pure expression parser, so I unit-tested the actual functions (loaded from this file) against real schema strings copied verbatim from
aztec-node.ts, plus a legacy Zod 3 string:Red→green: pre-fix, the same parser returns
{ paramTypes: [], returnType: "void" }for every Zod 4 string.Not done in this PR (needs the built monorepo): I did not run the full generator end-to-end (
yarn generate:node-api-referencerequiresyarn-project/node_modules) or commit a regeneratednode-api-reference.md. A maintainer/CI should run the generator and commit the refreshed reference as a follow-up.Out of scope (follow-ups)
The generator's static tables have also drifted from the current RPC surface and will produce misplaced/ungrouped output even after this parser fix — kept separate to keep this change focused:
METHOD_GROUPSlists removed methods (getPublicLogs,getContractClassLogs,getPublicLogsByTagsFromContract) and omits current ones (getPrivateLogsByTags,getPublicLogsByTags,getCheckpointNumber,getCheckpointsData,getValidatorStats, …).simplifyZodTypestill maps deleted schemas (LogFilterSchema,GetPublicLogsResponseSchema,GetContractClassLogsResponseSchema) and lacksLogResultSchema/PrivateLogsQuerySchema/PublicLogsQuerySchema/TxReceiptSchema.The separate TypeScript API reference generator (
typescript_api_generation/) is unrelated to this bug.Created by claudebox · group:
slackbot