Coming from openapi-typescript
Move from openapi-typescript to contractdiff's types target: contractdiff migrate openapi-typescript turns your script flags and redocly.yaml into a config, contractdiff/openapi-typescript keeps the openapiTS call, and this page says which cases are not covered yet.
openapi-typescript turns an OpenAPI document into TypeScript types: a paths interface, the
components and operations it refers to, and an API, openapiTS, that returns compiler nodes.
contractdiff's types target writes the same interfaces, and its contractdiff/openapi-typescript
entry keeps the openapiTS call. Then the same package diffs the contract, lints it, and generates
the clients, validators and servers openapi-typescript leaves to other tools.
How the names map
| openapi-typescript | contractdiff |
|---|---|
npx openapi-typescript openapi.yaml -o src/api/types.ts | npx contractdiff gen, with a types target in contractdiff.config.json |
CLI flags (--alphabetize, --enum, --export-type, --immutable, --root-types and the rest) | the target's options, by their camelCase names |
redocly.yaml apis entries | one target per API |
import openapiTS, { astToString } from 'openapi-typescript' | import openapiTS, { astToString } from 'contractdiff/openapi-typescript' |
| openapi-fetch's client | the fetch target; Code generation |
| a separate breaking-change tool | contractdiff diff; Breaking changes |
Migrate with one command
contractdiff migrate openapi-typescript reads the package.json scripts that run
openapi-typescript and its redocly.yaml as data (it never runs them), writes
contractdiff.config.json with a types target in openapi-typescript's compatibility mode, rewrites
each script to contractdiff gen, and reports every flag it could not carry as a finding with a
fix:. It deletes nothing; it prints the uninstall command. --dry-run shows the plan and writes
nothing:
openapi: 3.1.0
info:
title: Pets
version: 1.0.0
paths:
/pets/{id}:
get:
operationId: getPet
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
"200":
description: A pet
content:
application/json:
schema:
type: object
required: [name]
properties:
name:
type: string{
"name": "pets-client",
"private": true,
"scripts": {
"gen": "openapi-typescript openapi.yaml -o src/api/types.ts --alphabetize"
},
"devDependencies": {
"openapi-typescript": "^7.13.0"
}
}{"ok":true,"data":{"changed":false,"read":["package.json"],"config":{"input":"openapi.yaml","targets":{"types":{"generator":"types","out":"src/api","options":{"compat":"openapi-typescript","alphabetize":true}}}},"written":[],"unchanged":[],"kept":[],"edited":["package.json"],"findings":[],"uninstall":"npm uninstall openapi-typescript"},"meta":{"provenance":{"dryRun":{"source":"flag","location":"--dry-run"}},"changed":false}}The steps, in order:
npm install -D contractdiff.npx contractdiff migrate openapi-typescript, and read its findings.- Set the target's
outto the folder: thetypestarget writestypes.tsinsideout. In 1.0.0,migratecopies the-ovalue as it was given (src/api/types.ts), sogenwould writesrc/api/types.ts/types.ts; change it tosrc/api. npx contractdiff gen, and compare the newtypes.tswith the old one in your diff.npm uninstall openapi-typescript.
The same command reads openapi-fetch, Hey API and orval configs: contractdiff migrate openapi-fetch,
hey-api or orval.
Keep the openapiTS call
A build script that calls openapi-typescript's API changes its import:
import openapiTS, { astToString } from "contractdiff/openapi-typescript";
const ast = await openapiTS(new URL("./openapi.yaml", import.meta.url));
console.log(astToString(ast).split("\n").slice(0, 10).join("\n"));export interface paths {
"/pets/{id}": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get: operations["getPet"];
put?: never;The entry also exports the transform* helpers, createRef, resolveRef, COMMENT_HEADER and
the rest of openapi-typescript 7's named exports; the API reference
lists them.
What is different on purpose
- No TypeScript compiler. contractdiff writes the types as text.
openapiTSresolves to that text, andastToStringhands it back unchanged, so the code above works, but a caller that walks the returned nodes does not. It also means the generator runs under TypeScript 7, which ships nots.factory. - No network. A remote URL is refused with a
fix:line: download the document and pass its text, its parsed value or afile:URL. Afile:URL's$refs into the files next to it are bundled, as openapi-typescript's Redocly bundler does. injectis text, written as given rather than re-printed.
What is not built
transform,postTransformandtransformProperty. They take and return compiler nodes, and the generator has none; passing one is refused with afix:line.- openapi-typescript's own CLI.
contractdiff/openapi-typescriptis the API, not aopenapi-typescriptbin; scripts move tocontractdiff gen.
Is it compatible?
Not claimed. The compat-oracle host for openapi-typescript is planned, not graded, so the
family's compatibility page has no row for it
and this site quotes no grade. The decision record that cut 1.0.0
(.sdlc/decisions/D-20261124-verification-family-1-0.md) says the entry is not a drop-in until it
passes all of openapi-typescript's own gated cases, and the package README names the two classes
of case it fails: the compiler-node options and the tests that spawn openapi-typescript's own CLI. Until then, read the diff of
your generated types.ts after gen; that is the check that matters for your contract.
Why contractdiff
What contractdiff does that oasdiff, Optic and openapi-typescript do not: one model for HTTP, events and agent tools, a stated compatibility question, decisions read from the contract, code generation that knows its own files, and what it leaves out on purpose.
Coming from oasdiff
Move a breaking-change check from oasdiff to contractdiff diff: the same rule ids for HTTP changes, a compatibility question you choose instead of a fixed one, AsyncAPI, JSON Schema and MCP on the same engine, and what oasdiff has that contractdiff does not.