{"_id":"@btfash/openapi-to-zod-schema","_rev":"3-d484895a4009488ff42ddad48d2c12b2","name":"@btfash/openapi-to-zod-schema","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0-semantic-release.0":{"name":"@btfash/openapi-to-zod-schema","version":"1.0.0-semantic-release.0","license":"MIT","_id":"@btfash/openapi-to-zod-schema@1.0.0-semantic-release.0","maintainers":[{"name":"the-tablet","email":"i.am.the.tablet@proton.me"}],"bin":{"openapi-to-zod-schema":"dist/cli.cjs"},"dist":{"shasum":"56ad214943c4c9a94dd00c238a70b4434447fbe8","tarball":"https://registry.npmjs.org/@btfash/openapi-to-zod-schema/-/openapi-to-zod-schema-1.0.0-semantic-release.0.tgz","fileCount":12,"integrity":"sha512-n5Awd1N4aluy600K3qexWpEr5Oi/5japtfmlUduQjYlxNuIFtq8RvRoLIBY7uxhKDy1wE0o4eORCYagMTz0VPw==","signatures":[{"sig":"MEUCIHy9TuoZqM0CoczL2r85k/pkIkCPNGqQOufhJ6GM6uwLAiEA5TSderBXeU/aeUC5DEeb4ObATsUtN2WMctKmqwzEEWE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":691657},"main":"dist/index.mjs","type":"module","types":"dist/index.d.ts","shasum":"56ad214943c4c9a94dd00c238a70b4434447fbe8","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.ts","default":"./dist/index.cjs"}}},"scripts":{"tsc":"tsc","test":"jest","build":"bun run clean && bun src/scripts/build.mjs && tsc -p tsconfig.build.json","clean":"rm -rf dist","prepublishOnly":"bun run build && bun run tsc && bun run test"},"_npmUser":{"name":"the-tablet","email":"i.am.the.tablet@proton.me"},"prettier":{"semi":true,"useTabs":false,"tabWidth":2,"printWidth":120,"quoteProps":"as-needed","arrowParens":"always","singleQuote":false,"trailingComma":"es5","bracketSpacing":true,"jsxBracketSameLine":false},"_integrity":"sha512-n5Awd1N4aluy600K3qexWpEr5Oi/5japtfmlUduQjYlxNuIFtq8RvRoLIBY7uxhKDy1wE0o4eORCYagMTz0VPw==","repository":"https://github.com/frankstolle/openapi-to-zod-schema","_npmVersion":"10.8.3","directories":{},"lint-staged":{"*":"prettier --ignore-unknown --write"},"_nodeVersion":"24.3.0","dependencies":{"yaml":"^2.4.5"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","husky":"^9.0.11","esbuild":"^0.21.5","ts-jest":"^29.1.5","prettier":"^3.3.2","typescript":"^5.5.2","@types/jest":"^29.5.12","@types/node":"^20.14.8","lint-staged":"^15.2.7","@commitlint/cli":"^19.3.0","semantic-release":"^24.0.0","@semantic-release/git":"^10.0.1","@semantic-release/changelog":"^6.0.3","@commitlint/config-conventional":"^19.2.2"},"peerDependencies":{"zod":"^4.1.12"},"_npmOperationalInternal":{"tmp":"tmp/openapi-to-zod-schema_1.0.0-semantic-release.0_1762579482327_0.14721703242507056","host":"s3://npm-registry-packages-npm-production"}},"1.0.1-semantic-release.0":{"name":"@btfash/openapi-to-zod-schema","version":"1.0.1-semantic-release.0","license":"MIT","_id":"@btfash/openapi-to-zod-schema@1.0.1-semantic-release.0","maintainers":[{"name":"the-tablet","email":"i.am.the.tablet@proton.me"}],"bin":{"openapi-to-zod-schema":"dist/cli.cjs"},"dist":{"shasum":"b0564a00a455782199119f1b11c5a10147d2e575","tarball":"https://registry.npmjs.org/@btfash/openapi-to-zod-schema/-/openapi-to-zod-schema-1.0.1-semantic-release.0.tgz","fileCount":12,"integrity":"sha512-nZxgZ1tgL8DPA3nPytjCvCO8uJejzGGSSwJDL1Tc6RDNNBB6iDAKcUzQW9v2yNoGyim2sHGenfONO+yVrplB6w==","signatures":[{"sig":"MEYCIQDYSK18Kng6j06Zwu1w+GexUIWKEy52RZnqAF1cP22dggIhALmU4+nIbt+sPrN3bvVhF+vkblsnPorTqUuNo4u1M2UX","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":692457},"main":"dist/index.mjs","type":"module","types":"dist/index.d.ts","shasum":"b0564a00a455782199119f1b11c5a10147d2e575","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.ts","default":"./dist/index.cjs"}}},"scripts":{"tsc":"tsc","test":"jest","build":"bun run clean && bun src/scripts/build.mjs && tsc -p tsconfig.build.json","clean":"rm -rf dist","prepublishOnly":"bun run build && bun run tsc && bun run test"},"_npmUser":{"name":"the-tablet","email":"i.am.the.tablet@proton.me"},"prettier":{"semi":true,"useTabs":false,"tabWidth":2,"printWidth":120,"quoteProps":"as-needed","arrowParens":"always","singleQuote":false,"trailingComma":"es5","bracketSpacing":true,"jsxBracketSameLine":false},"_integrity":"sha512-nZxgZ1tgL8DPA3nPytjCvCO8uJejzGGSSwJDL1Tc6RDNNBB6iDAKcUzQW9v2yNoGyim2sHGenfONO+yVrplB6w==","repository":"https://github.com/frankstolle/openapi-to-zod-schema","_npmVersion":"10.8.3","directories":{},"lint-staged":{"*":"prettier --ignore-unknown --write"},"_nodeVersion":"24.3.0","dependencies":{"yaml":"^2.4.5"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","husky":"^9.0.11","esbuild":"^0.21.5","ts-jest":"^29.1.5","prettier":"^3.3.2","typescript":"^5.5.2","@types/jest":"^29.5.12","@types/node":"^20.14.8","lint-staged":"^15.2.7","@commitlint/cli":"^19.3.0","semantic-release":"^24.0.0","@semantic-release/git":"^10.0.1","@semantic-release/changelog":"^6.0.3","@commitlint/config-conventional":"^19.2.2"},"peerDependencies":{"zod":"^4.1.12"},"_npmOperationalInternal":{"tmp":"tmp/openapi-to-zod-schema_1.0.1-semantic-release.0_1762715986304_0.7700350775456446","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@btfash/openapi-to-zod-schema","version":"1.1.0","repository":"https://github.com/frankstolle/openapi-to-zod-schema","license":"MIT","type":"module","types":"dist/index.d.ts","main":"dist/index.mjs","bin":{"openapi-to-zod-schema":"dist/cli.cjs"},"exports":{".":{"import":{"default":"./dist/index.mjs","types":"./dist/index.d.ts"},"require":{"default":"./dist/index.cjs","types":"./dist/index.d.ts"}}},"scripts":{"build":"bun run clean && bun src/scripts/build.mjs && tsc -p tsconfig.build.json","test":"jest","tsc":"tsc","prepublishOnly":"bun run build && bun run tsc && bun run test","clean":"rm -rf dist"},"lint-staged":{"*":"prettier --ignore-unknown --write"},"prettier":{"arrowParens":"always","bracketSpacing":true,"jsxBracketSameLine":false,"printWidth":120,"quoteProps":"as-needed","semi":true,"singleQuote":false,"tabWidth":2,"trailingComma":"es5","useTabs":false},"devDependencies":{"@commitlint/cli":"^19.3.0","@commitlint/config-conventional":"^19.2.2","@semantic-release/changelog":"^6.0.3","@semantic-release/git":"^10.0.1","@types/jest":"^29.5.12","@types/node":"^20.14.8","esbuild":"^0.21.5","husky":"^9.0.11","jest":"^29.7.0","lint-staged":"^15.2.7","prettier":"^3.3.2","semantic-release":"^24.0.0","ts-jest":"^29.1.5","typescript":"^5.5.2"},"peerDependencies":{"zod":"^4.1.12"},"dependencies":{"yaml":"^2.4.5"},"_id":"@btfash/openapi-to-zod-schema@1.1.0","_integrity":"sha512-b9nCetuMVM5N9sQSANPURn9o3EUo+jTtDApr1q0aXrMhBCXWT6HX5duZF8C2Z/benpXxsIQeOJQT2bGx/uhwxA==","_nodeVersion":"26.3.0","_npmVersion":"10.8.3","shasum":"7908ae2c9db5a556f2fd768a174871e03a56fe31","dist":{"integrity":"sha512-b9nCetuMVM5N9sQSANPURn9o3EUo+jTtDApr1q0aXrMhBCXWT6HX5duZF8C2Z/benpXxsIQeOJQT2bGx/uhwxA==","shasum":"7908ae2c9db5a556f2fd768a174871e03a56fe31","tarball":"https://registry.npmjs.org/@btfash/openapi-to-zod-schema/-/openapi-to-zod-schema-1.1.0.tgz","fileCount":12,"unpackedSize":695584,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIESxoeyHRaBfIa8XQr0pV6E+/IhPc0HCG6OV6qqykQI2AiBe/jdlpZs5te7xhKH2Y748etT+2UDLmJ8MhtlIaoT4Jw=="}]},"_npmUser":{"name":"the-tablet","email":"i.am.the.tablet@proton.me"},"directories":{},"maintainers":[{"name":"the-tablet","email":"i.am.the.tablet@proton.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/openapi-to-zod-schema_1.1.0_1784185165928_0.6435444493871303"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-08T05:24:42.220Z","modified":"2026-07-16T06:59:26.279Z","1.0.0-semantic-release.0":"2025-11-08T05:24:42.578Z","1.0.1-semantic-release.0":"2025-11-09T19:19:46.544Z","1.1.0":"2026-07-16T06:59:26.093Z"},"license":"MIT","repository":"https://github.com/frankstolle/openapi-to-zod-schema","maintainers":[{"name":"the-tablet","email":"i.am.the.tablet@proton.me"}],"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<name, {}> }\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<string, z.ZodTypeAny>, items: Array<{ name: string, schema: z.ZodTypeAny }> }`\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","readmeFilename":"README.md"}