# CLI Reference

All commands support `--help` for full usage details.

## `oagen generate`

Generate SDK code from an OpenAPI spec.

```bash
oagen generate --spec openapi.yml --lang node --output ./sdk --namespace Acme
```

| Argument               | Required | Default                 | Description                                                                                                                                                                                              |
| ---------------------- | -------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--spec <path>`        | No       | `OPENAPI_SPEC_PATH` env | Path to an OpenAPI 3.x spec file.                                                                                                                                                                        |
| `--lang <language>`    | Yes      |                         | Target language — must have a registered emitter (via `oagen.config.ts`)                                                                                                                                 |
| `--output <dir>`       | Yes      |                         | Directory to write generated files into                                                                                                                                                                  |
| `--namespace <name>`   | No       | Spec's `info.title`     | SDK namespace in PascalCase — used directly for code identifiers (e.g., `Acme::Client`) and converted to `snake_case` for file paths (e.g., `lib/acme/`). Use PascalCase with the exact casing you want. |
| `--dry-run`            | No       | `false`                 | Print the list of file paths that would be generated, without writing anything to disk                                                                                                                   |
| `--api-surface <path>` | No       |                         | Path to baseline API surface JSON for compat overlay                                                                                                                                                     |
| `--target <dir>`       | No       |                         | Target directory for live SDK integration — generated files are merged into this directory instead of `--output`                                                                                         |
| `--no-compat-check`    | No       | `false`                 | Skip compat overlay even if `--api-surface` is provided                                                                                                                                                  |

## `oagen diff`

Compare two OpenAPI specs and output a diff report as JSON. Use this to review what changed before regenerating.

An `operation-modified` change carries `serversChanged` when the servers the operation is actually served from — `Operation.servers` (its own, else its Path Item's), else the document's — changed: the two lists are matched on URL template and variables, ignoring descriptions, enum order and position, except that a reorder that moves the first entry's resolved URL counts. URLs are compared in their RFC 3986 form (see **Servers** below), so a host that only changed case is no change. `serverChanges` beside the flag lists what changed as the document-level diff reports the same edit — `base-url-changed`, `server-added`, `server-removed` and `server-modified` with its `variableChanges`, each list read as a document whose `baseUrl` is its first entry resolved, each entry classified by the rules in **Servers** below and the tables there — and the operation is breaking for its servers exactly when one of those entries is. So an enum value added, an enum lifted, a variable added, a server added after the first, a first server appearing where there was none, a default changed that moves no resolved URL (a host that only changed case), or any change to a variable the template never references is additive on an operation as it is on the document, and `oagen diff` exits `1` for it at either level; a server removed, the first entry's resolved URL moved or gone, or a referenced variable removed, its default changed so that a resolved URL moves, an enum put on it or a value taken off it is breaking at either level. An operation that inherits the document's servers on both sides is not reported here even when the document's own list moved. OpenAPI's default server is one list however it is spelled: an operation that writes `servers: [{ url: '/' }]` out under a document that declares no servers (or `servers: []`) is served from the same place as one that inherits, so neither gaining nor losing that entry is reported. A webhook carries no `servers` in the IR, so a `webhook-modified` change has no such flag.

```bash
oagen diff --old v1.yml --new v2.yml
```

| Argument       | Required | Description                   |
| -------------- | -------- | ----------------------------- |
| `--old <path>` | Yes      | Path to the old/previous spec |
| `--new <path>` | Yes      | Path to the new/current spec  |

**Exit codes:** 0 = no changes, 1 = additive or modified changes, 2 = breaking changes.

### Change kinds

Every entry in `changes` carries a `kind` and a `classification` (`additive` or `breaking`). A `-modified` change also lists what changed inside it and is breaking when any of those is.

| `kind`                     | Classification                                                                                                                                                                                                                                               | Fields                                                                                                                                                                                                                                                                 |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `base-url-changed`         | breaking; additive when the old spec declared nothing beyond the default server (no `servers`, `[]`, or only `/`)                                                                                                                                            | `oldBaseUrl`, `newBaseUrl` (as written; `''` for no server; `/` when the first server resolves to `/`, which means the same)                                                                                                                                           |
| `server-added`             | additive                                                                                                                                                                                                                                                     | `url` (the template as written in the new spec)                                                                                                                                                                                                                        |
| `server-removed`           | breaking                                                                                                                                                                                                                                                     | `url` (the template as written in the old spec)                                                                                                                                                                                                                        |
| `server-modified`          | from `variableChanges`                                                                                                                                                                                                                                       | `url` (the template as written in the new spec), `variableChanges[]`                                                                                                                                                                                                   |
| `security-changed`         | breaking when a caller built for the old default — or a handler, when a webhook or a callback inherits it — no longer passes; additive otherwise                                                                                                             | `oldSecurity`, `newSecurity` (`[]` for none)                                                                                                                                                                                                                           |
| `security-scheme-added`    | breaking when the old spec already had the scheme in use under a definition the parser omits (`openIdConnect`, `http digest`, `mutualTLS`); additive otherwise                                                                                               | `schemeName`, `scheme` (the definition, an `AuthScheme`; see **Security schemes** below)                                                                                                                                                                               |
| `security-scheme-removed`  | breaking when the scheme is in use in the old spec or a requirement in the new spec still names it; additive otherwise                                                                                                                                       | `schemeName`, `scheme` (the old definition)                                                                                                                                                                                                                            |
| `security-scheme-modified` | breaking when the wire form regressed (`kind`; an `apiKey`'s `in` and folded `name`; an `oauth2` scheme's flow removed or its URL changed; a scope a requirement still names no longer offered) and the scheme is in use in the new spec; additive otherwise | `schemeName`, `oldScheme`, `newScheme`, `details`                                                                                                                                                                                                                      |
| `model-added`              | additive                                                                                                                                                                                                                                                     | `name`                                                                                                                                                                                                                                                                 |
| `model-removed`            | breaking                                                                                                                                                                                                                                                     | `name`                                                                                                                                                                                                                                                                 |
| `model-modified`           | from `fieldChanges`, `variantChanges` and `constraintsChanged` (see **Constraints** below)                                                                                                                                                                   | `name`, `fieldChanges[]`, `variantChanges[]` (a named union's, see **Named unions** below), `constraintsChanged` with `oldConstraints`, `newConstraints` and `details` (the model's own limits)                                                                        |
| `enum-added`               | additive                                                                                                                                                                                                                                                     | `name`                                                                                                                                                                                                                                                                 |
| `enum-removed`             | breaking                                                                                                                                                                                                                                                     | `name`                                                                                                                                                                                                                                                                 |
| `enum-modified`            | from `valueChanges`                                                                                                                                                                                                                                          | `name`, `valueChanges[]`                                                                                                                                                                                                                                               |
| `service-added`            | additive                                                                                                                                                                                                                                                     | `name`                                                                                                                                                                                                                                                                 |
| `service-removed`          | breaking                                                                                                                                                                                                                                                     | `name`                                                                                                                                                                                                                                                                 |
| `operation-added`          | additive                                                                                                                                                                                                                                                     | `serviceName`, `operationName`                                                                                                                                                                                                                                         |
| `operation-removed`        | breaking                                                                                                                                                                                                                                                     | `serviceName`, `operationName`                                                                                                                                                                                                                                         |
| `operation-modified`       | from `paramChanges`, `envelopeFieldChanges` and the `…Changed` flags                                                                                                                                                                                         | `serviceName`, `operationName`, `paramChanges[]`, `responseChanged`, `requestBodyChanged`, `pathChanged`, … (see `OperationModified` in `src/differ/types.ts`)                                                                                                         |
| `webhook-added`            | additive                                                                                                                                                                                                                                                     | `name`, `httpMethod` (the pair that identifies a webhook, see [Webhook](architecture/ir-types.md#webhook))                                                                                                                                                             |
| `webhook-removed`          | breaking                                                                                                                                                                                                                                                     | `name`, `httpMethod`                                                                                                                                                                                                                                                   |
| `webhook-modified`         | from `paramChanges` and the `…Changed` flags, read from the receiver's side                                                                                                                                                                                  | `name`, `httpMethod`, `paramChanges[]`, `requestBodyChanged`, `responsesChanged`, `deprecatedChanged`, `securityChanged`, `tagsChanged`, … (see `WebhookModified` in `src/differ/types.ts`)                                                                            |
| `callback-added`           | additive                                                                                                                                                                                                                                                     | `name`, `expression`, `httpMethod` (the triple that identifies a callback, see [Callback](architecture/ir-types.md#callback)) and the site: `serviceName` + `operationName` or `webhookName` + `webhookMethod`, with `parents[]` when nested (see **Callbacks** below) |
| `callback-removed`         | breaking                                                                                                                                                                                                                                                     | `name`, `expression`, `httpMethod`, the site                                                                                                                                                                                                                           |
| `callback-modified`        | from `paramChanges` and the `…Changed` flags, read from the receiver's side, exactly as `webhook-modified`                                                                                                                                                   | `name`, `expression`, `httpMethod`, the site, `paramChanges[]`, `requestBodyChanged`, `responsesChanged`, `deprecatedChanged`, `securityChanged`, `tagsChanged`, … (see `CallbackModified` in `src/differ/types.ts`)                                                   |

**Servers.** `baseUrl` is `servers[0]` with its variables' defaults filled in, so `base-url-changed` is reported once whenever that resolved host differs: alongside whichever server change moved it, and on its own when the list was only reordered. Servers are matched on their `url` template, independent of position, so a changed template is a `server-removed` plus a `server-added`. A template declared more than once is matched as a multiset: its old and new entries pair up by the strongest signal available, each pass taking the first unmatched candidate in declaration order — identical variables first (so a reordered list, or one whose duplicates are unchanged, reports nothing), then the same variable defaults, then the same resolved URL, then position — and the surplus on either side is a `server-added` or a `server-removed`. Within a matched server, `variableChanges` lists each variable by name; descriptions are not compared. A document with no `servers`, one with `servers: []`, and one whose only server is `/` — description and variables aside, since `/` references no variable — all have OpenAPI's default server — a single server at `/` — and are compared as declaring no server: nothing is reported between any two of them (a variable declared on `/` included), and moving from any of them to a named host is an additive `base-url-changed` plus a `server-added`, with no `server-removed` for `/`. A document whose list means the default is matched as `[{ url: '/' }]`, and the `/` it is only implied to have is never reported as added or removed: `/` gaining a named host beside it is one `server-added`, losing that host is one `server-removed`, and moving from any spelling of the default to a named host is an additive `base-url-changed` plus a `server-added`. Beside a named host, `/` is a server a caller can pick, so it is added and removed like any other, and listed first it is the address a caller gets without naming a host: a host taking the front from it — by a reorder, or because `/` was removed — is a breaking `base-url-changed`, which is additive only from a document whose list means the default. The default address is compared with `''` and `/` read as one, so a first server that merely resolves to `/` (`{root}` with default `/`) has not moved from the default (a host taking the front from it is breaking all the same), while a `baseUrl` that names a host with no `servers` beside it (an IR built by hand; the parser never produces that shape) is compared as written, so a host change there is still a `base-url-changed`. `/` with a variable is the default too, since `/` references no variable and the variable cannot change where it points; beside a named host it comes and goes like any listed `/`. A variable the `url` template never references — no `{name}` placeholder for it in the template — cannot reach any resolved URL, so every change to it is additive, whatever its kind: removing it, changing its default or narrowing its values takes nothing away from any caller. For the four kinds that are breaking on a referenced variable — `variable-removed`, `variable-default-changed`, `variable-enum-added` and `variable-enum-value-removed` — the entry's `details` then ends with `{name} is not in the URL template, so no resolved URL moves` (after `; ` when the kind already carries text); `variable-added`, `variable-enum-removed` and `variable-enum-value-added` are additive for any variable and are reported exactly as the table shows. A referenced variable's default can also change without moving anything: when the template with only that variable filled in is one URL in its RFC 3986 form from either default (see below), as when `{region}` in `https://{region}.pets.example.com` goes from `EU` to `eu`, the `variable-default-changed` is still reported, since defaults are compared as written, but it is additive, and its `details` ends with `either default resolves to the same URL in its RFC 3986 form`. The template's other placeholders are kept rather than filled from their defaults, since a caller may pick any value for them and the RFC 3986 form folds only what no such value can change: in `{scheme}://pets.example.com:{port}`, `port` going from `443` to `''` stays breaking, since a caller who picks `http` for `scheme` moves from port 443 to port 80. The "breaking" rows below apply to a variable the template references, and the `variable-default-changed` row to a default that moves a resolved URL.

