A TypeScript utility that converts OpenAPI/Swagger specifications into Zod schemas. This tool helps you automatically generate type-safe validation schemas from your OpenAPI definitions.
- Converts OpenAPI schemas to Zod schemas
- Supports external schema references
- Handles circular dependencies
- Supports complex schema types including:
- oneOf, allOf, anyOf
- Enums
- Arrays and Objects
- References ($ref)
- Custom formats (e.g., date-time)
- Generates TypeScript types from schemas
- Preserves schema descriptions
Install the package using npm:
npm install @flatfile/openapi-to-zod
- Build the project using the build script
- Run the converter by pointing it to your OpenAPI YAML file
- Find your generated schemas in
generated-schemas.ts
- External References: Handles
$ref
references to external YAML files - Circular Dependencies: Safely handles circular references in schemas
- Type Generation: Automatically generates TypeScript types using Zod's inference
- Schema Validation: Creates runtime validation schemas using Zod
- Description Preservation: Maintains schema descriptions in the generated output
- Clone the repository
- Install dependencies
- Make your changes
- Build the project
yaml
: YAML parsingchange-case
: Case transformation utilitieszod
: Schema validation library (peer dependency)typescript
: TypeScript support
ISC
Contributions are welcome! Please feel free to submit a Pull Request.