ZeroTool Workbench
OpenAPI to TypeScript Generator
Convert OpenAPI 3.0/3.1 YAML or JSON to TypeScript interfaces in your browser. Handles $ref, oneOf, allOf, enum, nullable, and optional Zod schemas. No upload.
How to Use
- Paste an OpenAPI 3.0.x or 3.1.x document (YAML or JSON) into the left panel.
- Generation runs in real time as you type, with a 300 ms debounce.
- Optionally tweak the root namespace, mark every property optional, include path operation types, or emit matching Zod schemas.
- Click Copy to grab the full TypeScript output.
What gets generated
- components/schemas become one
export interfaceorexport typeper schema. Object schemas become interfaces; primitive, union, enum, and intersection schemas become type aliases. - $ref targets inside
#/components/schemas/...are resolved and emitted by name, preserving the declaration order from your spec. - oneOf / anyOf become union types (
A | B | C). allOf becomes an intersection (A & B). - enum becomes a string or numeric literal union.
- nullable in 3.0 and
type: ['X', 'null']in 3.1 both becomeX | null. - format hints add JSDoc comments —
format: date-timenotes ISO 8601,format: binarybecomesBlob. - additionalProperties become index signatures or
Record<string, T>.
Path types (optional)
With Include path types enabled, each operation produces a typed envelope:
export namespace Components {
export namespace GetPetById {
export interface PathParameters {
id: number;
}
export type Response200 = Pet;
}
}
If an operation has no operationId, the tool synthesises one from method + path, e.g. GetPetsId.
Zod schemas (optional)
Toggle Include Zod schemas to emit a parallel XSchema for every component:
import { z } from 'zod';
export const PetSchema = z.object({
id: z.number().int(),
name: z.string(),
status: z.enum(["available", "pending", "sold"]),
});
Pair this output with TypeScript to Zod when you want to keep schemas in sync with hand-written types instead of an OpenAPI spec.
Related tools
- OpenAPI Validator — sanity-check the spec before generating types.
- JSON to TypeScript — when you only have a sample JSON response, not a full spec.
- JSON to Zod Schema — generate Zod from a single JSON example.
FAQ
Which OpenAPI versions are supported?
Both 3.0.x and 3.1.x. OpenAPI 3.1 type unions like `type: ['string', 'null']` map to `string | null`. OpenAPI 3.0 `nullable: true` is also recognised.
What about Swagger 2.0?
Swagger 2.0 is not supported by design. Migrate your spec to OpenAPI 3.x first using editor.swagger.io (Swagger Editor's built-in converter), then paste the upgraded spec here.
Are remote `$ref` URLs resolved?
Only internal refs in the form `#/components/schemas/...` are resolved. Cross-document references to URLs or filesystem paths are not fetched. Inline the referenced schemas first, or use the openapi-typescript CLI for that workflow.
Where does my spec go?
Nowhere. Parsing, $ref resolution, and TypeScript generation all happen entirely in your browser. No backend, no telemetry of spec content, no upload.
Can I get Zod schemas as well?
Yes. Toggle **Include Zod schemas** to emit `z.object({...})` definitions alongside the TypeScript interfaces. Useful when you want runtime validation that mirrors your static types.
What does Include path types do?
It generates a `Components` (or your chosen root namespace) wrapper with one namespace per operation, exposing `PathParameters`, `QueryParameters`, `RequestBody`, and `Response200` / `Response201` etc. Skip it if you only need DTO interfaces.