feat: zod as response transformer#3847
Conversation
|
|
|
|
@SukkaW is attempting to deploy a commit to the Hey API Team on Vercel. A member of the Team first needs to authorize it. |
|
TL;DR — Extends the Key changes
Summary | 164 files | 5 commits | base:
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3847 +/- ##
==========================================
- Coverage 39.58% 39.51% -0.08%
==========================================
Files 532 533 +1
Lines 19581 19619 +38
Branches 5835 5850 +15
==========================================
+ Hits 7751 7752 +1
- Misses 9582 9613 +31
- Partials 2248 2254 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Important
Two design-level observations worth discussing before this merges. Neither is a correctness bug, but both affect maintainability.
Overall the approach is sound — the config normalization, plugin dispatch, and generated output all look correct. The snapshot coverage is thorough across all spec versions and compat modes. The boilerplate snapshot files (client scaffolding, utils, core modules) are standard generated code that doesn't change between the existing and new test scenarios.
| paramsStructure: 'grouped', | ||
| responseStyle: 'fields', | ||
| transformer: false, | ||
| transformer: { response: false }, |
There was a problem hiding this comment.
Minor: defaultConfig uses the normalized form { response: false } here, whereas validator on the next line uses the un-normalized false. Both work because resolveConfig handles normalization, but it's slightly inconsistent. Not blocking — just a readability note.
@hey-api/codegen-core
@hey-api/json-schema-ref-parser
@hey-api/nuxt
@hey-api/openapi-ts
@hey-api/shared
@hey-api/spec-types
@hey-api/types
@hey-api/vite-plugin
commit: |
|
Acknowledged that the outer type guard in Task list (2/2 completed)
|
|
Acknowledged the author's reply on the Task list (3/3 completed)
|

Fixes #3289
This PR extends the
@hey-api/sdkplugin'stransformeroption to accept'zod'. Whenzodis used as a transformer, itsparseAsyncreturn value is forwarded asresponseTransformeron the generated request options — enabling Zod's coercion and transformation rules (e.g.z.coerce.date()) to apply to response data.The PR changes the following things:
New
transformershapesEnabling
transformeroption as object form allows us to expand transformer abilities to request in the future.Zod plugin as transformer
@hey-api/transformerspath (existing): a named async transformer function is code-gen'd and passed as a reference toresponseTransformer.zodpath (new): the zod plugin now exposes acreateResponseTransformermethod. During code-gen we will check if the plugin exposes this method, and use that to generate an inline arrow function forresponseTransformer. In this case, we generate aparseAsynccall.Updated test snapshots
The test cases for this change uses the
type-format.yamlspec (which has anint64field) withtransformer: 'zod'andvalidator: true. The generated output lives in__snapshots__/3.1.x/{v3,v4,mini}/zod-transformer/.Two snapshot files are worth looking at:
zod.gen.ts— the generated Zod schema. Theint64field becomesz.coerce.bigint(), meaningparseAsyncwill coerce the raw wire value into a realBigInt:sdk.gen.ts— the generated SDK function. Three request options are present:The PR introduces no breaking changes:
transformer: falsebehaviour is unchanged.transformer: trueandtransformer: '@hey-api/transformers'continue to work exactly as before.validatorconfiguration is untouched.