<!--
  The OpenAPI pin — Marula PSA documentation
  Source: /docs/psa/v0.7/reference/openapi
  License: CC BY 4.0 — https://creativecommons.org/licenses/by/4.0/
  Source file: https://github.com/marulahq/marula-core/tree/main/docs/site/reference/openapi.md
-->
---
description: "The API contract is pinned twice, and CI enforces that the two are a byte-identical pair:"
---

# The OpenAPI pin

The API contract is pinned twice, and CI enforces that the two are a
byte-identical pair:

- [`packages/sdk/openapi.json`](../../../packages/sdk/openapi.json) — the
  snapshot `@marula-core/sdk` is generated from
- [`fixtures/openapi/v1/openapi.json`](../../../fixtures/openapi/v1/openapi.json)

## The compact rule (DX12)

Both pins are **compact single-line minified JSON**. The API serves
pretty-printed JSON, so after `curl /openapi.json > packages/sdk/openapi.json`
you must run `pnpm --filter @marula-core/sdk generate` (it minifies the
snapshot in place) before committing. Never commit the ~43k-line pretty
form; `scripts/check-openapi-pins.sh` fails it in CI.

## What the pin guarantees

- The generated typed SDK client and this docs site's [API
  reference](https://getmarula.com/docs/psa/v0.7/reference/api) are generated from the same committed snapshot, so they
  cannot drift from what the server serves.
- Path-versioned (`/api/v1`…): a supported API version never breaks inside
  its support window; new versions are added alongside, never swapped in
  place (policy §2).

## Machine scopes

Interactive sessions authorize by role. API keys authorize by scope, and the
document names them.

- `x-scope-catalog` (top level) lists every scope an organization can write onto
  a key and the permissions it grants. The key-creation endpoint validates
  against the same list.
- `x-api-key-scopes` on an operation names the scopes that satisfy it. Any one is
  enough. An operation without the extension is not reachable by any scope in the
  catalog.
- `components.securitySchemes` defines `bearer` (JWT) and `api_key` (an
  `x-api-key` header). OpenAPI 3.1 has no scope field on an API key scheme, so
  the vocabulary lives in the two extensions instead of being described as an
  OAuth2 flow.

Holding a scope is not enough on its own. Handlers still apply their own
permission and record-level checks.

## How this reference is generated

[`docs/site/scripts/generate-api-reference.mjs`](../scripts/generate-api-reference.mjs)
parses the compact pin (it never reads or pastes the pretty form) and emits
[`reference/api.md`](https://getmarula.com/docs/psa/v0.7/reference/api). Regenerate after any OpenAPI regen:

```sh
node docs/site/scripts/generate-api-reference.mjs
```