Every URL in that comparison — `baseUrl`, each `url` template and each resolved URL — is read in its RFC 3986 form (`normalizeServerUrl`, exported from the package): the scheme and the host are case-insensitive, a port that is empty or the scheme's default (`80` for `http` and `ws`, `443` for `https` and `wss`) is the same as none, a wholly literal authority with no path is the same as one followed by `/`, and in a percent-encoded octet the hex digits' case does not count and one that encodes an unreserved character (a letter, a digit, `-`, `.`, `_`, `~`) is the same as that character. So `https://PETS.example.com`, `HTTPS://pets.example.com:443/` and `https://pets.example.com` are one server, and a document that moves between them reports nothing. The path, query and fragment are case-sensitive and compared as written otherwise (`/v1` and `/V1`, or `/v1` and `/v1/`, are two servers). A `{name}` placeholder is kept as written, so `{Region}` and `{region}` are two templates and a template is never the URL it resolves to. A placeholder's value may carry any delimiter — a `@` that makes the text before it a username, a `:` and a port, a `/` and a path, a `://` and a whole URL — so nothing from the first placeholder on is folded, and a part is folded only when it is complete before that point: the scheme when its `:` comes first, the authority when its end (`/`, `?`, `#` or the end of the template) comes first. `HTTPS://API.example.com/{version}` is `https://api.example.com/{version}` and `HTTPS://API.example.com{basePath}` is `https://API.example.com{basePath}`, while `https://api.example.com{basePath}` and `https://api.example.com{basePath}/` (`/v1` and `/v1/` with `basePath` defaulting to `/v1`), `https://{host}:443/v2` and `https://{host}/v2`, `https://USER{suffix}/v1` and `https://user{suffix}/v1`, or `{prefix}://api.example.com` and `{prefix}://api.example.com/` stay two servers. From the first placeholder on not even percent-encoding is folded, and neither is it in an authority the placeholder sits in: a value may put the text in a scheme or a port, where `%` has no meaning (`{scheme}%73://notes.example.com` and `{scheme}s://notes.example.com`, or `https://api.example.com:4{port}` and `https://api.example.com:%34{port}`, stay two servers), or end in a `%` that joins with the text after it into another octet (`https://{host}/{x}7e` and `https://{host}/{x}%37e` stay two servers); a complete octet before the first placeholder in a path, query or fragment still folds. Every folding thus applies to text whose part and bytes no variable value can change, so two templates read as one resolve to one URL under every value of their variables. Not folded at all: dot-segments (`/v1/../v2` is compared as written) and internationalised host names (`https://bücher.example.com` and `https://xn--bcher-kva.example.com` are two servers). Variable names, defaults and enum values are compared as written, though a changed default is classified by whether it moves a resolved URL (see above). Every `url`, `oldBaseUrl` and `newBaseUrl` a change carries is the spelling of the spec that declares it.

| `variableChanges[].kind`      | Classification                                                                    | Meaning                                                      |
| ----------------------------- | --------------------------------------------------------------------------------- | ------------------------------------------------------------ |
| `variable-added`              | additive                                                                          | A client can now pick it                                     |
| `variable-removed`            | breaking; additive when the template never references it                          | A client can no longer pick it                               |
| `variable-default-changed`    | breaking; additive when the template never references it or no resolved URL moves | The server's resolved URL moves (`oldDefault`, `newDefault`) |
| `variable-enum-added`         | breaking; additive when the template never references it                          | Any value was accepted; now only the listed ones are         |
| `variable-enum-removed`       | additive                                                                          | The restriction is lifted                                    |
| `variable-enum-value-added`   | additive                                                                          | `value` can now be picked                                    |
| `variable-enum-value-removed` | breaking; additive when the template never references it                          | `value` can no longer be picked                              |

