OpenAPI to TypeScript

← All tools

Paste an OpenAPI 3.0 or 3.1 document. The page writes TypeScript for the schemas, the path and query parameters, and the JSON request and response bodies.

The document never leaves the browser. Nothing is uploaded.

Open file…

Options

Semicolons are the only option stored in the URL, as semi=1. The document stays on this page.

Not converted

TypeScript

The preview is cut at 200,000 characters. Copy and Download include everything.

About this tool

The page reads OpenAPI 3.0 and 3.1, as YAML or as JSON. A document that starts with a curly brace or a square bracket is parsed as JSON. Anything else is parsed as YAML 1.2. In that YAML, yes, no, and a date stay strings. Swagger 2.0 is rejected, and so is a file with no openapi field or a 2.x version.

Each schema in components.schemas becomes an exported interface when it is a plain object. Otherwise it becomes a type alias. A nullable object is an interface plus a type alias that addsnull. operationId names the parameter, request, and response types. Without one, the name comes from the method and the path. Path and query parameters land on one interface. Header and cookie parameters are skipped.

Request and response bodies use application/json and media types that end in +json. When several JSON media types are listed, the type comes from the first one, and the page says so.integer is number, because TypeScript has no integer type. format, minLength,pattern, and the other numeric limits are not copied into the types. additionalProperties: true does not add an index signature. A schema value for additionalProperties does.oneOf and anyOf become unions.discriminator is not checked. allOf becomes an intersection. A $ref has to point at#/components/schemas with three pointer parts. An external ref becomes unknown.

Keywords written next to $ref are ignored. A tuple (items as an array) becomes unknown[]. A boolean schema becomes unknown. readOnly,writeOnly, and deprecated are comments on the property. webhooks, callbacks, and a path item$ref are skipped. A path parameter markedrequired: false is still required in the type. Semicolons are off unless you tick the box. Files up to 1 MB open in the page.

Read more

Free books, courses, and software

Get my programming books, course editions, and complete software.

Get the download library →