-
-
Notifications
You must be signed in to change notification settings - Fork 526
feat(core): output.schemas now allows you to select zod as the schema type
#2644
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(core): output.schemas now allows you to select zod as the schema type
#2644
Conversation
This reverts commit ef35515.
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 adds support for Zod schema generation alongside TypeScript type definitions through an enhanced output.schemas configuration option. Users can now specify the schema type (typescript or zod) and generate multiple schema types simultaneously. This addresses issue #2598 by providing a unified interface for schema generation that supports both TypeScript and Zod outputs.
Key changes:
- Extended
schemasoption to accept either a string path (existing behavior) or an object withpathandtypeproperties - Implemented Zod schema file generation with
.zod.tsextension - Added support for generating multiple schema types via array configuration
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/types.ts | Added SchemaGenerationType, SchemaOptions types and updated schema-related type definitions |
| packages/orval/src/utils/options.ts | Added normalizeSchemasOption function to handle new schema configuration format |
| packages/orval/src/write-specs.ts | Extended schema writing logic to support both TypeScript and Zod generation based on configuration |
| packages/orval/src/write-zod-specs.ts | New file implementing Zod schema generation with proper imports and type inference |
| packages/zod/src/index.ts | Exported dereference function and isZodVersionV4 for use in Zod schema generation |
| packages/core/src/generators/schema-definition.ts | Added OpenAPI schema object to GeneratorSchema type for Zod processing |
| packages/core/src/generators/interface.ts | Included schema object in interface generation output |
| packages/orval/src/import-open-api.ts | Added spec to WriteSpecBuilder for schema reference resolution |
| packages/core/src/writers/*.ts | Updated all writer modes to handle new schema configuration format |
| tests/configs/default.config.ts | Added test configurations for typescript-only, zod-only, and combined schema generation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fix #2598
Summary
Extended the
schemasconfiguration option to support both TypeScript type definitions and Zod schema generation through a unified interface. Users can now specify the schema generation type (typescriptorzod) along with the output path, and can generate multiple schema types simultaneously using array configuration.Details
1: Existing Behavior
Generated Files:
./model/pet.ts./model/dog.ts2: TypeScript Schema Generation
same behavior as existing.
Generated Files:
./model/pet.ts./model/dog.ts3: Zod Schema Generation
Generated Files:
./model/pet.zod.ts./model/dog.zod.ts4: Multiple Schema Types
I'm not sure if it's necessary to specify both "typescript" and "zod" as the type. Therefore, I may stop supporting specifying multiple types as an array.
Generated Files:
./model/pet.ts./model/dog.ts./model/pet.zod.ts./model/dog.zod.ts