Swagger 2.0 to TypeScript types in browser
Convert a Swagger 2.0 (swagger: "2.0") spec to TypeScript interfaces. Resolves
#/definitions/ refs and generates typed paths from response schemas — no Node.js.
Swagger 2.0 (also known as OpenAPI 2.0) is the predecessor to OpenAPI 3.x and is still
widely used in enterprise and legacy APIs. Its main structural differences from OpenAPI 3.x
are: schemas live under definitions (not components/schemas),
request bodies are inline body parameters (not a separate requestBody
field), and responses reference schemas directly rather than through a content map.
The
OpenAPI to TypeScript browser generator
detects Swagger 2.0 by the swagger: "2.0" field and applies the correct parsing
strategy: #/definitions/Foo refs resolve to
components["schemas"]["Foo"] in the output (using a unified namespace for
compatibility), and response schema fields are used directly to produce typed
response shapes.
Swagger 2.0 vs OpenAPI 3.x in the generated types
- Definitions → schemas:
#/definitions/Userbecomescomponents["schemas"]["User"]in the TypeScript output, keeping the namespace consistent whether you upgrade to 3.x later or not. - Response schema: Swagger 2.0 uses
schemadirectly on the response object. The generator emitsschema: SomeTypeon the response type, matching the runtime shape. - x-nullable support: Swagger 2.0 does not have a standard
nullablefield, but many generators emitx-nullable: true. The generator treats this identically tonullable: true.
How to use
-
Paste your Swagger 2.0 JSON or YAML spec into the text area at
OpenAPI to TypeScript Types. The tool
detects the format from the
swagger: "2.0"field automatically. - Click Generate TypeScript. The generator handles
definitions, parameter schemas, and response schemas for all paths and HTTP methods. - Download
types.d.tsand integrate it into your TypeScript project. Thepathsinterface is compatible with typed fetch helpers.
Related tools
- OpenAPI to TypeScript Types — main generator (Swagger 2.0 + OpenAPI 3.x)
- OpenAPI 3.x to TypeScript — modern spec support
- OpenAPI JSON to TypeScript
- JSON Formatter — pretty-print your Swagger JSON
- YAML Validator