Commit ad31d4a
authored
fix(docs): parse Zod 4 function schemas in node API reference generator (#23798)
## 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.
`parseZodFunctionExpr` only recognized the **Zod 3** DSL:
```ts
z.function().args(BlockParameterSchema, schemas.Fr).returns(schemas.Fr)
```
After the repo-wide Zod 3 → 4 migration, every schema moved to the Zod 4
form:
```ts
getPublicStorageAt: z.function({
input: z.tuple([BlockParameterSchema, schemas.AztecAddress, schemas.Fr]),
output: schemas.Fr,
}),
```
There is no `.args(` / `.returns(` left, so `argsStart`/`returnsStart`
are `-1` and **every** method is emitted with `Parameters: None` and
`Returns: 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 `parseZodFunctionExpr` to read the Zod 4 `z.function({ input:
z.tuple([...]), output: <expr> })` object: it extracts the `input` tuple
elements as the parameter list and the `output` expression as the return
type, reusing the existing `simplifyZodType` mapping. The legacy
`.args().returns()` path is kept as a fallback so older versioned-docs
schemas still regenerate. Added small helpers `findMatchingBracket`,
`findTopLevelColon`, and `parseInputArgs`.
## 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:
```
PASS getPublicStorageAt (multi-arg tuple) -> [BlockHash|number|"latest", AztecAddress, Fr] / Fr
PASS getWorldStateSyncStatus (empty tuple) -> [] / WorldStateSyncStatus
PASS getTxReceipt (class.schema) -> [TxHash] / TxReceipt
PASS getPendingTxs (optionals + array output) -> [number|undefined, TxHash|undefined] / Tx[]
PASS getBlockNumber (optional ref + branded return) -> [ChainTip|undefined] / number
PASS registerContractFunctionSignatures (nested arr) -> [string[]] / void
PASS LEGACY Zod 3 .args().returns() -> [number, boolean|undefined] / void
7/7 passed
```
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-reference` requires
`yarn-project/node_modules`) or commit a regenerated
`node-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_GROUPS` lists removed methods (`getPublicLogs`,
`getContractClassLogs`, `getPublicLogsByTagsFromContract`) and omits
current ones (`getPrivateLogsByTags`, `getPublicLogsByTags`,
`getCheckpointNumber`, `getCheckpointsData`, `getValidatorStats`, …).
- `simplifyZodType` still maps deleted schemas (`LogFilterSchema`,
`GetPublicLogsResponseSchema`, `GetContractClassLogsResponseSchema`) and
lacks `LogResultSchema` / `PrivateLogsQuerySchema` /
`PublicLogsQuerySchema` / `TxReceiptSchema`.
The separate TypeScript API reference generator
(`typescript_api_generation/`) is unrelated to this bug.
---
*Created by
[claudebox](https://claudebox.work/v2/sessions/46be71fd1d38fe81) ·
group: `slackbot`*1 file changed
Lines changed: 97 additions & 9 deletions
Lines changed: 97 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
| 183 | + | |
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
193 | 196 | | |
194 | | - | |
195 | | - | |
196 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
197 | 200 | | |
198 | 201 | | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
205 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
206 | 236 | | |
207 | 237 | | |
208 | 238 | | |
| |||
215 | 245 | | |
216 | 246 | | |
217 | 247 | | |
218 | | - | |
219 | 248 | | |
220 | 249 | | |
221 | 250 | | |
| |||
228 | 257 | | |
229 | 258 | | |
230 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
231 | 288 | | |
232 | 289 | | |
233 | 290 | | |
| |||
244 | 301 | | |
245 | 302 | | |
246 | 303 | | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
247 | 335 | | |
248 | 336 | | |
249 | 337 | | |
| |||
0 commit comments