@alt-stack/zod-openapi
v1.6.2
Published
Convert OpenAPI schemas to Zod schemas with TypeScript code generation
Maintainers
Readme
@alt-stack/zod-openapi
Generate TypeScript interfaces, Zod 4 schemas, and typed HTTP Request/Response maps from OpenAPI JSON.
Install
pnpm add zod
pnpm add -D @alt-stack/zod-openapiGenerate
zod-openapi ./openapi.json --output ./src/generated-api.tsinput may be a local JSON path or HTTP(S) URL. The CLI also supports --registry for executing custom schema registrations, --include for inserting required imports/definitions, and --help. It always emits route maps; programmatic generation opts in with includeRoutes.
import { openApiToZodTsCode } from "@alt-stack/zod-openapi";
const source = openApiToZodTsCode(document, undefined, {
includeRoutes: true,
});Generated files begin with a do-not-edit banner. Change the OpenAPI source, registry/include files, or generator options and regenerate the whole file.
