SPECIFICATION-DRIVEN CODEGEN // OPENAPI 3.0 · 3.1 · SWAGGER 2.0v6.6.2 · ISC LICENSE · CLI + SDK + MCP

Your OpenAPI spec, compiled into typed code.

Point openapi-sync at any remote or local OpenAPI specification. It pins the canonical SHA-256 hash, flags breaking contract changes in CI, and emits TypeScript types, six typed clients, runtime validators, and an 11-tool MCP server.

$npx openapi-sync init
CLIENTS
fetch · next-fetch · axios · react-query · swr · rtk-query
SCHEMAS
zod · yup · joi · python @dataclass
GUARDRAILS
sha-256 lockfile · breaking diff · 11 mcp tools
INPUTpetstore.openapi.yaml · GET /pet/{petId}, POST /pet
src/api/petstore/types/index.ts
import * as Shared from "./shared";

export type IupdatePetDTO = Shared.IPet;
export type IupdatePet200Response = Shared.IPet;
export type IaddPetDTO = Shared.IPet;
export type IaddPet200Response = Shared.IPet;

export type IfindPetsByStatusQuery = {
  "status": ("available" | "pending" | "sold");
};

export type IgetPetById200Response = Shared.IPet;
$ npx openapi-sync --preset react-query-zodOUTPUT → src/api/petstore/types/index.ts
01 / ARCHITECTURE

Built for real API lifecycles, not toy demos.

Every generated module is deterministic, lint-clean, and inspectable in code review—from initial setup through multi-service CI gating.

01.1CLIENTS

Six Typed Client Generators

Emit production-ready Fetch, Next.js App Router Fetch, Axios, TanStack React Query v5, SWR, and RTK Query clients. Includes extensible ApiClient subclassing, method-level generics, and per-endpoint returnType overrides.

npx openapi-sync generate-client --type react-query
01.2VALIDATION

Runtime Schemas & Python Codegen

Compile OpenAPI constraints into Zod, Yup, or Joi schemas for DTOs, queries, and parameters alongside TypeScript interfaces—or target Python @dataclass types and typed endpoint helpers.

validations: { library: "zod", generate: { dto: true, query: true } }
01.3CI & LOCKFILES

Spec Pinning, Snapshots & Diffing

Lock canonical SHA-256 digests in .openapi-sync/lock.json and store deterministic snapshots. Gate pull requests with --frozen, build offline with --use-snapshot, and block breaking changes.

npx openapi-sync diff --fail-on-breaking
01.4MCP & AGENTS

11-Tool MCP Server & Agent-Safe CLI

Ship a standalone stdio MCP server (openapi-sync-mcp) plus non-blocking --json CLI commands with stable exit codes 0–3. Agents paginate endpoints and read exact types without blowing context windows.

npx -y openapi-sync-mcp | npx openapi-sync read-type --json
01.5PRESETS & LAYOUT

10 Presets, Tag Splitting & Auth

Start with zero-config framework presets or serialize them cleanly with --preserve. Organize multi-API workspaces by tag folders, deduplicate URLs with sharedPaths, and load Bearer, Basic, or API Key auth from env.

npx openapi-sync --preset next-fetch --shared-paths --preserve
01.6MAINTENANCE

Doctor, Stale Purge & Custom Code

Audit config syntax, spec reachability, lockfile alignment, and peer dependencies with doctor. Remove orphaned files safely via manifest-tracked purge --dry-run while keeping custom code markers intact.

npx openapi-sync doctor && npx openapi-sync purge --dry-run
02 / CONTRACT INTEGRITY & AI WORKFLOWS

Catch breaking changes before they reach production.

Gate CI builds against committed lockfile snapshots, and give coding agents surgical read/sync access through 11 structured MCP tools over stdio.

npx openapi-sync diff --fail-on-breaking
$ npx openapi-sync diff --fail-on-breaking
📊 petstore (1.0.27 -> 1.1.0): 2 breaking, 1 non-breaking change(s)
  ❌ [BREAKING] ENDPOINT_REMOVED: Endpoint PUT /pet was removed.
  ❌ [BREAKING] REQUIRED_PROPERTY_ADDED: New required request property "microchipId" added at requestBody.microchipId.
  ℹ️  [NON-BREAKING] OPTIONAL_PROPERTY_ADDED: New optional response property "vaccinated" added at response.200.vaccinated.

