OpenAPI to TypeScript

Generate TypeScript interfaces and types from OpenAPI 3.x or Swagger 2.0 JSON specs. Supports $ref resolution, enums, allOf/oneOf, and endpoint types.

Your data never leaves your browser
Generated TypeScript types will appear here...

How to Use

  1. Paste your OpenAPI 3.x or Swagger 2.0 JSON spec into the left panel.
  2. Optionally toggle "Use type instead of interface" for type alias syntax.
  3. Click Generate Types to create TypeScript definitions.
  4. Copy the output and add it to your project.

What Gets Generated

  • Schema types — every schema in components.schemas (OpenAPI 3) or definitions (Swagger 2) becomes a TypeScript interface or type
  • Enum types — schemas with enum values become union types
  • Nested objects — inline object schemas are expanded with proper nesting
  • $ref resolution — references are resolved to their TypeScript type names
  • allOf / oneOf / anyOf — composition types become intersection (&) or union (|) types
  • Endpoint types — request bodies and response schemas from paths get their own types
  • Nullable — nullable fields get | null appended
  • Descriptions — schema descriptions become JSDoc comments

OpenAPI vs Swagger

Swagger 2.0 stores schemas under definitions at the root level. OpenAPI 3.x moved them under components.schemas and added features like oneOf, anyOf, and request body schemas. This tool handles both automatically.

Why Generate Types from Specs?

Manually writing TypeScript types for API responses is error-prone and tedious, especially for large APIs with dozens of schemas. Generating types from your OpenAPI spec ensures your frontend types always match your API contract. When the spec changes, just re-generate.

For production workflows, consider tools like openapi-typescript (npm) which can be integrated into your build pipeline. This online tool is ideal for quick one-off generation, exploring a new API's types, or when you don't want to install dependencies.

Related Tools

Generate types from raw JSON with the JSON to TypeScript Generator. Convert YAML specs to JSON with the JSON-YAML Converter. Validate your JSON spec with the JSON Validator. Format messy specs with the JSON Formatter.

Frequently Asked Questions

Does this support both OpenAPI 3.x and Swagger 2.0?
Yes. The tool reads schemas from components.schemas (OpenAPI 3.x) or definitions (Swagger 2.0). Both formats are fully supported.
Can I paste a YAML spec instead of JSON?
Currently only JSON specs are supported. If your spec is in YAML, use our JSON-YAML Converter to convert it to JSON first, then paste it here.
How are $ref references handled?
References like $ref: "#/components/schemas/User" are resolved to their TypeScript type name (User). The referenced type must be defined in the same spec to be generated.
Does it generate types for API endpoints too?
Yes. If your spec includes paths with request bodies and responses, the tool generates request and response types for each operation.
Is my API spec safe?
Yes. All processing happens entirely in your browser. Your OpenAPI spec is never sent to any server.

AI agent tools available. The CodeTidy MCP Server gives Claude, Cursor, and other AI agents access to 47 developer tools. One command: npx @codetidy/mcp

Drop file to load