OpenAPI2Code

Turn { } into code.

Paste an OpenAPI or Swagger spec and get typed models back in TypeScript, Zod, Swift, Kotlin, Dart, Python, or Pydantic. It happens instantly, right in your browser, with nothing to install, and nothing you paste ever leaves your machine.

Open the editor
{
"Pet": {
"name": { "type": "string" }
}
}
TypeScript export interface Pet {
Zod const PetSchema = z.object({
Swift struct Pet: Codable {
Kotlin data class Pet(
Dart class Pet {
Python @dataclass(kw_only=True)
Pydantic class Pet(BaseModel):
Open full playground
Loading WASM module...

What is OpenAPI2Code?

OpenAPI2Code is a zero-dependency code generator for OpenAPI and Swagger specs. Paste or upload a spec above and you'll get typed models for your target language back, right in your browser. The playground runs the same Go engine as the CLI, compiled to WebAssembly, so nothing you paste here ever touches a server. There's no Java runtime to install, no Docker image to pull, no per-language toolchain to set up first. Just paste a spec and generate all seven targets in one run, whether you're kicking the tires or wiring it into a real project.

Supported targets

TypeScript interfaces
Zod runtime schemas
Swift Codable structs
Kotlin data classes
Dart classes
Python dataclasses
Pydantic validated models

How it works

  1. 1 Paste a spec, or pick one of the examples above.
  2. 2 Choose a target and, optionally, modular output.
  3. 3 Copy the generated code straight into your project.

Get the CLI

Prefer a command line? The same engine ships as a single static binary.

Other platforms (Intel macOS, ARM Linux): see all release assets.

FAQ

Does OpenAPI2Code send my spec to a server?

No. The playground runs the same Go engine as the CLI, compiled to WebAssembly, so it works entirely in your browser. Whatever spec you paste or upload stays on your machine.

Which OpenAPI and Swagger versions does OpenAPI2Code support?

OpenAPI 3.0, OpenAPI 3.1, and Swagger 2.0.

What languages can OpenAPI2Code generate?

TypeScript interfaces, Zod runtime validation schemas, Swift Codable structs, Kotlin data classes, Dart classes, Python dataclasses, and Pydantic BaseModel classes. All from the same spec, and you can generate more than one at a time.

Is OpenAPI2Code free and open source?

Yes. It's MIT licensed and free to use, and the source is on GitHub.

Can I use OpenAPI2Code from the command line?

Yes. Besides the browser playground, it ships as a single zero-dependency static binary for macOS, Linux, and Windows, and you can grab it from GitHub Releases.

How do you know the generated code actually works?

The test suite runs real generated output through the actual compiler or interpreter for each target (tsc, swiftc, kotlinc, dart, python3 — including a real Pydantic import check) instead of just comparing it as text. Enums also keep their real type now, so a boolean or integer enum won't get flattened into a string.