Run `npx openapi-sync` in a PR to review and update .openapi-sync/lock.json.
EXIT 1 · BREAKING_SPEC_CHANGE · CI BLOCKEDCI Pinning Docs →
MCP STDIO SERVER · 11 TOOLS
  • openapi_sync_read_configInspect active openapi.sync config
  • openapi_sync_initCreate non-interactive config + auth
  • openapi_sync_doctorVerify config, specs, lockfile & peers
  • openapi_sync_validateCheck specs with frozen / breaking flags
  • openapi_sync_diffClassify breaking vs non-breaking changes
  • openapi_sync_list_endpointsFilter & paginate discovered endpoints
  • openapi_sync_get_endpoint_detailsRead full schema for one operationId
  • openapi_sync_read_generated_typeExtract exact TS interface declaration
  • openapi_sync_syncGenerate types, endpoints & schemas
  • openapi_sync_generate_clientEmit typed client hooks or classes
  • openapi_sync_purgeDetect & clean stale generated files
03 / INSTALLATION & PRESETS

Zero-config presets, zero lock-in.

Run directly via npx or install as a dev dependency. Pick any preset to inspect its CLI flag, config, and output layout.

v6.6.2 · npmjs.com/package/openapi-sync
$npx openapi-sync
PRESETTARGETVALIDATION
react-query-zodTanStack React Query v5
Validation: Zod

Typed Query & Mutation hooks over Axios with Zod runtime schemas, operationId naming, and preserved custom code.

$npx openapi-sync --api-url https://petstore3.swagger.io/api/v3/openapi.json --preset react-query-zod --preserve
openapi.sync.ts
import { defineConfig } from "openapi-sync";

export default defineConfig({
  preset: "react-query-zod",
  folder: "./src/api",
  api: {
    petstore: "https://petstore3.swagger.io/api/v3/openapi.json",
  },
});
PEER DEPENDENCIES
npm i @tanstack/react-query axios zod
GENERATED ARTIFACTS
types/ · endpoints.ts · validations.ts · clients.ts · hooks.ts
04 / QUICK START

Three commands from spec to typed code.

No custom templates or AST boilerplate required. Configure once, lock the contract, and import typed hooks and validators.

01STEP 01

Configure your APIs

Declare your specification sources, framework preset, and optional version pin in openapi.sync.ts—or scaffold interactively with npx openapi-sync init.

Supports .ts, .js, and .json configs, plus process.env credentials for protected specs.

openapi.sync.ts
import { defineConfig } from "openapi-sync";

export default defineConfig({
  preset: "react-query-zod",
  folder: "./src/api",
  api: {
    petstore: {
      url: "https://petstore3.swagger.io/api/v3/openapi.json",
      version: "1.0.27",
    },
  },
});
02STEP 02

Sync & Lock Snapshot

Run the compiler to generate TypeScript types, endpoint definitions, Zod validation schemas, and client hooks while recording a canonical SHA-256 lockfile.

Commit .openapi-sync/lock.json and .openapi-sync/snapshots/ so CI can enforce --frozen.

terminal
$ npx openapi-sync

🔄 Syncing petstore...
✅ Successfully synced petstore
✅ petstore: 19 endpoints

🚀 Generating react-query client for 19 endpoint(s)...
✅ Generated axios client: ./src/api/petstore/clients.ts
✅ Generated React Query hooks: ./src/api/petstore/hooks.ts

✨ Client generation complete!
03STEP 03

Consume Types, Hooks & Schemas

Import generated hooks, interfaces, and runtime validators directly into your application. Custom code inside protected markers survives every re-sync.

Method-level generics allow return-type overrides at any call site.

src/components/PetCard.tsx
import { useGetPetById } from "@/api/petstore/hooks";
import { IaddPetDTOSchema } from "@/api/petstore/validations";
import type { IPet } from "@/api/petstore/types/shared";

export function PetCard({ petId }: { petId: number }) {
  const { data } = useGetPetById({ url: { petId } });

  const parseDraft = (input: unknown): IPet => {
    return IaddPetDTOSchema.parse(input);
  };

  return <span>{data?.name ?? "Loading..."}</span>;
}
05 / RECIPES

Production configurations & client recipes.

Inspect real v6.6.2 recipes for every client generator, CI lockfile workflow, and MCP integration.

View Full Reference Docs →

Interactive & Non-Interactive Init

Getting Started

Run the interactive wizard locally or pass explicit flags for automated CI/agent provisioning.

terminal
# Interactive setup wizard (TypeScript, JSON, or JS)
npx openapi-sync init

# Non-interactive setup for CI or AI agents (zero prompts)
npx openapi-sync init --no-interactive \
  --api-name petstore \
  --api-url https://petstore3.swagger.io/api/v3/openapi.json \
  --output-folder ./src/api \
  --preset react-query-zod \
  --config-format typescript \
  --json
06 / SHIP WITHOUT DRIFT

Keep your specs, types, and clients locked together.

Initialize a typed configuration in seconds, commit your snapshot lockfile, and let OpenAPI Sync guard every contract change across humans, CI pipelines, and MCP-enabled agents.