Skip to Content
openapi-proxy

Serving a variant

The URLs, formats and response headers your consumers get, and how a private variant is read.

Every variant has a URL. Docs renderers, SDK generators and contract tests fetch it like any other OpenAPI document.

GET /v/<project>/<variant>              JSON, or YAML if the Accept header asks for it
GET /v/<project>/<variant>.json
GET /v/<project>/<variant>.yaml
GET /v/<project>/<variant>/3.0.json     in one OpenAPI version, see OpenAPI versions

The URL picks the representation: the format by its extension, and the OpenAPI version by a path segment. JSON output keeps the formatting of your source: a minified source is served minified, an indented one indented.

Public and private

A variant is public or private. You choose next to its URL in the editor, and a workspace chooses what new variants start as, under New variants on the Workspace page.

  • Public: anyone with the URL can read it. The dice next to the slug makes a URL that cannot be guessed.
  • Private: a reader sends an API key of the workspace.
curl https://proxy.example.com/v/acme/internal.json \
  -H "Authorization: Bearer $OPENAPI_PROXY_API_KEY"

Next to a private variant's URL, Create a key for this variant makes a key that reads this variant and does nothing else. That is the key to hand to a partner or to put into a docs build. A key can also read every private variant of the workspace, or have full access; see API keys.

Without a key the answer is a 401. With a key that is not for this variant it is a 403.

Response headers

HeaderValue
ETagChanges exactly when the served bytes do: a new source document, a new selection, another format or version.
Cache-Controlpublic, max-age=60, stale-while-revalidate=300. For a private variant, private, no-cache.
X-Proxy-Source-Statusfresh when the document reflects the latest check. stale when a check is still running and the previous copy was served. stale-error when your API is failing and the last good copy was served.
Access-Control-Allow-Origin*, because documentation tools fetch from other origins.

Conditional requests (If-None-Match) get a 304 when nothing changed, and HEAD is answered without a body.

When you need the current document

A build that runs right after a deploy may want the document as it is this second. Tell the proxy to check first, with an API key, and then fetch as usual:

curl -X POST https://proxy.example.com/api/projects/$PROJECT_ID/check \
  -H "Authorization: Bearer $OPENAPI_PROXY_API_KEY"
curl https://proxy.example.com/v/acme/sdk.json

Otherwise the proxy looks by itself: every 5 minutes if your API can be checked cheaply, once an hour if not. See Keeping in sync.

Delivery does not fail

Once a project has been fetched, its variants are always answered. If your API is down or returns something invalid, consumers get the last good document and X-Proxy-Source-Status: stale-error. If an operation you selected disappears from the source, the variant is served without it, and you are told in the app and by email.

On this page