{"id":17657969,"url":"https://github.com/3rd/openapi-to-zod-schema","last_synced_at":"2026-02-04T01:37:35.113Z","repository":{"id":245749002,"uuid":"819133195","full_name":"3rd/openapi-to-zod-schema","owner":"3rd","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-26T21:30:39.000Z","size":106,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-17T07:09:11.875Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/3rd.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-06-23T21:47:06.000Z","updated_at":"2024-11-22T14:32:48.000Z","dependencies_parsed_at":"2024-06-23T21:55:14.596Z","dependency_job_id":"f4529244-4e4b-4b97-98cb-91915167ff90","html_url":"https://github.com/3rd/openapi-to-zod-schema","commit_stats":null,"previous_names":["3rd/openapi-to-zod-schema"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/3rd/openapi-to-zod-schema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Fopenapi-to-zod-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Fopenapi-to-zod-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Fopenapi-to-zod-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Fopenapi-to-zod-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/3rd","download_url":"https://codeload.github.com/3rd/openapi-to-zod-schema/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Fopenapi-to-zod-schema/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261153375,"owners_count":23116896,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-23T14:43:49.054Z","updated_at":"2026-02-04T01:37:35.105Z","avatar_url":"https://github.com/3rd.png","language":"TypeScript","readme":"# OpenAPI to Zod Schema\n\nThis package provides a CLI and library to convert OpenAPI schemas to Zod schemas and generate schema code.\n\n## Features\n\n- Convert OpenAPI schemas (YAML or JSON) to Zod schemas\n- Support for complex schema structures including `allOf`, `oneOf`, and `anyOf`\n- Handle references (`$ref`) in OpenAPI schemas\n- CLI tool for easy conversion from the command line\n- Support for both local files and remote URLs as input\n\n## Installation\n\nYou can install the package from [NPM](https://www.npmjs.com/openapi-to-zod-schema):\n\n```bash\n# install\nnpm i -D openapi-to-zod-schema\n\n# or run it directly\nnpx openapi-to-zod-schema https://raw.githubusercontent.com/openai/openai-openapi/refs/heads/manual_spec/openapi.yaml\nnpx openapi-to-zod-schema .openapi.yaml -o openai-schemas.ts\n```\n\n## Usage\n\n### As a Library\n\nYou can use the library in your project like this:\n\n```typescript\nimport { convertOpenAPISpecToZodSchemas, codegen } from \"openapi-to-zod-schema\";\n\nconst openAPISpec = {\n  components: {\n    // Your OpenAPI spec's components here\n  },\n};\n\nconst zodSchemas = convertOpenAPISpecToZodSchemas(openAPISpec);\nconsole.log(zodSchemas); // { items: [], map: Record\u003cname, {}\u003e }\n\n// Generate TypeScript code\nconst code = codegen(openAPISpec);\nconsole.log(code);\n```\n\n### As a CLI Tool\n\nYou can use the CLI wrapper to convert OpenAPI schemas to Zod schemas like this:\n\n```bash\nnpx openapi-to-zod-schema ./path/to/your/openapi-spec.yaml\n```\n\nOr for remote files:\n\n```bash\nnpx openapi-to-zod-schema https://example.com/path/to/openapi-spec.yaml\n```\n\nBy default, the CLI tool will output the generated Zod schema to the console. If you want to save it to a file, you can use the `-o` option:\n\n```bash\nnpx openapi-to-zod-schema ./path/to/your/openapi-spec.yaml -o ./output-schema.ts\n```\n\n## API Reference\n\n### `convertOpenAPISpecToZodSchemas(spec: OpenAPISpec): { map: Record\u003cstring, z.ZodTypeAny\u003e, items: Array\u003c{ name: string, schema: z.ZodTypeAny }\u003e }`\n\nConverts an OpenAPI specification to Zod schemas.\n\n- `spec`: The OpenAPI specification object.\n- Returns: An object containing:\n  - `map`: A record of schema names to their corresponding Zod schemas.\n  - `items`: An array of objects, each containing the schema name and the Zod schema.\n\nExample:\n\n```typescript\nconst { map, items } = convertOpenAPISpecToZodSchemas(openAPISpec);\n\nconsole.log(map.UserSchema); // Zod schema for User\nconsole.log(items[0]); // { name: 'User', schema: ZodSchema }\n```\n\n### `codegen(spec: OpenAPISpec): string`\n\nGenerates TypeScript code for the Zod schemas based on the OpenAPI specification.\n\n- `spec`: The OpenAPI specification object.\n- Returns: A string containing the generated TypeScript code.\n\nExample:\n\n```typescript\nconst code = codegen(openAPISpec);\nconsole.log(code);\n// Output: TypeScript code defining Zod schemas\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3rd%2Fopenapi-to-zod-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F3rd%2Fopenapi-to-zod-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3rd%2Fopenapi-to-zod-schema/lists"}