openapi3-ts

Typed TypeScript models and a fluent builder DSL for authoring OpenAPI 3.0, 3.1, and 3.2 contracts.

Library
npm
v4.6.1
541stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
61/100Good
Development Activity60
Maintenance36
Community68
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture78
Code Quality82
Innovation80
Learning Curve75

openapi3-ts gives TypeScript and JavaScript projects a fully typed way to construct OpenAPI 3.x documents instead of hand-writing JSON or YAML. It ships parallel, version-isolated implementations for OAS 3.0, 3.1, and 3.2 — each with its own typed interfaces (OpenAPIObject, PathsObject, SchemaObject, and the rest of the spec’s object model) plus a fluent OpenApiBuilder class for assembling a document call by call.

Because each OAS version is its own subpath export (openapi3-ts/oas30, /oas31, /oas32), consumers pull in only the version they target with no cross-version type bleed, and the compiler enforces that a document built against 3.1 rules can’t accidentally use a 3.0-only or 3.2-only field. The finished document can be emitted as JSON via getSpecAsJson() or as YAML via getSpecAsYaml() (backed by the yaml package), and it has no other runtime dependencies, so it runs equally well in Node, Deno, or the browser.

What You Get

  • Separate typed model modules for OAS 3.0, 3.1, and 3.2, each mirroring the official specification’s object model (InfoObject, PathsObject, SchemaObject, ComponentsObject, etc.)
  • A fluent OpenApiBuilder class per version with chainable addInfo(), addPath(), addSchema(), addResponse(), addParameter(), and similar methods
  • Built-in serialization to JSON (getSpecAsJson()) and YAML (getSpecAsYaml()) directly off the assembled document
  • Version-scoped subpath exports (openapi3-ts/oas30, openapi3-ts/oas31, openapi3-ts/oas32) so a project only imports the spec version it targets
  • A shared Server/ServerVariable type export usable across all three OAS versions
  • Runs anywhere — Node, Deno, or the browser — with a single runtime dependency (yaml)

Common Use Cases

  • Generating an OpenAPI 3.x contract programmatically from route definitions or decorators instead of maintaining a hand-written YAML file
  • Building internal tooling that needs to construct, mutate, or validate the shape of OpenAPI documents with compile-time type safety
  • Migrating an API description between OAS versions (3.0 to 3.1 or 3.2) using version-specific typed models to catch incompatible fields at compile time
  • Powering code generators or API gateways that assemble an OpenAPI document at build time and export it as JSON or YAML for downstream consumers

Under The Hood

Architecture The library is a straightforward layered structure: src/model holds pure TypeScript interface definitions mirroring the OpenAPI spec object-by-object (openapi30.ts, openapi31.ts, openapi32.ts, oas-common.ts, server.ts, specification-extension.ts), while src/dsl holds three parallel OpenApiBuilder classes (openapi-builder30.ts, -31.ts, -32.ts) that wrap a rootDoc instance of the matching version’s OpenAPIObject behind chainable addX() methods. Version-specific entry points (oas30.ts, oas31.ts, oas32.ts) re-export the matching model-plus-builder pair, and the root index.ts aggregates all three namespaces plus the shared Server/ServerVariable types. There is no shared abstraction across the three OAS versions beyond structural parallelism, so a change to the core document shape is replicated three times rather than centralized; data flow is entirely synchronous and in-memory, with builder methods mutating rootDoc before getSpecAsJson()/getSpecAsYaml() serialize it.

Tech Stack Written in TypeScript, compiled via Vite library mode plus tsc --emitDeclarationOnly for type declarations, and published as dual CommonJS/ESM output with a package.json exports map carrying per-version subpath exports. The only runtime dependency is the yaml package for YAML serialization. Development tooling includes ESLint with the flat-config typescript-eslint setup, Prettier for formatting, Vitest with @vitest/coverage-v8 for testing, and coveralls for CI coverage reporting. There is no runtime framework, database, or deployment target — it is a pure library published to npm for consumption by other TypeScript/JavaScript projects.

Code Quality Spec files sit alongside their implementation files across both the model and DSL layers, covering type-shape checks and full builder fluent-chain assertions using Vitest’s describe/it/expect. Error handling is minimal but explicit where it matters — addOpenApiVersion() validates its input against a version-pattern regex and throws a descriptive error on malformed input — while elsewhere the library leans on TypeScript’s type system rather than runtime validation, consistent with its role as a typed-contract builder rather than a validator. Naming is consistent fluent addX() builder methods throughout, and the codebase is strictly typed with only a single file-level eslint-disable for no-explicit-any in the model layer’s extension fields. CI runs lint, build, and test stages on every change.

API Design The most distinctive choice is maintaining three fully separate, parallel model-and-builder implementations for OAS 3.0, 3.1, and 3.2 rather than one merged superset type, so consumers import exactly the version-specific subpath they need with no cross-version type pollution — a level of discipline uncommon among spec-modeling libraries, most of which ship untyped or version-merged definitions. The fluent builder chain plus direct JSON/YAML serialization keeps boilerplate to a handful of chained calls with full editor autocomplete, and there is no setup or configuration step required to start building a document.

Used by 6 apps in this directory

TypeScript
81%
Other

Directus

CMS · Low Code Platforms

37,783

Connect any SQL database and get instant REST and GraphQL APIs, a visual management Studio, and a native MCP server for AI agents — free for most organizations.

View details
92
Repo Health
82
Technical
76
Dependency
Built with
TypeScript81%
Vue18%
Updated 3 days ago
TypeScript
100%
Other

Dub

Marketing · Analytics

24,676

The open-source link attribution platform for short links, conversion tracking, and affiliate programs — powering 100M+ clicks monthly.

View details
80
Repo Health
78
Technical
62
Dependency
Built with
TypeScript100%
Updated 2 days ago
TypeScript
57%
MIT

Jitsu

Data Engineering

5,063

Open-source, fully-scriptable data ingestion engine that streams events from web, apps, and APIs to any data warehouse in real time.

View details
88
Repo Health
79
Technical
66
Dependency
Built with
TypeScript57%
Go41%
Updated 3 days ago
TypeScript
88%
Apache 2.0

Medplum

Developer Tools · Databases · Authentication

2,657

An open-source, FHIR-native healthcare platform that gives developers a compliant backend, authentication, a React component library, and serverless bots to build clinical applications in weeks instead of years.

View details
93
Repo Health
90
Technical
72
Dependency
Built with
TypeScript88%
MDX10%
Updated yesterday
TypeScript
86%
MIT

medusa

Ecommerce

36,163

The most flexible open-source commerce platform — build B2C, B2B, and marketplace applications with modular, composable commerce primitives.

View details
93
Repo Health
87
Technical
63
Dependency
Built with
TypeScript86%
JavaScript14%
Updated 2 days ago
TypeScript
99%
Other

Teable

Databases · No Code Platforms

21,759

A no-code PostgreSQL database with spreadsheet UX, real-time collaboration, and native AI agents — built for teams that outgrow Airtable.

View details
79
Repo Health
76
Technical
63
Dependency
Built with
TypeScript99%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search