OpenAPI to TypeScript Types, Zod Schemas and Fetch Client
Types for every schema, request and response, plus Zod schemas and a typed client.
Try before you buy.
- Free preview: the list of files with their sizes, and the first lines of each file (up to 20).
- Locked until you unlock it: download and copy.
- Unlock: Premium pass, ₹799 for 30 days or ₹249 for 1 week, a one-time payment that never renews. Unlock: Premium pass, $19.99 for 30 days or $7.99 for 1 week, a one-time payment that never renews.
Ways to unlock shows how to get the full result.
Printing this result is locked in the free preview.
OpenAPI 3.0, 3.1, 3.2 or Swagger 2.0 (upgraded to 3.1 first), in YAML or JSON. Converted as you type.
Problems
Options
TypeScript
Not expressible in TypeScript
Locked in the free preview. Opens the ways to unlock this result.
Locked in the free preview. Batch runs unlock with a pass.
Locked in the free preview. Query results unlock with a pass.
About the OpenAPI to TypeScript Types, Zod Schemas and Fetch Client
Paste or open an OpenAPI 3.0, 3.1 or 3.2 description — or a Swagger 2.0 one, which is upgraded to 3.1 first — and get TypeScript for it: schema.ts with a type for every schema, parameter, request body and response, in the paths / components / operations shape the openapi-typescript project made common; zod.ts with Zod 4 schemas to check data at run time; and client.ts, a small typed fetch client with one function per operation.
Choose enums as unions or TypeScript enums, date-time strings or Date objects, optional or optional-and-nullable properties, and what happens to read-only and write-only properties. Constructs TypeScript cannot express (not, if / then / else, pattern-matched keys) are listed instead of silently becoming any. With a Premium pass, copy the files one by one or download them as a ZIP. Everything runs in your browser.
Without a pass the result is a free preview: the list of files and the first lines of each. The whole files, copying them and the ZIP unlock with a Premium pass.
How to use it
- Paste the description, open the file, or drop it on the box (a split description: all its files at once, or the folder). It is converted as you type.
- Choose the options: enums, dates, optional properties, read-only and write-only properties, and which files to make.
- Read the files in the viewer and check Not expressible in TypeScript if it appears.
- With a Premium pass, or after unlocking this result, copy a file or download them all as a ZIP, put them in one folder of your project (for example
src/api/), and runnpm install zodif you use the Zod schemas.
Examples
Order:
type: object
required: [id, status]
properties:
id: { type: string }
status: { type: string, enum: [paid, refunded] }
note: { type: string }Order: {
id: string;
status: "paid" | "refunded";
note?: string;
};
export const Order = z.looseObject({
id: z.string(),
status: z.enum(["paid", "refunded"]),
note: z.string().optional(),
});GET /events/{eventId} → 200 Event, 404 Problemconst api = createClient({ headers: () => ({ 'X-API-Key': key }) });
const event = await api.getEvent({ path: { eventId } }); // typed as Event
// a 404 throws ApiError with .status and .bodyCommon uses
- Typing the calls a front end makes to an API that has an OpenAPI description, without adding a code-generation step to the build.
- Checking API responses at run time with Zod, from the same description.
- Getting a dependency-free client for a script, a test or a prototype.
- Seeing at a glance which parts of a description are too loose or too clever to type.
What schema.ts contains
paths lists each path with its parameters and operations; operations has, for each operation (by its operationId, or a name made from the method and path), its parameters by location (query, header, path, cookie), its requestBody by media type and its responses by status and media type, with response headers; components has the schemas, responses, parameters, request bodies and headers; webhooks are in webhooks. So components["schemas"]["Event"] or operations["getEvent"]["responses"][200]["content"]["application/json"] names any part of the API, the way openapi-typescript does. Comments carry descriptions, formats, defaults, examples and deprecation, and a named alias is exported for each schema.
How schemas become types
type: [string, "null"], nullable: true (3.0) and x-nullable (2.0) add | null; enum and const become literal unions; allOf an intersection (&), oneOf and anyOf a union; prefixItems a tuple; additionalProperties an index signature ([key: string]: T). format: binary is Blob. With Date objects, date and date-time are Date and the client converts responses with the Zod schemas (z.coerce.date()). With Leave them out where they do not apply, request bodies use shapes without read-only properties and responses shapes without write-only ones, in a variants interface. TypeScript has no way to say “anything but this” (not), conditional shapes (if / then / else) or keys that match a pattern, so those are listed with what they were typed as.
The Zod schemas
zod.ts uses Zod 4: z.email(), z.uuid(), z.url(), z.iso.datetime({ offset: true }) and z.iso.date() for formats; .min(), .max(), .gte(), .lt(), .multipleOf() and .regex() for limits and patterns; z.enum(), z.literal(), z.union() and z.intersection(). Objects keep properties they do not list (z.looseObject), as JSON Schema allows, and additionalProperties: false becomes z.strictObject. Schemas are written in dependency order, and recursive ones use Zod 4’s getters. Read-only and write-only properties are optional, so one schema checks both requests and responses. The JSON request body and success response of each operation have their own export (createHoldBody, getEventResponse).
The fetch client
createClient({ baseUrl, headers, query, fetch }) returns one function per operation, taking one object with path, query and header parameters and the body. Path parameters are encoded, query parameters are written as their style and explode say (repeated keys, comma-, space- or pipe-separated, or deepObject), bodies are sent as JSON, URL-encoded form fields or multipart form data, and responses are read by their content type. A response that is not 2xx throws an ApiError with its status and body. Cookie parameters are not sent: browsers do not let scripts set cookies on a request.
Limitations
- Operations without an operationId get a name made from their method and path (
getEventsByEventId). not,if/then/else,patternProperties,dependentSchemasanduniqueItemshave no TypeScript type; they are listed, and Zod does not check them either.- A schema with both
propertiesandadditionalPropertiesgets[key: string]: unknown, because TypeScript requires every named property to fit the index type. - References to other files are bundled from the files you open; references to URLs are not loaded and become
unknown. - The client uses the description’s first server unless you pass a
baseUrl; it sends no cookies and does not run OAuth flows (pass a token inheaders). - A schema that contains itself outside an object — a list or a union of itself, as a JSON value type does — has that inner reference typed
unknown, because TypeScript cannot write such a type in place; it is listed with the rest. - OpenAPI 3.2 QUERY operations are listed and left out of the types and the client.
Privacy
On this device: nothing is sent
Everything happens in your browser. What you enter or open here is not uploaded or stored by MySmartCoPilot.
Frequently asked questions
What do I get without a pass?
Without a pass, OpenAPI to TypeScript Types, Zod Schemas and Fetch Client shows the list of files with their sizes, and the first lines of each file (up to 20). Until you unlock it, the result can’t be downloaded or copied. A Premium or Ultimate pass, a one-time payment that never renews, unlocks the full result. The pricing page lists the passes and their prices.
Is my API description uploaded?
No. Reading the description and writing the TypeScript happen in your browser, in a background worker; the page works offline once loaded.
Is the output the same as openapi-typescript’s?
It follows the same shape — paths, components, operations, webhooks and $defs — so code written against openapi-typescript types reads the same. It is a separate implementation, so details differ, for example the named alias for each schema and the variants interface.
Which Zod version do the schemas need?
Zod 4 (npm install zod). They use Zod 4’s z.email(), z.iso.datetime(), z.looseObject() and getter-based recursion, which Zod 3 does not have.
How is this different from JSON to TypeScript?
JSON to TypeScript guesses types from JSON samples. This reads the API description itself, so it knows which properties are required, every enum value, every operation and every response — including error responses.
Why do some types say unknown?
A schema without a type (or {}) allows any JSON value, so unknown is the honest type. Constructs TypeScript cannot express are listed above the files with the place they are in the description.