**Callbacks.** An operation's or a webhook's `callbacks` (see [Callback](architecture/ir-types.md#callback)) are compared for each pair of operations or webhooks both specs carry, right after the owner's `operation-modified` or `webhook-modified` change — or where it would be, since a callback change is reported even when the owner itself has no other change; an owner only one spec carries is reported as added or removed and says nothing about its callbacks. A callback is identified by `name` + `expression` + `httpMethod`, so an expression or method edit is a `callback-removed` (breaking) beside a `callback-added` (additive), as a webhook's method edit is. A pair is compared exactly as a webhook pair is, from the receiver's side: every rule stated for a `webhook-modified` change in this section — the payload's type, encoding, requiredness and media types, the accepted responses, the parameters, deprecation, security and tags — holds for a `callback-modified` change, which carries the same fields and flags beside the callback's triple and its site: `serviceName` + `operationName` for an operation's callback, `webhookName` + `webhookMethod` for a webhook's, and `parents[]` — the callbacks between the owner and a nested callback, outermost first, each by its triple — present only when nested (a callback declared by a callback operation's own `callbacks` is compared right after its parent, by the same rules, and one whose parent is added or removed reports nothing). So a field the sender adds to the payload is an additive `field-added` on the payload model's `model-modified` change even when required (a callback payload is received, like a webhook's, so the entry reads `required on a response-only model`), while an existing payload field made required is a breaking `field-required-changed` (the command exits 2) and one made optional additive — `field-required-changed` is direction-blind on purpose, on a webhook's payload exactly as on a callback's (see the comment in `diffFields`, `src/differ/models.ts`); a header the sender starts carrying is an additive `param-added`, a header it stops carrying a breaking `param-removed`, an accepted response withdrawn breaking, and the summary and exit code follow: `oagen diff` exits 1 for a callback added and 2 for one removed. The callback's own `deprecated` flip and security change are mirrored into `behaviorChanges` as `callback` nodes, and a parameter's flip as a `callback-parameter` node, each carrying the triple and the site (see **Deprecation** and **Security** below); a document-level security change is read from the receiver's side when a callback inherits the default in both specs, as when a webhook does.

**Deprecation.** A node becoming deprecated, or no longer being deprecated, is reported and is additive in either direction (nothing a caller compiles against changes): `deprecatedChanged: true` on an `operation-modified`, `model-modified`, `enum-modified`, `webhook-modified` or `callback-modified` change, with `oldDeprecated`/`newDeprecated` beside it, and a `param-deprecated-changed`, `header-deprecated-changed`, `field-deprecated-changed` or `value-deprecated-changed` entry — carrying the same two values and `details` reading `live → deprecated` or `deprecated → live` — in that change's `paramChanges` (an operation's, a webhook's or a callback's), `responseHeaderChanges` (an operation's response headers, see Response headers below), `fieldChanges`, `envelopeFieldChanges` (an operation's list envelope fields, see List envelopes below) or `valueChanges`. A change whose only content is the flag is still reported (so the command exits 1), and a breaking change on the same node keeps the change breaking. That holds for an inline copy of a deprecated component too: the copy keeps its qualified model under either flag (`GetLegacyWidgetWidget` for a `getLegacyWidget` response identical to a deprecated `Widget`), so deprecating it is one `model-modified` change with `deprecatedChanged: true`, exit 1, in either direction — never a `model-removed` beside a breaking `responseChanged` (#441). Two such copies sharing that model keep sharing it when one of them is deprecated, the model staying live, so that flip is no change at all (exit 0), as it is between two inline twins; the model flips only once every copy is deprecated. The one flip that is not additive is the component's own beside such copies: an inline copy's name never depends on the copy's flag but on the component's — a live component takes its identical copies, of either flag, under its own name, a deprecated one takes none — so deprecating `Pet` moves every identical copy off it, whether the copies are deprecated in the same edit or already were. `getLegacyPet`'s inline copy of `Pet` goes from `Pet` to `GetLegacyPetPet`, reported as `model-added GetLegacyPetPet` beside a breaking `responseChanged` on `getLegacyPet` and the additive `model-modified Pet` flip, exit 2 (the reverse edit `model-removed`, exit 2): the retype deprecating `Pet` alone has always cost a live copy, now paid whatever the copy's flag. An inline error body's shared model is read the same way (see [Shared error bodies](architecture/ir-types.md#shared-error-bodies)): deprecating one `{ message }` body among twins, or one body's `message`, is no change at all (exit 0), with a warning; deprecating every body, or every body's `message`, is one additive `model-modified ErrorBody` with `deprecatedChanged: true` or one `field-deprecated-changed` (exit 1); and a component `ErrorBody` becoming deprecated, or deprecating its `message`, moves the live bodies off it — `model-added GetPetError404` beside a breaking `errorsChanged` on `getPet`, exit 2 — as deprecating `Pet` does. Only `true` counts as deprecated: `false` and an absent key are the same thing. Each flip is also mirrored into `behaviorChanges` as a `deprecated-changed` entry naming the node (`operation`, `parameter`, `response-header`, `model`, `field`, `envelope-field`, `enum`, `enum-value`, `webhook`, `webhook-parameter`, `callback` or `callback-parameter`) and copying `oldDeprecated`/`newDeprecated` from the change, beside the `param-default-changed` entries collected there; a `response-header` entry also carries the header's `statusCode` or `fallback` when its change does, an `envelope-field` entry the operation and field names, as its `extensions-changed` entry does, and a `callback` or `callback-parameter` entry the callback's `name`, `expression` and `httpMethod` and its site, as its `callback-modified` change does.

**Documentation.** A `description` is not compared on any node — a model's, a field's, an enum's, an enum value's, an operation's, a parameter's, a response header's, a response's, a request body's — so a change to one, including a description appearing or disappearing, is not reported and the command exits 0 when nothing else changed: documentation is not shape, and no change carries a flag for it. A body comparison that reads a model or enum ref through to its shape (see Response media types) ignores documentation the same way.

**Security.** What a request must carry is compared on the document and on every operation, webhook and callback. `ApiSpec.security` — the default every operation, webhook and callback that declares none of its own inherits — differing between the two documents is one `security-changed` change, with `oldSecurity`/`newSecurity` beside it (`[]` when a document declares none; `security: []` and an undeclared list both mean no authentication). An operation, webhook or callback that declares its own list on either side is compared on what it actually requires — its own list, else that document's — and reported with `securityChanged: true` on its `operation-modified`, `webhook-modified` or `callback-modified` change, with `oldSecurity`/`newSecurity` beside it; one that inherits on both sides is not reported again for a moved default. Lists are compared as sets of alternatives, each a set of schemes with scopes as sets, so order and repetition are not changes. The classification is read from the node's side of the wire. For an operation, a caller built for the old list must still satisfy the new one: breaking when some old alternative satisfies no new one (a scheme or scope now required, an alternative removed, an anonymous alternative withdrawn), additive otherwise (an alternative added, a scheme or scope no longer needed, authentication made optional). For a webhook or a callback, a handler built for the old list must still find what it checked for in whatever the sender now presents: breaking when some new alternative carries no old one (a credential the sender stops presenting, an alternative it may now use that the old list never offered), additive otherwise (a credential the sender starts carrying beside the old ones, an alternative withdrawn). The document-level change is read from each side that inherits the default in both documents — the caller's when an operation does, the receiver's when a webhook or a callback does, each matched across the two documents as its own change is (an operation by name within its service, a webhook by name and method, a callback by its owner and its triple) — and is breaking if any such side breaks. No other node reads both defaults: one that declares its own list on either side is compared on its own, as above, and one added or removed is reported as such. When nothing inherits the default in both documents (say the only operation that did now declares the old default as its own list), no request reads both defaults, so the change is additive. A change whose only content is security is still reported, and a breaking change on the same node keeps the change breaking. Every security change is mirrored into `behaviorChanges` as a `security-changed` entry naming the node (`document`, `operation`, `webhook` or `callback`, the last carrying the callback's triple and site as its change does), copying the two lists and carrying the security change's own classification, which stays additive when the owning change is breaking for another reason.

**Security schemes.** The definitions the requirements name — `components.securitySchemes`, `ApiSpec.auth` — are compared by `schemeName` (#384): a requirement names a scheme, and the definition says what a request carrying it puts on the wire, so a scheme that changes its header, its location or its kind under the same name is a change even though no requirement moved. A scheme the new spec declares and the old did not is `security-scheme-added`, with the definition as `scheme`: breaking when the old spec already had the scheme in use under a definition the parser omits from `auth` (`openIdConnect`, an `http` scheme such as `digest`, `mutualTLS`), since every old request carried that and not what the new definition reads — `petKey: { type: openIdConnect, openIdConnectUrl: … }` becoming `{ type: apiKey, in: header, name: X-Key }` under `security: [{ petKey: [] }]` exits 2, as the reverse (a breaking `security-scheme-removed`) does — and additive otherwise. One the old spec declared and the new does not is `security-scheme-removed`, with the old definition as `scheme`: breaking when some request read it — the scheme is in use in the old spec, or a requirement in the new spec still names it, so the spec now requires what it does not define — and additive when nothing read it on either side, as a change to a server variable no template references is. One both declare whose definitions differ in anything but `description` and `x-*` keys (documentation and extensions are never a change) is `security-scheme-modified`, with `oldScheme`/`newScheme` and `details` beside it: breaking when its wire form regressed and the scheme is in use in the new spec, since an SDK built for the old definition sends what the server no longer reads; additive when nothing in the new spec uses it, or when the definition only grew. The wire form is the scheme's `kind`; for an `apiKey` also `in` and `name`; for `oauth2` the `flows` object with its `x-*` keys and each flow's dropped (both objects may be extended, and an extension is not a flow: `clientCredentials: { …, x-note: a }` or `flows: { …, x-note: a }` is no change, exit 0) and each flow's `scopes` map set aside, read the way the security comparison above reads a requirement's alternatives — a flow added beside unchanged ones (`authorizationCode` beside a kept `clientCredentials`), or a `refreshUrl` added to a flow that had none, is an alternative a caller may use and is additive (exit 1), while a flow removed, or a URL a flow already declared (`authorizationUrl`, `tokenUrl`, `refreshUrl`) changed or removed, is breaking in use (exit 2). A flow's scopes are the requirement's to need, which `security-changed` compares, so a scope added, re-described, or removed while no requirement names it is reported but additive — except a scope the old definition offered in some flow, the new offers in none, and a requirement in the new spec still names on the scheme: `petAuth`'s `clientCredentials` scopes going from `{ read:pets, write:pets }` to `{ read:pets }` under `security: [{ petAuth: [write:pets] }]` exits 2, with `details` reading `oauth2 scopes changed; required scope "write:pets" removed`, since the spec now asks for what its definition no longer offers, as it does for a removed scheme a requirement still names. An `apiKey` header's `name` is compared folded, since HTTP header names are case-insensitive (RFC 9110 §5.1), exactly as a header parameter's is (see **Parameters** below): `apiKey: { in: header, name: X-Key }` becoming `name: x-key` is still reported, as `security-scheme-modified` with `details` reading `apiKey in header "X-Key" → in header "x-key"`, but is additive (the command exits 1, in either direction, whether or not the scheme is in use), since every existing caller and handler still works; a respelling that changes letters (`x-api-key`) stays breaking in use, and a query or cookie name is case-sensitive, so `in: query, name: X-Key` becoming `x-key` is breaking in use. `details` reads `apiKey in header "X-Key" → in header "X-Api-Key"` for an `apiKey` whose location or name moved, `apiKey → http basic` (`http bearer`, `oauth2`) for a changed kind, and for an `oauth2` scheme `oauth2 flows changed` when anything but a `scopes` map moved or `oauth2 scopes changed` when only scopes did, either followed by `; required scope "write:pets" removed` (`required scopes "a", "b" removed`, sorted) when a scope a requirement still names is gone. A scheme is in use in a spec when the effective requirement list of at least one of its operations or webhooks — its own `security`, else the document's, else none, the resolution the security comparison above uses — names it, so a document default every operation overrides puts nothing in use, and one a single operation inherits does. Both sides of the wire are treated alike: a scheme a webhook's requirement names is read by the handler, and a changed header name breaks the handler as it breaks a caller. A callback's requirement counts the same way — its own `security`, else the document's — for every callback of every operation and webhook, nested ones included (see **Callbacks** above), so a scheme only a callback names is in use, and renaming its header or dropping its definition is breaking. So, for `GET /pets` under a document-level `security: [{ apiKey: [] }]` with `apiKey: { type: apiKey, in: header, name: X-Key }`, the scheme's `name` becoming `X-Api-Key`, its `in` becoming `query`, or the scheme becoming `{ type: http, scheme: basic }` is each one breaking `security-scheme-modified` (the command exits 2, in either direction); the same edits on a scheme no operation or webhook uses — the default names another scheme, or every operation declares `security: []` — exit 1; a `description` edit alone exits 0. A scheme the parser omits from `auth` (an unsupported `http` scheme, `openIdConnect`, `mutualTLS`; see [AuthScheme](architecture/ir-types.md#authscheme)) is invisible to the diff except as the old side of an added scheme or the new side of a removed one, as above. A scheme declared as a `$ref` to another entry of `components.securitySchemes` (allowed on 3.0.3 and 3.1.0) is read by the parser under the referencing key with the target's definition, so with `petKey: { $ref: '#/components/securitySchemes/sharedKey' }`, `sharedKey: { type: apiKey, in: header, name: X-Key }` and `security: [{ petKey: [] }]`, renaming `sharedKey`'s header to `X-Api-Key` exits 2 as a breaking `security-scheme-modified` on `petKey`, beside an additive one on `sharedKey`, which nothing names directly. `auth` absent and `[]` both read as no schemes. The three kinds are listed after the document's `security-changed` change and before the models — added, then removed, then modified, each in its spec's order — and count as `added`, `removed` and `modified` in the summary. Each is mirrored into `behaviorChanges` as a `security-scheme-changed` entry carrying `schemeName`, `oldScheme` when the old spec declares the scheme, `newScheme` when the new one does, and the change's own classification, beside the `security-changed` entries.

**Tags.** Operations are matched by name within a service, and the parser groups an operation into a service by its first tag that has a name — `tags[0]`, blank and non-string entries dropped and repeats folded, unless it has no ASCII letter or digit (`-`), which names nothing and is passed over (then the path-prefix split, see [Service naming](architecture/ir-types.md#service--operation)), so a `tags` edit is reported by where the operation ends up. When it stays in a service of the same name — any edit that leaves the first entry with a name alone (`['Pets']` → `['-', 'Pets']` included), a first tag respelled to the same service name (`pets` → `Pets`), or a first tag changed to one the split files back under the same path-named service — it is `tagsChanged: true` on the `operation-modified` change, with `oldTags`/`newTags` beside it (`[]` for none; the lists are compared in document order, so a reorder after the first entry counts). When the first entry moves it to a service of another name, there is no `operation-modified` to carry a flag: the diff reports the move, `operation-removed` from the old service (breaking) and `operation-added` to the new one (additive), or `service-removed` (breaking) and `service-added` (additive) when a service goes or comes with it — so swapping `['Pets', 'Store']` to `['Store', 'Pets']` on a document's only operation exits 2. A webhook or a callback belongs to no service, so every edit to its `tags` is `tagsChanged` on its `webhook-modified` or `callback-modified` change. `tagsChanged` is always additive: tags group and document a method and change nothing a caller compiles against. A change whose only content is such a tags edit is still reported (so the command exits 1), and tags are not mirrored into `behaviorChanges`.

**Extensions.** A node's `extensions` — the `x-*` keys the operation, model, field or enum was built with (see [Extensions](architecture/ir-types.md#extensions)) — differing between the two specs is reported and is additive: a key added, removed or given another value, compared deeply with key order aside, an absent key and an empty object both reading as none. It is `extensionsChanged: true` on the `operation-modified`, `model-modified` or `enum-modified` change, with `oldExtensions`/`newExtensions` beside it — each present only when the node had extensions on that side — and a `field-extensions-changed` entry carrying the same two values in a `model-modified` change's `fieldChanges`. A list envelope's fields (`Operation.pagination.envelopeFields`) are compared as a model's fields are (see List envelopes below), so an extension change on one — a scalar companion such as `has_more`, which no model carries — is a `field-extensions-changed` entry in the `operation-modified` change's `envelopeFieldChanges`; a companion object's model is compared like any model, so its fields report under `model-modified`. The flag is present only when the extensions differ, unlike `deprecatedChanged`, so a change report without an extension change keeps its shape. Extensions are not shape: a change to them is never a `field-type-changed`, `param-type-changed` or retyped body, a body comparison that reads a model or enum ref through to its shape ignores them as it ignores documentation, and a breaking change on the same node keeps the change breaking. A change whose only content is an extension change is still reported (so the command exits 1), since an emitter may derive behavior from a key it knows. Each is mirrored into `behaviorChanges` as an `extensions-changed` entry naming the node (`operation`, `model`, `field`, `enum` or `envelope-field`, the last with the operation and field names) and copying `oldExtensions`/`newExtensions` from the change. A parameter, response header, webhook, request body or response object carries no `extensions`, so none is compared there.

**Constraints.** The validation keywords a node carries — its `constraints`, see [Constraints](architecture/ir-types.md#constraints) and [Type constraints](architecture/ir-types.md#type-constraints) — are compared between the two specs on every node that carries them, so a `pattern` narrowed, a `maxLength` lowered or a `minimum` raised is reported (#599): a model's field, a list envelope's field, an operation's, a webhook's or a callback's parameter in any location, a response header, a model's own keywords (an object schema's `minProperties`, `maxProperties` and `dependentRequired`; what is written beside a named union's `oneOf`/`anyOf`) and a named union's variant. The site's own keywords are compared first — a field's or parameter's `constraints`, which equal its type's whenever the type can carry them; a response header's or a variant's type's, since neither carries any of its own — and then, in lockstep, those the type carries at every level under it: an array's `items`, a map's `valueType`, a union's variants, through every nullable wrapper (whose `inner` carries the value's keywords). Each keyword is compared on its own, by value — `dependentRequired` as a map of sets, so a reorder of its names is no change — and every keyword added, removed or changed is named in `details`, old → new, in one fixed order whatever order the document wrote them in, prefixed with the path to a nested level: `maxLength 100 → 10`, `pattern '^pet_[0-9A-Z]{26}$' → '^pet_[0-9A-Z]{12}$'`, `minimum <unset> → 5` for a keyword added, `maxItems 10 → <unset>` for one removed, `uniqueItems <unset> → true`, `dependentRequired {"a":["b"]} → {"a":["b","c"]}` (properties and names sorted), `items.pattern '^tag_' → '^tg_'`, `valueType.maxLength 5 → 3`, `variants[1].minimum 0 → 1`, `items.items.maxLength 10 → 5`, several joined with `; `. A union's variants pair by type (`typeRefsEqual`, which passes over limits) — a variant that is itself a union pairing also with the union it only widened (see Inline unions below), so the kept variants of a widened inner union are compared too (`variants[1].variants[0].maxLength 100 → 10`) — an old variant carrying the same limits preferred, so a reorder of two string variants that differ only in `pattern` reports nothing, a kept variant whose `pattern` moved reports under the new variant's index, and a union that gained a variant still reports its kept variants' limits; two levels of different kinds (an array become a string) are left to the type change that reports them, and a model or enum reference carries no limits at the site (the model's own are compared with the model, under its own `model-modified`). The change is a `field-constraints-changed` entry in `fieldChanges` or `envelopeFieldChanges`, a `param-constraints-changed` entry in `paramChanges`, a `header-constraints-changed` entry in `responseHeaderChanges`, a `variant-constraints-changed` entry in `variantChanges` (naming the new variant by its label, as `variant-added` does), or `constraintsChanged: true` on the `model-modified` change with `details` beside it, each carrying `oldConstraints`/`newConstraints` — the site's own keywords on each side (the type's for a header or a variant), present when it declares any there, so a change on a nested level alone carries two equal sides, or none, and names the level in `details` — and reported beside, not instead of, whatever else changed about the node (a `field-type-changed`, a `param-format-changed`). A change whose only content is a limit is still reported, tightened or loosened (the command exits 1 or 2 by its classification), as a deprecation flip is.

A keyword is **tightened** when the new declaration can reject a value the old one admitted, **loosened** when it cannot:

| Keyword                                  | Tightened                                                                                                                                                                                                                                                                                                                                                                       | Loosened                                                                                                                           |
| ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `minimum`, `exclusiveMinimum`            | the lower bound the two make together — the stricter when both are declared — added, raised, or made exclusive at the same value; on an `integer` an exclusive bound is read as the inclusive one beside it first (`exclusiveMinimum: n` is `minimum: ⌊n⌋ + 1`, a fractional `minimum` is rounded up), so `exclusiveMinimum: 0` → `minimum: 1` is reported but tightens nothing | removed, lowered, or made inclusive at the same value                                                                              |
| `maximum`, `exclusiveMaximum`            | the upper bound the two make together added, lowered, or made exclusive at the same value; on an `integer` read as the inclusive one first (`exclusiveMaximum: n` is `maximum: ⌈n⌉ − 1`), so `maximum: 9` → `exclusiveMaximum: 10` tightens nothing                                                                                                                             | removed, raised, or made inclusive at the same value                                                                               |
| `maxLength`, `maxItems`, `maxProperties` | added, or lowered                                                                                                                                                                                                                                                                                                                                                               | removed, or raised                                                                                                                 |
| `minLength`, `minItems`, `minProperties` | raised, an absent side read as its default (`0`): added above the default, or removed from below it                                                                                                                                                                                                                                                                             | lowered, likewise: removed from above the default, or added at or removed from it (`minLength: 0` is reported but rejects nothing) |
| `minContains`, `maxContains`             | never: they bound what `contains` matches, which the IR does not carry, and constrain nothing without it, so a change to them is reported in `details` but classified additive either way                                                                                                                                                                                       | —                                                                                                                                  |
| `pattern`                                | added, or changed (a rewritten pattern admits other values in general)                                                                                                                                                                                                                                                                                                          | removed                                                                                                                            |
| `multipleOf`                             | added, or changed (the new multiple need not divide the old)                                                                                                                                                                                                                                                                                                                    | removed                                                                                                                            |
| `uniqueItems`                            | added (`true`)                                                                                                                                                                                                                                                                                                                                                                  | removed                                                                                                                            |
| `dependentRequired`                      | a property requiring a name it did not (one newly listed with names, or the keyword added with any)                                                                                                                                                                                                                                                                             | removed, names only taken away, or added with no names (`{ a: [] }` requires nothing)                                              |

An entry is tightened when the limits tightened at any level it names, loosened otherwise. OpenAPI 3.0's boolean `exclusiveMinimum: true` beside `minimum: 0` is read as `exclusiveMinimum: 0` (see the IR types reference), so flipping it on is `minimum 0 → <unset>; exclusiveMinimum <unset> → 0`, tightened (the bound at `0` became exclusive), and flipping it off — or `exclusiveMinimum: 0` becoming `minimum: 0` in 3.1 — is the reverse, loosened: the `0` it rejected is admitted again, exit 1. `{ minimum: 5, exclusiveMinimum: 0 }` losing its `exclusiveMinimum` is reported but loosens nothing, since the inclusive `5` was the stricter bound. On an `integer` — a primitive of that type, under any nullable wrapper — an exclusive bound admits the same integers as the inclusive one beside it, so the bounds are read as inclusive before they are judged (`exclusiveMinimum: n` as `minimum: ⌊n⌋ + 1`, `exclusiveMaximum: n` as `maximum: ⌈n⌉ − 1`, a fractional inclusive bound rounded inward, the stricter of a side's two winning): `exclusiveMinimum: 0` → `minimum: 1`, OpenAPI 3.0's `{ minimum: 0, exclusiveMinimum: true }` → `{ minimum: 1 }` and `maximum: 9` → `exclusiveMaximum: 10` are each reported — the declaration changed, and `details` names the keywords as written (`minimum <unset> → 1; exclusiveMinimum 0 → <unset>`) — but tighten nothing and are additive, exit 1, as `minLength: 0` added is, while `exclusiveMinimum: 0` → `minimum: 2` is tightened. On a `number`, or a type the differ cannot read as one integer (a union, a model), the bounds are read as written: `0 < x` admits `0.5` and `1 <= x` does not, so the same rewrite on a number is tightened. An exclusive integer bound whose neighbor is not a safe integer (at or beyond 2^53) is read as written too, since the neighbor cannot be represented, so `minimum: 9007199254740992` → `exclusiveMinimum: 9007199254740992` is tightened. A keyword written on a type it cannot constrain — `maxLength: 5` on an integer, legal in OpenAPI 3.1 and kept by the parser — rejects nothing, so it is reported but never tightened or loosened: the keywords judged are the string ones (`minLength`, `maxLength`, `pattern`) on a `string` or a string literal, the numeric ones on an `integer` or `number`, the array ones on an `array`, the object ones (`minProperties`, `maxProperties`, `dependentRequired`) on a map, none on a `boolean`, a union's by every variant's, and every keyword on a type the differ cannot read — an `unknown`, a model or enum reference (the keywords written beside a `$ref`), a model's own. A literal — a `const`, or a single-member `enum` — admits exactly one value, and an enum reference the IR carries the `values` of admits exactly those, so on either a limit tightens only when some value the old limits admitted the new reject: `{ const: 'abc', maxLength: 5 }` → `maxLength: 3` is reported but additive, exit 1, since `'abc'` still fits, while `maxLength: 2` rejects it and is breaking; where the old type's values are known too, only a value both list is judged, since one the new enum adds was never admitted — `{ enum: ['a', 'bb'], maxLength: 5 }` → `{ enum: ['a', 'bb', 'cccc'], maxLength: 3 }` tightens nothing, as `'a'` and `'bb'` still fit and `'cccc'` is new; a string's length is counted in code points against `minLength`/`maxLength`, a number against its bounds and an integer `multipleOf`, and a `pattern` or a `multipleOf` the differ cannot evaluate exactly (no regular expression is built from a document; a non-integer multiple) is judged as on any string or number. The classification follows the side of the wire the value travels on:

| Site                                                                                                                     | Tightened                                                         | Loosened |
| ------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------- | -------- |
| A field, the model's own keywords or a named union's variant on a request-facing, both-facing or unknown-direction model | breaking (a value a caller sends today can be rejected)           | additive |
| A field, the model's own keywords or a variant on a response-only model; a list envelope's field                         | additive, `details` ending `; tightened on a response-only model` | additive |
| An operation's parameter (path, query, header, cookie)                                                                   | breaking                                                          | additive |
| A webhook's or a callback's parameter                                                                                    | additive                                                          | additive |
| A response header                                                                                                        | additive                                                          | additive |

So for the `Pet` of #599 — `name: { type: string, maxLength: 100 }`, `id: { type: string, pattern: '^pet_[0-9A-Z]{26}$' }`, taken by `createPet` and returned by `getPet` — with `getPet`'s path parameter `petId` of the same pattern and query parameter `limit` of `{ type: integer, minimum: 1 }`, the document that lowers `maxLength` to 10, raises `minimum` to 5 and rewrites both patterns to `{12}` reports two breaking `field-constraints-changed` entries on `model-modified Pet` and two breaking `param-constraints-changed` entries on `operation-modified getPet`, exit 2; the reverse edit reports `maxLength 10 → 100` and `minimum 5 → 1` additive and the two rewritten patterns breaking still, exit 2; lowering `maxLength` alone exits 2 and raising it alone exits 1, on OpenAPI 3.0 and 3.1 alike. A loosened limit is additive from either side because the wire base type is unchanged, as a format change is, and a tightened one on a read-only site because the SDK only reads the value — an emitter that types a `pattern` as a template literal may still change a signature, which its own compat check reports, as for `field-format-changed`. Limits are not mirrored into `behaviorChanges`. A limit on an inline body's own type — a `maxLength` on a `text/plain` request or response body, a `pattern` on the items of an array body, under any media type — is still not reported: a body's model, when it has one, is compared as any model is, and a body typed in place has no flag to carry its limits (see Response media types below).

**Parameters.** An operation's parameters are compared in every location it carries them — path, query, header and cookie — and a webhook's or a callback's in header, query and cookie, through one walk, so a change is reported wherever the parameter lives. Parameters are matched by location and name (`parameterKey` in `src/ir/parameter-key.ts`, the identity the parser merges path-item and operation parameters on) — OpenAPI allows a path `id` beside a query `id` on one operation — and every `paramChanges` entry carries `paramLocation` (`path`, `query`, `header` or `cookie` on an operation; `header`, `query` or `cookie` on a webhook or a callback) to say which one it is about. A header's name is matched case-insensitively, since HTTP header names are (RFC 9110 §5.1): a header written `X-Pet-Token` in one spec and `x-pet-token` in the other is one parameter, its type, limits (`param-constraints-changed`, see Constraints above), requiredness, default and `deprecated` compared as usual, and the spelling change is a `param-name-changed` entry — additive, with `oldName`/`newName` and `details` reading `name X-Pet-Token → x-pet-token` — beside whatever else changed, not a `param-removed` beside a `param-added`. The inline enum or model a header's schema mints is named from the lower-cased header name on both sides (`PetsXRatelimitPolicy` for `X-RateLimit-Policy` and `x-ratelimit-policy` alike; the same for a response header's), so a case change leaves the header's type, and the `enums` and `models` lists, where they were: no `param-type-changed`, no `enum-removed`, no `model-removed`. On the entries of a paired parameter, `paramName` is the name as the new spec writes it; a `param-removed` entry carries the old spec's name, which the new spec no longer has, and a `param-added` entry the new spec's. Path, query and cookie names are case-sensitive, so `Limit` and `limit` are two query parameters. A `param-name-changed` entry is not mirrored into `behaviorChanges`. A query parameter the request body owns (`Operation.bodyOwnedQueryParams`: declared as a body property too, on a body-carrying method) is not compared as a parameter — it travels in the body, whose model the differ compares field by field — so a query parameter the body takes over is reported as `param-removed` at `query`. A parameter's media type — its `contentType`, the `content` key its value is serialized under; for a `content` map none of whose media types is read, the first of its `contentTypes`; none for a `schema` parameter (see `Parameter` in [docs/architecture/ir-types.md](architecture/ir-types.md)) — is compared by media type essence (`type/subtype`, case folded, parameters stripped): a parameter that moves from `schema` to `content` or back, an unread map included (`schema` → `application/xml`), or between two essences (`application/json` → `text/plain`, `application/json` → `application/xml`), is a `param-content-type-changed` entry, breaking in both directions and on a webhook too, since the value is encoded another way on the wire. So is a map read on one side only that keeps its essence (a JSON entry that gained or lost its schema), since an unread map's string value is sent as written. A move between two JSON media types the parser reads (`application/json` and any `+json` type: `application/json` → `application/vnd.api+json`, or between two `+json` types) is reported too, but additive: the value is JSON-encoded on both sides, so nothing a caller sends or a handler decodes changes. The entry carries `oldContentType`/`newContentType` (each as written, `null` for the `schema` side) and `details` reading `content type <schema> → application/json`, an unread side followed by `(unread)` (`content type <schema> → application/xml (unread)`), and is reported beside, not instead of, whatever else changed about the parameter — a parameter whose schema is the same on both sides reports it alone, with no `param-type-changed`, `enum-removed` or `model-removed`. A respelling that keeps the essence (`application/json` → `application/json; charset=utf-8`) is not reported. The entry is not mirrored into `behaviorChanges`.

**Request body requiredness.** `requestBodyRequired` — whether a caller must send the body — flipping between the two specs is reported as `requestBodyRequiredChanged: true` on the `operation-modified` change: optional → required is breaking (callers must now send a body; the command exits 2), required → optional is additive (exit 1). The flag is compared whenever both specs carry a body the parser keeps it on: one read as `requestBody`, or one carried in `requestBodyContents` alone because none of its media types is read — `application/xml`, or the media range `application/*+json` (see [Request Body Required](architecture/ir-types.md#request-body-required)). An SDK that offers such a body through its contents makes the argument mandatory by the flag just the same, so `createPet`'s body under `application/xml` alone going from `required: false` to `required: true` is the same breaking change, and the same exit `2`, as under `application/json`, and the reverse flip the same additive change (exit `1`), on OpenAPI 3.0 and 3.1 alike. It is compared whichever way each spec reads the body: a body carried in its contents in the old spec and read as `requestBody` in the new, with the flag flipped, sets `requestBodyRequiredChanged` beside the `requestBodyChanged` and `requestBodyContentTypesChanged` such a pair already set. An absent flag beside a carried body reads as optional, as it does in OpenAPI; a body that declares no media type (`content: {}`) keeps no flag and has nothing to compare. A body appearing or disappearing takes its flag with it: one read as `requestBody` is `requestBodyChanged` alone, one carried in its contents alone is not reported. On a `webhook-modified` change the same comparison, read from the receiver's side, sets `requestBodyChanged` with `details` saying `body optional → required` (additive: the payload is now always there) or `body required → optional` (breaking: a handler that assumed a payload may get none), for a payload read as `requestBody` or carried in its contents alone alike.

**Request body encoding.** `requestBodyEncoding` — the wire format a body is serialized as, read from the media type it is declared under: `json`, `form-data`, `form-urlencoded`, `binary` or `text` — differing between the two specs while both carry a `requestBody` is reported as `requestBodyEncodingChanged: true` on the `operation-modified` change, with `oldRequestBodyEncoding`/`newRequestBodyEncoding` beside it. An SDK built for the old spec keeps serializing the body and labelling the request as that spec said, so the change is breaking when the new spec no longer accepts that representation — the media type the old body was read from is gone from its `requestBodyContentTypes`, or the body under it changed shape, compared as `retyped` is (`application/json` where the server now reads only `application/x-www-form-urlencoded`) — and additive when it still does, as when a media type the parser prefers is added beside it (`application/json` added beside a kept `application/x-www-form-urlencoded`: the parser now reads the body from JSON, existing callers keep sending the form body, and the server still reads it). A kept media type whose inline schema the parser names differently on the two sides (`CreatePetRequest` while it is the body `requestBody` is read from, `CreatePetApplicationXWwwFormUrlencodedRequest` once JSON is preferred) is still the same representation: the two models are compared field by field through the two specs' models, as `retyped` is, not by name. A body without media-type lists reads as breaking. A body appearing or disappearing takes its encoding with it and is `requestBodyChanged` alone; a body carried in `requestBodyContents` alone on either side, which no encoding is read from, reports only what its media types did (below); a body that changes type and encoding at once sets `requestBodyChanged` and `requestBodyEncodingChanged`. The encoding flag is reported beside the request body media-type comparison (below): a body moving from `application/json` to `application/x-www-form-urlencoded` sets `requestBodyEncodingChanged` and `requestBodyContentTypesChanged` both (the JSON media type is removed, the form one added), while a media type changing essence within one encoding (`application/json` → `application/vnd.api+json`) sets `requestBodyContentTypesChanged` alone. On a `webhook-modified` change the same comparison — made only while both specs carry a `requestBody`, as on an operation; a payload appearing or disappearing is `payload added` / `payload removed` alone and carries neither field, and one carried in its contents alone on either side carries neither too — sets `requestBodyChanged` with `details` saying `encoding json → form-urlencoded` and the same two fields beside it, breaking from the receiver's side when the representation the sender now uses — the media type the new payload is read from, with its shape — is not one the old spec declared with that shape (the handler decodes a wire format it never saw), additive when it is (a media type dropped beside one the handler already decoded). A change whose only content is the encoding is still reported (the command exits 2 when it is breaking, 1 when it is additive), and the encoding is not mirrored into `behaviorChanges`.

**Response media types.** An `operation-modified` change lists, per response entry both specs declare, the media types the new spec `added` (additive), `removed` (breaking) or `retyped` (breaking) under `responseContentTypeChanges`, keyed by `statusCode` or, for the `default` and range responses, by `fallback`. Media types are matched by essence — `type/subtype`, case folded, parameters stripped — the rule the parser types a body by, so `Text/HTML` is `text/html` and `application/problem+json; charset=utf-8` is `application/problem+json`: a key that only changed case, whitespace or `charset` is no change, and reordering the keys is none either. A pair whose parameters other than `charset` differ (`application/pdf; version=1.7` → `; version=2.0`, a `profile` on `application/ld+json`) is listed under `reparameterized` with both spellings, additive: the body is typed the same, but the parameter may select another representation, so the change stays visible without being called breaking. Parameters are read as RFC 9110 writes them — a `;` inside a quoted value does not end the parameter, backslash escapes are decoded, the quotes are not part of the value — and compared as name/value pairs with names case-folded, in any order (never as one joined string, so `title="report; version=2"` and `title=report; version=2` are different parameters). Each media type is reported as written in the spec that declares it. Two keys of one essence declared side by side (`application/json` beside `application/json; charset=utf-8`) stay two media types: each pairs, in this order of preference, with the key spelled the same way on the other side, else one of its essence with the same parameters other than `charset` (so `Application/YAML; version=1` is still `application/yaml; version=1` wherever it moved), else one of its essence whose body is the same shape (so a key that only edited a parameter finds its body), else the other side's next unpaired key of its essence in document order; one left over is added or removed. A model the parser mints for a secondary media type is named from the essence too (`GetReportApplicationYamlResponse` for `application/yaml` and for `application/yaml; charset=utf-8` alike), so a key that only respells itself keeps its model name and is not reported as retyped; beside another key of its essence, from the parameters compared here (`charset` left out, the rest sorted, so `…ApplicationYamlA1B2Response` for `; b=2; a=1` and for `; a=1; b=2`), plus `Charset` without its value when a `charset` is all that tells two keys apart (`…ApplicationYamlCharsetResponse`), and keys still left with one name are named in one order whatever the document's. So a `charset` edit, a parameter's value quoted or a space dropped, and a reorder of the keys or of a key's parameters rename no model — but for the two exceptions below — and neither does a key told apart by a parameter other than `charset` added beside one that has none (`application/yaml; version=2` beside `application/yaml; charset=utf-8`). Two exceptions follow from naming by the keys alone: keys left with one name are ordered by their case and `charset` (case-only spellings, or keys that differ only in the `charset` both declare), so a case or `charset` edit that changes that order swaps their models, while keys that differ only in how they quote, space or order their parameters keep their document order, so reordering them does; and a key without parameters declared beside a `charset` key renames that key's model `…CharsetResponse` (`application/yaml` added beside `application/yaml; charset=utf-8`, whatever else is declared beside them). `retyped` means the body's shape changed: two bodies that are both models are compared field by field through the two specs' models (nested models and enums included, documentation aside), not by name — unless both specs declare both names, since then neither was renamed: a body moved from `Note` to an identical `NoteCopy` that both specs declare is `retyped`, as the generated SDK now types it by another model and no `model-removed` or `model-added` reports it. So when a key declared beside another spelling of its essence edits a parameter other than `charset` (`application/yaml; version=1` → `application/yaml; version=3`), which renames the model the parser mints for it, the body is reported as `reparameterized` (additive) and not as `retyped`; the rename surfaces as `model-removed` + `model-added`, which is what the generated SDK actually loses and gains. A schema change under such a key is still `retyped`; a limit edited on the body's type alone — a `maxLength` on a `text/plain` string, a `pattern` on an array's items — is not, and is not reported at all (a limit edited on a field or a parameter is, as a `field-constraints-changed` or `param-constraints-changed` entry, see **Constraints** above), while under a renamed model a field's limits and those its type carries on its items, values or variants are shape, so a model renamed and narrowed at once is `retyped` (see Type constraints in the IR types reference). The same holds for a secondary body on an error, `default` or range response.

**Request body media types.** The media types a request body may be sent as — the `content` keys of the Request Body Object, carried as `requestBodyContentTypes` / `requestBodyContents` — are compared the same way, while both specs declare a body (one read as `requestBody`, or one carried in `requestBodyContents` alone: `createPet`'s body under `application/xml` alone gaining `text/csv` is reported although no encoding is read from such a body; a body appearing or disappearing is `requestBodyChanged` alone). On an `operation-modified` change, `requestBodyContentTypesChanged: true` comes with `requestBodyContentTypeChange` listing the media types `added` (additive: callers can newly send it), `removed` (breaking: a representation callers could send is gone) and `retyped` (breaking; only ever a secondary media type, since the body `requestBody` is read from is `requestBodyChanged`'s). As for responses, `retyped` is decided by shape, not by name, unless both specs declare both names: a `<Op><MediaType>Request` model that a parameter edit on a sibling-distinguished key only renamed is not a retype and surfaces as `model-removed` + `model-added`, while a form body beside JSON moved from `Note` to an identical `NoteCopy` that both specs declare is `retyped`, since neither was renamed. A changed parameter other than `charset` is `reparameterized`, additive, on an operation and on a webhook alike (`details` reads `payload media type text/csv; version=1 → text/csv; version=2`). On a `webhook-modified` change the same comparison is read from the receiver's side and sets `requestBodyChanged` with `details` such as `payload media type text/csv added`, beside a `requestBodyContentTypeChange` with the lists: a media type the sender can newly use, or whose body changed shape, is breaking (the handler must decode it); one it can no longer use is additive.

**Response headers.** An `operation-modified` change lists, per response entry both specs declare, the headers the new spec added, removed, retyped, re-required, respelled, deprecated or re-limited under `responseHeaderChanges`, each entry carrying `headerName` as written in the spec that declares it (the new spec's spelling for a header both declare) and the response entry it belongs to: `statusCode` for an entry with an explicit status code — the primary success response when the operation declares more than one 2xx/3xx response, every other 2xx/3xx entry and every error — `fallback` for the `default` and range responses, and `Operation.responseStatusCode` as `statusCode` for a lone 2xx (neither only for a hand-built IR whose lone 2xx carries no code). A change is located at the entry of the spec that declares what changed: `header-removed` at the old spec's entry, every other kind at the new spec's — so an operation that lost its only 2xx (a lone `200` that became a lone `404`), whose new primary carries no code, reports that entry's headers removed under `200`; a `responseContentTypeChanges` entry that only removes, when the new spec's entry carries no code, is located at the old spec's entry the same way. Entries pair up between the two specs as they do for `responseContentTypeChanges` (see Success status below), and headers within an entry by name case-insensitively, as HTTP compares header names (RFC 9110 §5.1): `X-Rate-Limit` and `x-rate-limit` are one header, so a case-only rename is one additive `header-name-changed` entry with `oldName`/`newName` beside it rather than a removal beside an addition; two names of one folding declared side by side stay two headers, paired by exact spelling first. The SDK reads these headers off the response and never sends them, so each kind is classified from the reader's side, as a webhook's parameters are: `header-added` is additive, required or not (the server simply starts sending it); `header-removed` is breaking (an accessor the SDK exposed is gone); `header-type-changed` is breaking and `header-format-changed` additive, with the two formats in `details`, as for a parameter; `header-required-changed` is additive for optional → required (the header is now always sent) and breaking for required → optional, `details` saying which; `header-deprecated-changed` is additive either way, with `oldDeprecated`/`newDeprecated` and `details` beside it, and is mirrored into `behaviorChanges` as a `deprecated-changed` entry with `node: 'response-header'` (see Deprecation above); `header-constraints-changed` — the limits the header's type carries, at every level, `details` naming every keyword that moved (`pattern '^req_' → '^rq_'`, `items.maxLength 10 → 5`) with `oldConstraints`/`newConstraints` beside it — is additive either way, since the SDK only reads the header (see Constraints above). A 2xx the old spec declared and the new does not has no other flag to report its headers, so each is `header-removed`; an error or fallback response only one spec declares is `errorsChanged` or `fallbackResponsesChanged` alone, and a 2xx the new spec adds is no header change. A change whose only content is a header is still reported (the command exits 1 or 2 by its classification). A webhook's accepted responses carry no headers in the IR, so a `webhook-modified` change has no such list.

**Success status.** Response entries pair up between the two specs by status code — every 2xx/3xx entry, the primary among them (a lone 2xx by `Operation.responseStatusCode`, the code the parser read `response` from), and every error — so a lone `201` pairs with the other spec's `201` whether that spec declares it alone or beside a `200` it added, and the added `200` is no header or media-type change. When neither primary has a counterpart by code, both carry one, and each is its side's only 2xx/3xx, the primary moved (a lone `201` became a lone `200`): the two primaries pair and the move is reported once, as `responseStatusCodeChanged: true` on the `operation-modified` change with `oldResponseStatusCode`/`newResponseStatusCode` beside it, rather than every header and media type as removed under one code and added under the other. A primary replaced among several 2xx is no move: `POST /pets` with a `200` (`application/json`, header `X-Pet-Id`) beside a `202`, whose `200` becomes a `201`, no longer declares the `200`, so what the `200` declared is reported removed under `200` — a breaking `responseContentTypeChanges` entry with `removed: ['application/json']` and a breaking `header-removed` for `X-Pet-Id` — exactly as when the `200` is dropped beside the kept `202`, with `responseStatusCodeChanged` (`200` → `201`) beside them, and the new `201` is a 2xx the new spec adds, which is no header or media-type change; the same holds when only one side declares several (a lone `200` that became a `201` beside a new `202` reports the `200` removed). `responseStatusCodeChanged` is set whenever both specs carry a code and the two differ — a `201` that became the primary beside a `200` whose body lost its schema included — and is breaking unless the new spec still declares the old code. "Declared" is the 2xx/3xx codes the new operation answers with — `Operation.responseStatusCode` and every `successResponses` entry; errors, `default` and range responses do not count. So a lone `200` that became a lone `201`, a lone `302` (with a `Location` header) that became a lone `301`, a lone `200` that became a lone `204`, and the `200` beside a `202` that became a `201` above are each breaking (the command exits 2): a caller that checks the declared code — generated code, or the smoke helpers in `@workos/oagen/smoke` that read `responseStatusCode` — stops matching, and a redirect moving between temporary and permanent changes what caches may do. The `200` added beside a lone `201`, which makes the `200` the primary, is additive (exit 1): the `201` is still declared, so a caller built for it still works. So is the move when a `201` becomes the primary beside a `200` whose body lost its schema: the `200` is still declared, and what breaks there is its body, reported as a `retyped` entry under `200` in `responseContentTypeChanges` (`removed`, when the body is gone altogether) — the reverse edit, the `200` regaining its body beside the kept `201`, is additive throughout. The flag is not mirrored into `behaviorChanges`. An operation gaining or losing its only 2xx/3xx is not a move, but it is still reported: as `responseChanged: true`, breaking, whether or not that response has a body. `response` is `unknown` both for a 2xx/3xx without a body (a lone `204` or `302`) and for none at all, so `responseStatusCode` appearing or disappearing is what tells the two apart. Only a hand-built IR whose lone 2xx carries no code falls back to pairing it with the entry of the other spec that offers its media types, else with that spec's primary; an operation that declared no 2xx/3xx pairs with nothing, so every 2xx the new spec adds to it is no header or media-type change — the operation is already reported as `responseChanged`.

**Named unions.** A `model-modified` change on a named union (`Model.variants`) lists what moved under `variantChanges`, each entry naming the `variant` by a short type label (`Cat`, `nullable<Cat>`, `array<Cat>`). Variants are matched by type, not by position, so a reorder is no change. `variant-added` is additive, like a new enum value, from either side of the wire — a caller may construct the new variant but need not, and a reader may receive it as it may a new enum value; a required field the union model itself gains is a `field-added` entry, judged by direction as any field is. `variant-removed` is breaking. A discriminator mapping entry that comes with an added variant — a new key whose target is a model no variant of the old union names, under any wrapper (`nullable<Cat>` added beside a kept `Cat` brings no new model, so a key for `Cat` added with it is an alias) — or goes with a removed one is part of that variant's entry, carried as its `details` (`mapping added for 'bird'`, `mapping removed for 'dog'`, the keys of every model the variant names listed once each and sorted) and not reported on its own, so a variant added to a discriminated union is additive whether the spec writes the `mapping` or the parser derives it from the variants' consts; an entry of an undiscriminated union carries no `details`. Every other discriminator change is one breaking `discriminator-changed` entry, since it changes how an existing payload is dispatched: the discriminator added or removed (`details` says which), moved to another property (`property changed from 'kind' to 'type'`), or its mapping changed for a key the old union dispatched otherwise — retargeted, added for a model the old union already dispatched to (or for no variant), or removed while its model stays — with `mapping changed for 'dog'` naming every such key, sorted. A change of composition keyword between two unions is one breaking `composition-changed` entry (`composition changed from 'anyOf' to 'oneOf'`); a model that becomes or stops being a union reports each variant added or removed instead. A kept variant whose type carries other limits — a string variant's `pattern`, an array variant's items' `maxLength` — is a `variant-constraints-changed` entry naming the variant by its label, with `oldConstraints`/`newConstraints` and `details` beside it, judged by the union's direction as a field's limits are (see Constraints above): breaking when tightened on a union that is not response-only, additive otherwise; the keywords written beside the union's own `oneOf`/`anyOf` are `constraintsChanged` on the `model-modified` change. An inline-union variant that gained a variant is still a `variant-removed` beside a `variant-added` (variants match by type), and, when a variant it kept carries other limits, a `variant-constraints-changed` beside them naming the new variant (`variants[0].maxLength 100 → 10`). An allOf+oneOf dispatcher — a model with `discriminator` and no `variants`, whose mapping alone names what it dispatches to — is compared as a union of the mapping's targets, so a target added to or removed from its mapping is the same `variant-added` or `variant-removed`. A change whose only content is a variant entry is still reported (the command exits 1 or 2 by its classification), and variant entries are not mirrored into `behaviorChanges`.

**Inline unions.** A union written inline — a field's type, or an operation's response or request body, bare or under the same `nullable`, array or map wrapper on both sides (a field typed as an array of a `oneOf`) — is not a model, so it is compared as one type, by its variants in order and its discriminator, with one exception: a union that only gained variants is additive, as a variant added to a named union is, from either side of the wire. It only gained variants when the old variants are all still there in their order, every other variant is one no old variant is (inserted anywhere among them), and nothing else changed but what a named union's `variant-added` carries: the same composition keyword, and the same discriminator but for the mapping keys the new variants bring, judged as under Named unions. An old variant is still there when the variant in its place is the same (its composition keyword included, through every wrapper and nested union), or is itself a union — bare or under the same wrapper — that only gained variants by this same rule: a union that widens a variant which is itself a union is still only a widening (`pet: { oneOf: [Cat, { oneOf: [Dog, Fish] }] }` gaining `Bird` in the inner `oneOf` is `variant Bird added`), and what the inner union gained is listed with what the outer one did, in order. The discriminator is read the same at every site — a request body's mapping targets are stripped of `#/components/schemas/` as a field's or a response's are — so a key the new variant brings is part of its addition wherever the union is written. On a field that is a `field-type-changed` entry classified additive, its `details` naming the variants by the labels Named unions uses (`variant Bird added`, `variants Bird, Fish added`); on an operation it sets `responseChanged` or `requestBodyChanged` without making the change breaking. A kept variant whose limits moved is still kept — limits are not type — and on a field they are reported beside the widening as a `field-constraints-changed` entry naming the variant by its new index (`variants[0].pattern '^pet_' → '^pt_'`; see Constraints above), a kept variant of a widened inner union included (`variants[1].variants[0].maxLength 100 → 10`), so a field that widens its union and tightens a kept variant at once is additive for the widening and breaking for the limit. Every other difference stays a breaking type change (`field-type-changed` with `details` reading `type changed`, or a breaking `responseChanged` or `requestBodyChanged`): a variant removed or swapped for another, the old variants reordered or one repeated (in the union itself or in a variant that is one), a mapping key retargeted, added for a variant the old union already had or for none, or dropped while its variant stays, the discriminator added, removed or moved, a variant added beside a changed composition keyword (the union's own or an inner union's), a member added to an `allOf` (which narrows it), a wrapper added or removed, and an operation gaining or losing its only 2xx/3xx whatever its body. A union written anywhere else — a parameter's or a response header's type, any response body but the primary success one, a secondary media type's body, a webhook's payload — is still compared as one type.

**List envelopes.** When the parser unwraps a list envelope, the envelope's other properties — the pagination companion (`has_more`, `list_metadata`, `total_count`, …) and any discriminant such as `object: "list"` — are `Operation.pagination.envelopeFields` (see [PaginationMeta](architecture/ir-types.md#paginationmeta)), which an emitter types the envelope from beside the data array. While both specs paginate they are compared as a model's fields are, matched by name, an absent list reading as no field, and what changed is listed under the `operation-modified` change's `envelopeFieldChanges` (present only when there is an entry) with the entries and classifications a model's `fieldChanges` would carry, the envelope judged as a response-only model since the SDK only ever reads it: a field added is an additive `field-added`, a required one included (`details` reading `required on a response-only model`); a field removed is a breaking `field-removed`; a field retyped is a breaking `field-type-changed`, except that a format-only change is an additive `field-format-changed` and an inline union that only gained variants is additive (see Inline unions above); and `field-required-changed`, `field-access-changed`, `field-deprecated-changed` and `field-extensions-changed` report the rest as on a model's field, the last two mirrored into `behaviorChanges` as an `envelope-field` node (see Deprecation and Extensions above), while a limit tightened or loosened on a companion (`total_count`'s `minimum`) is a `field-constraints-changed` entry that is additive either way, as on a response-only model (see Constraints above). The operation is breaking when an entry is, so `total_count` added to a `{ data, has_more }` envelope exits 1, and removed or retyped exits 2. A companion object's own fields are compared on its model under `model-modified`; its envelope field is an entry only when the field itself changes, the model it names included (`ListMetadata` → `Pagination` is a `field-type-changed`). Envelope fields are not compared while only one spec paginates, which `paginatedChanged` reports, and a list response kept as a model (a `$ref` to a component, say) carries none: that model's fields are compared under `model-modified`.

## `oagen extract`

Extract the public API surface from an existing SDK. Produces a JSON file used as input for compat overlay and verification.

```bash
oagen extract --sdk-path ./existing-sdk --lang ruby --output ./sdk/sdk-ruby-surface.json
oagen extract --sdk-path ./existing-sdk --lang ruby --output my-surface.json
```

| Argument            | Required | Default                   | Description                                                                                                     |
| ------------------- | -------- | ------------------------- | --------------------------------------------------------------------------------------------------------------- |
| `--sdk-path <path>` | Yes      |                           | Path to the live SDK                                                                                            |
| `--lang <language>` | Yes      |                           | Target language                                                                                                 |
| `--output <path>`   | No       | `sdk-{lang}-surface.json` | Output file path (recommend writing to your output dir, e.g. `./sdk/sdk-ruby-surface.json`, and gitignoring it) |

## `oagen compat-extract`

Extract a compat snapshot from a live SDK and write it to a JSON file. The snapshot is a machine-readable record of the SDK's public API surface, used as input to `compat-diff`.

```bash
oagen compat-extract --sdk-path ./existing-sdk --lang node --output .
oagen compat-extract --sdk-path ./existing-sdk --lang php --output ./sdk --spec openapi.yml
```

| Argument            | Required | Default                 | Description                                                                        |
| ------------------- | -------- | ----------------------- | ---------------------------------------------------------------------------------- |
| `--sdk-path <path>` | Yes      |                         | Path to the live SDK                                                               |
| `--lang <language>` | Yes      |                         | Target language                                                                    |
| `--output <dir>`    | Yes      |                         | Directory to write `.oagen-compat-snapshot.json` into                              |
| `--spec <path>`     | No       | `OPENAPI_SPEC_PATH` env | Path to OpenAPI spec — enriches symbols with `operationId`, `route`, and `specSha` |

Always writes `.oagen-compat-snapshot.json` in the specified directory. The snapshot file is meant to be committed to the repository and updated on each release.

When `--spec` is provided, the command parses the spec and enriches callable symbols with `operationId` and `route` (HTTP method + path) by matching each callable's `Class.method` name against the names `generate` writes the spec's operations as. It also computes a SHA-256 of the spec file and stores it as `source.specSha` in the snapshot.

The spec is parsed with the config's parser settings, exactly as `generate` parses it (`operationIdTransform`, `schemaNameTransform`, `transformSpec`, `fieldHints`, `operationHints`, `collapseErrorBodies`), and its operations are resolved as the engine resolves them (`operationHints`, `mountRules`, `operationNaming`), so the names matched are the ones the SDK `generate` writes has. A callable is matched with underscores stripped and case folded, so any language's casing reads the same (`Pets.list_pets`, `Pets.listPets`, `Pets.ListPets`), first to the mount target and resolved method name — and to each split wrapper's name on that target — then to the IR's operation name on the mount target, then to the IR's own `Service.operation` key (the one match made before). So under `mountRules: { Pets: 'Animals' }` an SDK's `Animals.get` and `Animals.list` get their `operationId` and `route`, as `Animals.get_pet` and `Animals.list_pets` (the names path naming writes) would; `Pets.list_all` gets them under `operationHints: { 'GET /pets': { name: 'list_all' } }`; a `Pets.list` method named by an `operationIdTransform` that strips `PetsController_` gets them; and a `ListPetsResponse` that a `pagination: { strategy: 'none' }` hint makes `generate` write gets its `schemaName`.

## `oagen compat-diff`

Diff two compat snapshot files and produce a classified change report. No extraction or spec required — pure file-in, report-out.

```bash
# Basic diff with terminal output
oagen compat-diff --baseline .oagen-compat-snapshot.json --candidate /tmp/candidate.json

# With machine-readable report and failure threshold
oagen compat-diff \
  --baseline .oagen-compat-snapshot.json \
  --candidate /tmp/candidate.json \
  --output compat-report.json \
  --fail-on breaking
```

| Argument             | Required | Default    | Description                                        |
| -------------------- | -------- | ---------- | -------------------------------------------------- |
| `--baseline <path>`  | Yes      |            | Path to the baseline compat snapshot JSON          |
| `--candidate <path>` | Yes      |            | Path to the candidate compat snapshot JSON         |
| `--output <path>`    | No       |            | Write machine-readable JSON report to this path    |
| `--fail-on <level>`  | No       | `breaking` | Fail threshold: `none`, `breaking`, or `soft-risk` |
| `--explain`          | No       | `false`    | Include provenance explanations in terminal output |

**Exit codes:** 0 = no changes exceed threshold, 1 = changes exceed threshold.

## `oagen compat-summary`

Format a compat report as a markdown PR comment. Reads the JSON report produced by `compat-diff --output` and outputs markdown to stdout or a file.

```bash
# Single language
oagen compat-summary --report compat-report.json | gh pr comment --body-file -

# Cross-language rollup (multiple reports)
oagen compat-summary --report php.json --report python.json --report go.json

# Write to a file
oagen compat-summary --report compat-report.json --output summary.md
```

| Argument             | Required | Default | Description                                                                |
| -------------------- | -------- | ------- | -------------------------------------------------------------------------- |
| `--report <path...>` | Yes      |         | Path(s) to compat report JSON(s) — pass multiple for cross-language rollup |
| `--output <path>`    | No       | stdout  | Write markdown to this file instead of stdout                              |

**Single report** output includes:

- Status header (pass/warning/fail)
- Summary table with breaking, soft-risk, and additive counts
- Breaking changes table (always visible)
- Soft-risk and additive changes in collapsible `<details>` sections

**Multiple reports** produce a cross-language rollup:

- Per-language summary table (breaking/soft-risk/additive per language)
- Conceptual changes table showing per-language severity for each change
- Same conceptual change across languages is shown as one row, not N separate rows

## `oagen verify`

Verify an already-generated SDK — run smoke tests and optional compat checks. Use after `oagen generate`.

```bash
oagen verify --lang node --output ./sdk --spec openapi.yml

# With compat check
oagen verify --lang node --output ./sdk --spec openapi.yml \
  --api-surface ./sdk/sdk-node-surface.json
```

| Argument                | Required | Default                         | Description                                                                                                                                                                                                                                                                    |
| ----------------------- | -------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `--lang <language>`     | Yes      |                                 | Target language                                                                                                                                                                                                                                                                |
| `--output <dir>`        | Yes      |                                 | Path to the generated SDK                                                                                                                                                                                                                                                      |
| `--spec <path>`         | No       | `OPENAPI_SPEC_PATH` env         | Path to an OpenAPI 3.x spec file                                                                                                                                                                                                                                               |
| `--api-surface <path>`  | No       |                                 | Baseline API surface JSON — enables compat verification                                                                                                                                                                                                                        |
| `--raw-results <path>`  | No       | auto-generated                  | Path to an existing smoke baseline file to diff against                                                                                                                                                                                                                        |
| `--smoke-config <path>` | No       |                                 | Smoke config JSON for skip lists and service mappings                                                                                                                                                                                                                          |
| `--smoke-runner <path>` | No       |                                 | Custom smoke runner script (overrides built-in `sdk-test.ts`)                                                                                                                                                                                                                  |
| `--scope <mode>`        | No       | `spec-only` when `--spec` given | Compat scope: `full` compares all baseline symbols, `spec-only` only compares symbols derivable from the spec — the models, and the classes and methods the config's `mountRules`, `operationHints` and `operationNaming` resolve the operations to, as `generate` writes them |
| `--diagnostics`         | No       | `false`                         | Output `verify-diagnostics.json` with structured violation breakdown                                                                                                                                                                                                           |
| `--max-retries <n>`     | No       | `3`                             | Max retry iterations for self-correcting overlay loop (set to 0 for single-pass)                                                                                                                                                                                               |

`--spec` and `--old-spec` are parsed with the config's parser settings, exactly as `generate` parses them (`operationIdTransform`, `schemaNameTransform`, `transformSpec`, `fieldHints`, `operationHints`, `collapseErrorBodies`), and `docUrl` is expanded the same way, so the compat scope and the staleness check read the models `generate` wrote: a `ListPetsResponse` that a `pagination: { strategy: 'none' }` hint makes `generate` write stays in scope and is reported removed or stale, not scoped out. Both also resolve the operations as `generate` resolves them, under the config's `mountRules`, `operationHints` and `operationNaming`, so the service classes and methods in scope are the ones `generate` writes: the mount target and the resolved method name, matched in any language's casing (`Animals.list_all` keeps a Node `listAll` and a Ruby `list_all`), beside the IR's operation name on that target. Under `mountRules: { Pets: 'Animals' }` and `operationHints: { 'GET /pets': { name: 'list_all' } }` a baseline holding `Animals` and `Pet` is scoped `2/2` and a method the SDK lost from `Animals` is reported as `symbol_removed`; read from the IR's `Pets`, as before, `Animals` was scoped out (`1/2`) and the loss passed. A `Pets` class is out of scope under that rule, since `generate` writes none. The staleness check finds the same classes and methods stale: a live `Animals.list_all` once `--spec` drops `GET /pets`, and `Animals` once it drops the `Pets` tag (see [Non-additive changes](architecture/non-additive-changes.md)). Both also read the compat overlay `generate --api-surface` wrote the SDK with, built as `generate` builds it from the baseline and the `.oagen-manifest.json` in `--output`: a baseline method the manifest maps to one of the spec's operations (`Animals.fetchAll` for `GET /pets`) stays in scope under its own name, since that is the name `generate` wrote, so an SDK that renamed it to `listPets` is reported (`symbol_removed`) and the retry restores `fetchAll`, and the method is found stale once `--spec` drops the route; a mapped method whose route the spec does not declare derives nothing and stays out of scope. The overlay retry regenerates the SDK in `--output` with the settings `generate` hands the engine (`operationHints`, `mountRules`, `operationNaming`, `modelHints` and the language's `emitterOptions`), so it rewrites the SDK `generate` wrote: under `mountRules: { Pets: 'Animals' }` it writes `Animals`, never a second `Pets` service beside it. The smoke step reads that IR too: the smoke scripts run as subprocesses, which the config's settings cannot reach, so `verify` writes the IR it parsed to a file (the shape `oagen parse` prints, kept while the scripts run) and hands it to the spec-only baseline script and to the runner as `--ir <path>` beside `--spec`. The baseline written when no raw baseline exists (`smoke-results-spec-baseline.json`) therefore lists the operations `generate` reads — `Pets.list` and `Pets.get` under an `operationIdTransform` that strips `PetsController_`, where a bare parse listed `Pets.petsControllerList` and `Pets.petsControllerGet`, and no `Pets.get` under a `transformSpec` that drops `/pets/{id}` — and a runner that reads the file (`loadSmokeSpec` from `@workos/oagen/smoke`) plans the same operations.

**Exit codes:**

| Code | Meaning                                                                 | Details                     |
| ---- | ----------------------------------------------------------------------- | --------------------------- |
| 0    | Clean — all checks passed                                               |                             |
| 1    | Findings — CRITICAL smoke mismatches, compat violations, or missing ops | `smoke-diff-findings.json`  |
| 2    | Compile error — SDK failed type check                                   | `smoke-compile-errors.json` |

## `oagen init`

Scaffold a new emitter project with all boilerplate files and a compilable stub emitter.

```bash
oagen init --lang ruby
oagen init --lang go --project ./my-emitter
```

| Argument            | Required | Default | Description                          |
| ------------------- | -------- | ------- | ------------------------------------ |
| `--lang <language>` | Yes      |         | Target language (e.g., `ruby`, `go`) |
| `--project <dir>`   | No       | `.`     | Directory to create the project in   |

Creates:

- `package.json` with `@workos/oagen` dependency and `sdk:generate`/`sdk:verify`/`sdk:extract` scripts
- `tsconfig.json`, `vitest.config.ts`, `tsup.config.ts` — build/test tooling
- `oagen.config.ts` — minimal config for local development, imports the plugin bundle
- `src/plugin.ts` — plugin bundle export registering the stub emitter
- `src/{language}/index.ts` — stub emitter implementing the full `Emitter` interface
- `src/index.ts` — barrel export including the plugin bundle
- Empty directories: `test/`, `smoke/`, `docs/sdk-architecture/`

After initialization, `npm run typecheck` passes immediately. Implement your emitter methods in `src/{language}/` to start generating SDK code.

## `oagen parse`

Parse an OpenAPI spec and output the IR as JSON to stdout. Useful for inspecting what the parser extracts.

```bash
oagen parse --spec openapi.yml
```

| Argument        | Required | Default                 | Description                                      |
| --------------- | -------- | ----------------------- | ------------------------------------------------ |
| `--spec <path>` | No       | `OPENAPI_SPEC_PATH` env | Path to an OpenAPI 3.x spec file (YAML or JSON). |

## `oagen resolve`

Resolve operation names from the spec using the algorithm and optional hints. Outputs a review table (markdown) or JSON for programmatic use.

```bash
# Markdown review table (default)
oagen resolve --spec openapi.yml

# JSON output for CI/scripting
oagen resolve --spec openapi.yml --format json
```

| Argument            | Required | Default                 | Description                                      |
| ------------------- | -------- | ----------------------- | ------------------------------------------------ |
| `--spec <path>`     | No       | `OPENAPI_SPEC_PATH` env | Path to an OpenAPI 3.x spec file (YAML or JSON). |
| `--format <format>` | No       | `table`                 | Output format: `table` (markdown) or `json`.     |

When `oagen.config.ts` defines `operationHints` and/or `mountRules`, they are applied automatically. The table format flags operations that have no hint and are resolved purely by algorithm.

## `--config <path>`

All commands accept a global `--config <path>` option to load a specific config file instead of the default cwd-based discovery.

```bash
# Explicit config
oagen generate --config ../openapi-spec/oagen.config.ts --spec openapi.yml --lang node --output ./sdk

# Default: searches for oagen.config.ts in the current directory
oagen generate --spec openapi.yml --lang node --output ./sdk
```

When `--config` is omitted, the CLI searches the current working directory for `oagen.config.ts`, `oagen.config.js`, or `oagen.config.mjs` in that order.

## Configuration (`oagen.config.ts`)

Place an `oagen.config.ts` (or `.js`/`.mjs`) in the project that drives generation. The CLI loads this file at startup before any command runs.

The config file belongs to the **consumer project** (the project that owns spec interpretation policy), not the emitter library. Emitter packages export plugin bundles that the consumer config composes.

### Consumer config (recommended)

```ts
import type { OagenConfig } from "@workos/oagen";
import { acmeEmittersPlugin } from "@acme/oagen-emitters";

const config: OagenConfig = {
  ...acmeEmittersPlugin,
  docUrl: "https://docs.example.com",
  operationIdTransform: (id) => id.replace(/Controller_/, ""),
  operationHints,
  mountRules,
};

export default config;
```

### Standalone emitter config

For standalone emitter projects that also serve as the consumer:

```ts
import type { OagenConfig } from "@workos/oagen";
import { nodeEmitter } from "./src/node/index.js";

const config: OagenConfig = {
  emitters: [nodeEmitter],
};

export default config;
```

### Composing multiple plugin bundles

```ts
import type { OagenConfig } from "@workos/oagen";
import { acmeEmittersPlugin } from "@acme/oagen-emitters";
import { experimentalPlugin } from "@workos/oagen-experimental";

const config: OagenConfig = {
  emitters: [
    ...(acmeEmittersPlugin.emitters ?? []),
    ...(experimentalPlugin.emitters ?? []),
  ],
  extractors: [
    ...(acmeEmittersPlugin.extractors ?? []),
    ...(experimentalPlugin.extractors ?? []),
  ],
  smokeRunners: {
    ...(acmeEmittersPlugin.smokeRunners ?? {}),
    ...(experimentalPlugin.smokeRunners ?? {}),
  },
  operationHints,
  mountRules,
};

export default config;
```

### Options

Every command that parses a spec (`parse`, `generate`, `diff`, `resolve`, `verify`, `compat-extract`) parses it with the same settings: `operationIdTransform`, `schemaNameTransform`, `transformSpec`, `fieldHints`, `operationHints` and `collapseErrorBodies`. `generate` also reads `docUrl`, `mountRules`, `operationNaming`, `modelHints` and `emitterOptions`; so do `diff` (`docUrl`), `resolve` (`docUrl`, `mountRules`, `operationNaming`), `compat-extract` (`mountRules`, `operationNaming`, with `operationHints`: the names it matches the SDK's callables by) and `verify`, whose compat scope and staleness check read the classes and methods those three resolve the operations to, whose overlay retry regenerates the SDK with all of them and whose smoke step hands the spec-only baseline and the runner the IR it parsed. Every command therefore reads the SDK `generate` writes, and the retry rewrites that SDK rather than another one.

| Key                    | Type                                              | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ---------------------- | ------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `emitters`             | `Emitter[]`                                       | Language emitters to register. Each emitter implements the `Emitter` interface and generates SDK files for one target language.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `extractors`           | `Extractor[]`                                     | API surface extractors to register. Each extractor parses a live SDK and produces an `ApiSurface` JSON used for compat verification.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `emitterProject`       | `string`                                          | Path to the emitter project directory. Used by skills to scaffold new emitters, tests, and smoke runners in the correct location.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `smokeRunners`         | `Record<string, string>`                          | Map from language key to custom smoke runner script path. Overrides the built-in `sdk-test.ts` for `oagen verify`. Can also be set per-invocation with `--smoke-runner`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `operationIdTransform` | `(id: string) => string`                          | Custom transform for operation IDs. Receives each `operationId` once, as the spec spells it with its trailing `[N]` overload markers stripped; return the desired operation name. No additional casing conversion is applied. When omitted, `operationId` values are converted to `camelCase`. A result with no ASCII letter or digit once such markers are stripped (`''`, `' '`, `'-'`, `'[1]'`), or that is not a string, names nothing: the operation is read as one without an `operationId` — path-named, its models named from its path, `Operation.operationId` unset — after one warning naming the id and the operation, so `(id) => id.split('.').at(1) ?? ''` names `pets.list` `list` and path-names `getPet` (`get`; `get_pet` under either `operationNaming`) instead of naming it `''`. An `operationId` that itself names nothing is never passed to the transform.                                                                                                                                                               |
| `schemaNameTransform`  | `(name: string, originalName?: string) => string` | Custom transform for schema (model/enum) names. Applied after the built-in `cleanSchemaName` normalization. Receives the cleaned PascalCase name (`name`) and, for component schemas, the original name exactly as spelled in the document (`originalName`); return the desired name. Return `originalName` to opt a schema out of normalization, but only when its spelling is already a valid identifier: a bare `originalName ?? name` would also keep keys like `user-profile` or `Foo.Bar` that `cleanSchemaName` would otherwise have fixed. For example `(name, originalName) => (originalName && /^[A-Za-z_$][\w$]*$/.test(originalName) ? originalName : name)` keeps `HTTPConfig`, `URL`, and `Settings` instead of `HttpConfig`, `Url`, and `Setting`. `originalName` is `undefined` for any name oagen synthesises (inline enums, request-body variant models, title-derived names), so fall back to `name` for those. Collisions are detected automatically: if a transform would produce a duplicate name, the cleaned name is kept. |
| `transformSpec`        | `(spec: OpenApiDocument) => OpenApiDocument`      | Pre-IR overlay applied to the bundled OpenAPI document before any IR extraction. Use to patch around upstream spec quirks that would otherwise emit a breaking SDK change. See [`transformSpec` — Pre-IR Spec Overlay](advanced/transform-spec.md).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `docUrl`               | `string`                                          | Base URL for documentation links. When set, relative markdown paths in descriptions (e.g. `[User](/reference/users/user)`) are expanded to full URLs (e.g. `[User](https://docs.example.com/reference/users/user)`).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `operationHints`       | `Record<string, OperationHint>`                   | Per-operation overrides keyed by `"METHOD /path"`. Override derived method names, remount to a different service, split union-body operations into typed wrappers, or state an operation's pagination explicitly (`pagination`, the same object as the spec's `x-pagination` extension; it wins over the extension and over detection). See [Operation Resolution](architecture/ir-types.md#operation-resolution).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `mountRules`           | `Record<string, string>`                          | Service-level remounting. Maps IR service name to target service/namespace (PascalCase). Keys may be exact names or trailing-`*` prefix patterns (e.g. `"UserManagement*"`); an exact key wins over any wildcard, and among wildcards the longest prefix wins. All operations in the source service are mounted on the target unless overridden per-operation in `operationHints`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `operationNaming`      | `'path' \| 'operationId'`                         | Where the operation resolver takes an unhinted method name from. `path` (default) derives it from the HTTP method and path; `operationId` uses the operation's own name when the document declares an `operationId` (`Operation.name`, so `operationIdTransform` applies) and the path only for an operation without one. That name is snake_cased word by word: a lower-case letter before a capital, a digit or a run of capitals before a capitalized word, and any character that is not a letter or digit mark a boundary, so `getSSOAuthorizationUrl` becomes `get_sso_authorization_url`, `createM2MApp` `create_m2m_app` and an id a transform keeps as written, `pets:adopt`, `pets_adopt`. A `name` in `operationHints` overrides either. Flipping it on an existing SDK renames every method whose operationId and path disagree — run `oagen resolve` and diff first.                                                                                                                                                                  |
| `modelHints`           | `Record<string, string>`                          | Pin specific models to a specific IR service for placement. Maps IR model name (post-`cleanSchemaName`/`schemaNameTransform`) → IR service name (PascalCase). Overrides the default "first service to reference the model wins" assignment. Both names must exist in the parsed spec; unknown names throw at generation time.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `collapseErrorBodies`  | `boolean`                                         | Fold the models materialized for inline 4xx/5xx bodies onto shared, shape-named models (`ErrorBody`, `ErrorBodyWithCode`, the enum `ErrorBodyCode`) instead of one model per operation and status code (`<Op>Error<code>`). Default `true`; set `false` to keep the per-operation models. Read by every command that parses a spec (`parse`, `generate`, `diff`, `resolve`, `verify`, `compat-extract`). See "Shared error bodies" in the IR types reference.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
