-
-
Notifications
You must be signed in to change notification settings - Fork 274
Feature: Add Zod v4 .meta() Support for Enhanced OpenAPI Metadata #3028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This enables local meta support. No breaking changes on the api. Also parses examples for previous global registry.
Parameter examples have not been extracted. Also places examples in "example" meta attribute instead of "examples" as this is utilized by zod v4s built-in support for generating OpenAPI schemas.
This is a somewhat breaking change. Previously, the deprecated and description field have been overwritten by the schema property of parameters. This leads to parameters that were marked as deprecated on the parameter-level to not be marked as deprecated in the generated output IF the schema was not marked as deprecated. Local configuration should overwrite schema configuration. This is a breaking change, as it introduces different (valid) documentation compared to how it was handled previously. The general runtime of outputs should not be affected.
There has been an issue that incorrecly parses schema-level descriptions instead of parameter level ones and example values
|
|
|
|
Someone is attempting to deploy a commit to the Hey API Team on Vercel. A member of the Team first needs to authorize it. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3028 +/- ##
==========================================
+ Coverage 33.01% 34.45% +1.43%
==========================================
Files 426 426
Lines 32792 32907 +115
Branches 2126 2289 +163
==========================================
+ Hits 10827 11337 +510
+ Misses 21937 21542 -395
Partials 28 28
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:
|
To reach required test coverage we need to export some private methods form the parameter files
commit: |
|
@willsamu I don't understand the motivation for this pull request? |
|
@mrlubos I assumed that using the However, this PR contains two more things that were added/fixed along the way:
How should we proceed? As the meta decorator does not offer any additional functionality to users, we could remove it from the PR if you prefer to not add it to the codebase. It would be good to get the other two points merged though |
|
@willsamu though I'm not sure about the global vs local metadata naming, I actually wouldn't mind it if some people prefer it. The main issue is the pull request is 100% vibe coded and needs manual clean up. There are many obvious flags, such as using
The only thing I don't like is the metadata construction logic. It's just as arbitrary as the current output but it also fragments implementations, so I'd remove that. tl;dr
If you can split it into 3 separate pull requests, 1 and 2 are definitely things we'd want to merge, 3 is low priority so up to you. Maybe we could add a resolver for 3 and let people define |

Motivation
We utilize Zod as an internal validation tool for our API. The upstream API spec is partially republished (in adapted ways) as part of our client-facing API. For this purpose, we leverage Zod v4's OpenAPI conversion capabilities. It is critical that the
.meta()field is populated correctly for values that we pass down 1:1, enabling proper documentation generation and API specification accuracy.Key Changes
1. Zod v4
.meta()Support (Main Feature).meta()method as an alternative to the global registry patternmetadata: 'local'uses.meta()directly on schemas (Zod v4 API)metadata: 'true'ormetadata: 'global'continues to use.register(z.globalRegistry, ...).meta()approach better leverages Zod's native API and capabilities2. Fix: Parameter Attribute Precedence 🐛
Breaking behavior fix (not a breaking change in functionality):
Previously, parameter-level attributes (
description,deprecated) were incorrectly overwritten by schema-level attributes. This has been corrected to follow proper OpenAPI precedence rules:description,deprecatedExample of the fix:
3. Enhancement: Parameter Examples Support ✨
Added support for extracting and parsing examples from parameter definitions:
example(singular) andexamples(plural/object) fieldsexamplesobject format to arrays for Zod consumptionexamplesfield as per OpenAPI spec. We convert all examples to singularexampleform as an array. While slightly incorrect per spec, this is an acceptable tradeoff - better to have examples in a slightly incorrect format than no examples at all.4. Documentation & Tests
docs/openapi-ts/plugins/zod.md:243-244'local'and'global')specs/3.0.x/validators-parameter-example.yaml(parameter examples)specs/3.1.x/validators-metadata-enhanced.yaml(enhanced metadata with title, deprecated, examples)Breaking Changes
None - This is purely additive functionality with bug fixes:
metadata: 'local'option (opt-in)metadata: trueandmetadata: 'global'continue workingdescription anddeprecated` fix corrects invalid behavior (fix of documentation behaviour, not breaking change or validation or runtime behaviour)Testing
All changes are covered by snapshot tests across multiple scenarios:
Note on Contribution Process
I did not find a formal contribution process (e.g., opening issues beforehand), so I proceeded directly with implementing this feature. Happy to adjust the approach if there are preferred contribution guidelines.