-
-
Notifications
You must be signed in to change notification settings - Fork 526
feat(fetch): add runtime validation support with zod schemas #2651
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
feat(fetch): add runtime validation support with zod schemas #2651
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces runtime validation support for the Fetch client using Zod schemas. When enabled, API responses are validated at runtime to ensure they match the expected types, throwing errors for type mismatches.
Key Changes:
- Added
runtimeValidationconfiguration option toFetchOptionsandNormalizedFetchOptions - Modified code generation to inject Zod schema parsing when runtime validation is enabled
- Primitive types (string, number, boolean, void) are excluded from validation
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/core/src/types.ts | Added runtimeValidation boolean field to Fetch type definitions |
| packages/orval/src/utils/options.ts | Added normalization logic for the new runtimeValidation option |
| packages/fetch/src/index.ts | Implemented runtime validation logic with Zod schema parsing in generated code |
| tests/configs/fetch.config.ts | Enabled runtimeValidation in test configurations alongside useZodSchemaResponse |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
How can I get runtime validation with the use of fetch and react-query? |
fix #2598
Summary
Added runtime validation feature for Fetch client using Zod schemas. This feature enables runtime verification that API responses match the expected types.
Details
Usage
Enable the
fetch.runtimeValidationoption in your configuration file:Generated Code
Response data is validated with Zod schemas, and runtime errors are thrown if types don't match. Primitive types (
string,number,boolean,void) are excluded from validation.