Skip to main content

Document store

The document store is where the REST API keeps files that never change once written. It has three backends, and you choose one with environment variables on the rest service:

APIOME_DOCUMENT_STOREObjects are kept inUse it for
db (default)The Apiome databaseAny installation without a bucket. Nothing to set up.
s3A bucket on an S3-compatible serviceProduction. Works with AWS S3, MinIO, Garage, Cloudflare R2 and Google Cloud Storage (interoperability mode).
filesystemA directory on the REST hostDevelopment and single-node installations.

Apiome writes four kinds of object to the store:

Diffs, downloads, exports and /v1/schema read these stored objects instead of building the document again on every request. When you allow it, a workspace can keep its own originals and rendered documents in a bucket it owns instead (see Tenant buckets).

How objects are stored​

Every object is named by the SHA-256 of its bytes, inside the owning tenant's folder:

<prefix>/tenants/<tenant>/objects/sha256/<first two hex digits>/<sha-256>
  • The same bytes are stored once. Writing a file the tenant already holds writes nothing.
  • Tenants never share a folder. The same file in two tenants is two objects.
  • Objects are never changed, only added and removed.

Choose the storage folder​

APIOME_DOCUMENT_STORE_PREFIX is the folder all Apiome objects are written under. It applies to every backend, and defaults to apiome:

APIOME_DOCUMENT_STORE_PREFIX=apiome # s3://<bucket>/apiome/tenants/…
APIOME_DOCUMENT_STORE_PREFIX=teams/platform/apiome # a nested folder
APIOME_DOCUMENT_STORE_PREFIX= # the root of the bucket or directory

Use it to share one bucket with other applications, or to keep two Apiome installations apart in the same bucket. Leading and trailing slashes are ignored; . and .. segments are refused.

warning

Changing the prefix does not move objects. Objects written under the old folder are no longer found, so copy them to the new folder before you restart the REST API.

Use an S3-compatible bucket​

  1. Create the bucket. Apiome does not create it.
  2. Give the key (or IAM role) permission to read, write and delete objects under the prefix: s3:GetObject, s3:PutObject, s3:DeleteObject, and s3:ListBucket on the bucket.
  3. Set the variables in apiome-rest/.env (or on the rest service in Compose) and restart.

Garage​

APIOME_DOCUMENT_STORE=s3
APIOME_DOCUMENT_STORE_BUCKET=apiome
APIOME_DOCUMENT_STORE_PREFIX=apiome
APIOME_DOCUMENT_STORE_ENDPOINT_URL=http://garage.internal:3900
APIOME_DOCUMENT_STORE_REGION=garage
APIOME_DOCUMENT_STORE_ADDRESSING_STYLE=path
APIOME_DOCUMENT_STORE_ACCESS_KEY_ID=GK…
APIOME_DOCUMENT_STORE_SECRET_ACCESS_KEY=…
APIOME_DOCUMENT_STORE_ALLOW_PRIVATE=true # only when Garage is on a private network

REGION must match s3_region in Garage's configuration (garage unless you changed it). Leave APIOME_DOCUMENT_STORE_SSE empty: Garage does not offer SSE-S3 or SSE-KMS.

MinIO and Cloudflare R2​

The same variables as Garage, with the service's endpoint. For MinIO use ADDRESSING_STYLE=path and REGION=us-east-1 unless you configured another. For R2 use ENDPOINT_URL=https://<account id>.r2.cloudflarestorage.com and REGION=auto.

The bundled MinIO (local development)​

docker compose up always starts a MinIO service (API on localhost:9000, web console on localhost:9001) and a one-shot minio-init service that creates the bucket, then exits. REST keeps using the database until you switch, so nothing changes by default. To use the bundled MinIO, add one line to the .env next to docker-compose.yml and restart:

APIOME_DOCUMENT_STORE=s3

Compose already points the endpoint, bucket (apiome), path-style addressing and credentials at the bundled MinIO, and allows its private address for this endpoint only. Sign in to the console at http://localhost:9001 with apiome / apiome_local_dev to see the objects. To change the defaults set MINIO_ROOT_USER, MINIO_ROOT_PASSWORD, APIOME_DOCUMENT_STORE_BUCKET, MINIO_API_PUBLISH_PORT or MINIO_CONSOLE_PUBLISH_PORT in the same .env; the data lives in the apiome_minio_data volume.

warning

The bundled MinIO uses well-known development credentials, so the production overlay (docker-compose.prod.yml) does not start it. In production point the APIOME_DOCUMENT_STORE_* variables at AWS S3, R2 or your own MinIO; docker-compose.prod.env.example has a commented block for each.

Run the setup script​

./setup.sh asks Document store (db/s3/filesystem) and, for s3, the bucket, endpoint, region and keys (the defaults match the bundled MinIO), then writes them to apiome-rest/.env. Answer db to keep the default.

AWS S3​

APIOME_DOCUMENT_STORE=s3
APIOME_DOCUMENT_STORE_BUCKET=acme-apiome-documents
APIOME_DOCUMENT_STORE_REGION=eu-west-1
APIOME_DOCUMENT_STORE_SSE=kms
APIOME_DOCUMENT_STORE_KMS_KEY_ID=alias/apiome-documents

Leave the two key variables unset to use the instance's IAM role or the standard AWS_* environment variables. Set both to use a static key pair.

Use a directory​

APIOME_DOCUMENT_STORE=filesystem
APIOME_DOCUMENT_STORE_PATH=/var/lib/apiome/documents

The directory is created on the first write. In Docker, mount a volume at that path, or the objects are lost when the container is replaced. Every REST instance must see the same directory, so use s3 when you run more than one.

Settings​

All of these are set on the rest service.

VariableDefaultMeaning
APIOME_DOCUMENT_STOREdbThe backend: db, s3 or filesystem.
APIOME_DOCUMENT_STORE_PREFIXapiomeThe folder all objects are written under. Empty for the root.
APIOME_DOCUMENT_STORE_PATH—filesystem: the storage directory. Required.
APIOME_DOCUMENT_STORE_BUCKET—s3: the bucket. Required.
APIOME_DOCUMENT_STORE_REGIONus-east-1s3: the signing region.
APIOME_DOCUMENT_STORE_ENDPOINT_URL—s3: the service URL for anything other than AWS.
APIOME_DOCUMENT_STORE_ADDRESSING_STYLEautos3: path (https://host/bucket/key), virtual (https://bucket.host/key) or auto.
APIOME_DOCUMENT_STORE_SSE—s3: encryption requested on each write. s3 (SSE-S3) or kms (SSE-KMS). Empty uses the bucket's default.
APIOME_DOCUMENT_STORE_KMS_KEY_ID—s3 with SSE=kms: the key. Empty uses the bucket's default KMS key.
APIOME_DOCUMENT_STORE_ACCESS_KEY_ID—s3: a static access key. Set it together with the secret key, or set neither.
APIOME_DOCUMENT_STORE_SECRET_ACCESS_KEY—s3: the secret key. Keep it in your secret manager.
APIOME_DOCUMENT_STORE_PRESIGN_TTL_SECONDS300s3: how long a presigned download link stays valid (1 second to 7 days).
APIOME_DOCUMENT_STORE_DB_MAX_BYTES33554432db: the largest single object accepted (32 MiB).
APIOME_DOCUMENT_STORE_GZIP_MIN_BYTES65536Originals of at least this many bytes are stored gzip-coded. 0 turns the coding off.
APIOME_DOCUMENT_STORE_ALLOW_PRIVATEfalses3: allow an endpoint on a private or loopback address.
APIOME_DOCUMENT_STORE_ALLOW_TENANT_BUCKETSfalseLet a tenant keep its documents in its own bucket. See Tenant buckets.
APIOME_DOCUMENT_STORE_TENANT_ALLOW_PRIVATEfalseAllow a tenant's bucket endpoint on a private or loopback address. Leave it off on a shared installation.
APIOME_DOCUMENT_STORE_FALLBACK—What startup does when the store cannot be used. Empty refuses to start; db starts on the database store instead. See Check the store.
APIOME_DOCUMENT_LIFECYCLE_INTERVAL_SECONDS3600How often the REST API runs retention and the integrity check. 0 turns the schedule off.
APIOME_DOCUMENT_GC_GRACE_HOURS24How long an unused object, a replaced rendered document or a deleted tenant's files wait before they are deleted.
APIOME_DOCUMENT_INTEGRITY_SAMPLE100How many objects each run re-hashes, least recently checked first. 0 skips the check.

These variables are the only place the store is set. The admin console's Document store page shows them but cannot change them, and never shows a key.

Endpoints on a private network​

The endpoint URL passes the same check as any URL the REST API calls: it must be http or https, carry no user name or password, and resolve to public addresses. A store on your own network (http://garage.internal:3900, http://127.0.0.1:9000) is refused until you set APIOME_DOCUMENT_STORE_ALLOW_PRIVATE=true. That setting applies to the document store endpoint only. It does not let users import from private addresses, which APIOME_SSRF_ALLOW_PRIVATE would.

Check the store​

At startup​

When the REST API starts, it builds the store from the settings above and checks that it answers:

  • s3: the bucket exists and the key may use it (HeadBucket).
  • filesystem: the directory exists, or can be created, and is writable.
  • db: nothing more to check; the database readiness check covers it.

If the check fails, the REST API does not start. The log names the problem and the setting to fix, with every key replaced by [redacted]:

The document store (APIOME_DOCUMENT_STORE=s3) is not usable: The document store could not reach
bucket 'acme-apiome-documents' (NoSuchBucket: …). Check the APIOME_DOCUMENT_STORE_* settings, the
bucket and the key's permissions. Fix the APIOME_DOCUMENT_STORE_* settings, or set
APIOME_DOCUMENT_STORE_FALLBACK=db to start on the database store instead.

To keep serving while you fix the store, set APIOME_DOCUMENT_STORE_FALLBACK=db and restart. The REST API then starts on the database store, logs why, and reports the fallback on /health and on the Document store page. New documents go to the database until you fix the settings and restart without the fallback; move them afterwards.

warning

The fallback only covers the configured store failing. An unknown APIOME_DOCUMENT_STORE value, or a bad APIOME_DOCUMENT_STORE_PREFIX with db, still stops startup.

In the admin console​

Route/admin/dashboard/document-store
The Document store page: an S3-compatible bucket marked Reachable, a passed connection test with its three steps, the bucket settings and the usage totalsThe Document store page: an S3-compatible bucket marked Reachable, a passed connection test with its three steps, the bucket settings and the usage totals
Route/admin/dashboard/document-store
  1. Sign in to the admin console and click “Document store” in the sidebar.
  2. Read the status card. It names the backend and says Reachable or Unreachable, with the error when the last check failed. The check is repeated at most every 30 seconds.
  3. Click “Test connection”. The REST API writes a small probe object, reads it back, compares the bytes and deletes it. The Connection test card lists Write a probe object, Read it back and Delete it, each with its time or its error. When the write fails, the other two steps are skipped.

The page also shows:

CardWhat it shows
SettingsThe settings of the active backend: bucket, region, endpoint, addressing style, encryption, where the credentials come from (Static keys or Default credential chain or IAM role), download link lifetime and prefix for s3; the directory for filesystem; the largest object for db.
UsageThe number and total size of objects in the document index (originals, rendered documents and frozen schemas), split by backend when more than one holds objects, and Last integrity check: the latest time an object was read back and verified, by the integrity check or the migration.

| Tenant buckets | Whether tenants may use their own bucket, and each tenant that has set one up: its bucket and its state — In use, Moving documents, Move incomplete, Moved back or Unavailable, with when the bucket stopped answering and why. See Tenant buckets. |

If the REST API started on the fallback, an amber notice at the top names the configured backend and why it could not be used.

From the REST API​

EndpointWhoDoes
GET /healthAnyoneAdds a document_store block: status (ok, degraded on the fallback or when a tenant's bucket is down, unavailable when the store did not answer), backend, fallback and tenant_buckets_unavailable (a count). No error text, settings or tenant names.
GET /v1/ops/document-storePlatform administratorsThe same data as the Document store page, including tenantBuckets.
POST /v1/ops/document-store/testPlatform administratorsRuns the connection test. Answers 200 whether or not it passed; read ok and each step's error.
curl -s https://api.example.com/health | jq .document_store
# { "status": "ok", "backend": "s3", "fallback": false, "tenant_buckets_unavailable": 0 }

curl -s -X POST -H "Authorization: Bearer $TOKEN" \
https://api.example.com/v1/ops/document-store/test | jq '.ok, [.steps[] | .name + ": " + (.ok|tostring)]'

A store that stops answering does not make /health return 503: only the database decides readiness. Imports and exports that need the store report their own errors, as described below. The endpoints are in the ops reference.

Tenant buckets​

By default every tenant's documents go to the store configured above. A tenant can instead keep its originals and rendered documents in an S3-compatible bucket it owns — for its own region, encryption keys, retention rules or audit. Export downloads stay in the platform store.

Turn it on​

Set this on the rest service and restart it:

APIOME_DOCUMENT_STORE_ALLOW_TENANT_BUCKETS=true

It is off by default. A tenant's bucket endpoint must be a public address; on an installation where tenants run their own store on your private network (MinIO beside a self-hosted install), also set APIOME_DOCUMENT_STORE_TENANT_ALLOW_PRIVATE=true. Storage credentials are sealed with APIOME_MCP_CREDENTIAL_ENCRYPTION_KEYS, which must be set.

Turning the setting off later stops tenants from changing where their documents go. Tenants already on their own bucket keep reading and writing there.

What a tenant administrator does​

A tenant Owner or Admin (the permission document_store:manage) opens Document storage in the tenant settings, chooses Your own bucket, picks a storage credential, names the bucket, tests it and saves. The steps are on Tenants & the manage drawer.

  • New documents go to the bucket at once. Existing ones are moved in the background: each is copied, read back, checked against its SHA-256 and only then read from the bucket. Nothing fails while the move runs, and it resumes where it stopped after a restart.
  • Old copies stay in the place they came from until the administrator clicks Delete old copies… and confirms.
  • Moving back to platform storage works the same way in the other direction.
  • Objects are written under <folder>/tenants/<tenant id>/objects/sha256/… in the tenant's bucket, and Apiome never reads or writes outside that folder.

The key the tenant gives needs to read, write and delete objects under that folder (s3:GetObject, s3:PutObject, s3:DeleteObject) and to list it (s3:ListBucket).

When a tenant's bucket stops answering​

If the bucket is unreachable, or its credential is revoked or deleted:

  • Requests that need a stored original answer 503 with the code tenant-document-store-unavailable and the reason. The reason names the bucket and the provider's error code, never a key.
  • Specs, diffs and compatibility checks keep working: the documents are rendered on each request instead of read from the bucket.
  • New imports and uploads fail with the same 503. Nothing is written to the platform store instead.
  • The tenant's owners and administrators get one Document bucket outages notification per outage.
  • The Tenant buckets card marks the tenant Unavailable, and GET /health counts it in tenant_buckets_unavailable and reports degraded.

The flag clears the next time the bucket answers.

The Tenant buckets card: Northwind's bucket In use, and Globex's bucket Unavailable with the time it stopped answering and the provider's errorThe Tenant buckets card: Northwind's bucket In use, and Globex's bucket Unavailable with the time it stopped answering and the provider's error
Route/admin/dashboard/document-store

Deleting a tenant​

Deleted tenants are purged from their own bucket too: after the grace period the retention run deletes everything under <folder>/tenants/<tenant id>/. It never deletes the bucket or anything else in it.

Originals of imports​

Every import writes the document it read to the store, after the workspace's secret scrub, and records it as the revision's original in version_documents. An archive is written as one object per file (original_part) plus a manifest (original). A source that is withheld writes nothing. What an import records describes this for users.

Where the document text is also kept depends on the backend:

APIOME_DOCUMENT_STOREThe store holdsThe database holds
db (default)The originalThe text as before (version_import_snapshots.source_text, format_metadata.sourceContent) and the pointer
s3 or filesystemThe originalThe pointer only
note

Every feature that needs the document reads it from the store, whatever the backend: How originals are read. You can run on s3 or filesystem without losing export, conversion or the source workspace's as-imported view.

  • Large documents are gzip-coded. A document of at least APIOME_DOCUMENT_STORE_GZIP_MIN_BYTES bytes (64 KiB) is stored compressed, and its document_objects.encoding is gzip. Smaller documents, and documents gzip does not shrink, are stored as they are (identity).
  • The digest is of the stored bytes. For an identity object, document_objects.sha256 is the SHA-256 of the document text. For a gzip object it is the SHA-256 of the compressed bytes.
  • If the store cannot be written, the import still succeeds and the text stays in the database, whatever the backend. The REST log has a line original not stored.
  • With db, an original larger than APIOME_DOCUMENT_STORE_DB_MAX_BYTES is not stored. The text stays in the database as before.
  • Existing versions are not changed by the upgrade. Only imports that run after it write an original. To move older originals into the store, run the migration.

How originals are read​

Export, conversion, lint evidence, compatibility checks, the catalog's Source & Code tab, the schema registry and the source workspace's as-imported view all read an import's document the same way:

  1. The document store. The revision's original in version_documents, decoded if it is gzip-coded. An archive comes back as its files, with the root file the import chose.
  2. The database, for older revisions. A revision imported before originals were stored is read from where its text was kept then (format_metadata.sourceContent or version_import_snapshots.source_text).

If neither holds the document, the feature reports that the source was not kept, as before (for an export, 422 source-not-captured).

  • If an object cannot be read (a bucket that is down, an object deleted by hand), the reader falls back to the database text when there is one. The REST log has a line original not read.
  • An OpenAPI, Swagger or Arazzo project is not rebuilt from its original. Its classes, paths and workflows are what you edit, so exports are generated from them. The original is used only to show what was imported.
  • Lists do not carry the document. The catalog list, a catalog item and version lookups return format_metadata without sourceContent. GET …/catalog/{tenant}/{item}/source returns the document.

The parsed-model cache​

Reading a version for export or a check means parsing its document. Each REST worker keeps the most recently parsed models in memory, keyed by the SHA-256 of the document, so a second read of the same document does not parse it again. An import that changes the document has a new digest, so nothing needs to be cleared.

SettingDefaultMeaning
APIOME_CANONICAL_MODEL_CACHE_ENTRIES32The most models one worker keeps. 0 turns the cache off.
APIOME_CANONICAL_MODEL_CACHE_MAX_BYTES16777216The most document bytes the kept models may add up to (16 MiB). A document larger than a quarter of this is parsed every time. 0 turns the cache off.

Memory use grows with both settings and with the number of REST workers. Lower them on a small host.

Scoring the export targets​

The Export dialog and the Export Studio show a fidelity badge on every format. Working those out reads the parsed model once per format, which takes several seconds on a spec with thousands of schemas. REST does that work on a small pool of background threads, so other requests keep being answered while it runs, and keeps each finished list for ten minutes per version.

SettingDefaultMeaning
APIOME_EXPORT_FIDELITY_WORKERS2How many lists one REST worker scores at the same time. Requests beyond that wait their turn.

GET /v1/export/{tenant}/targets?fidelity=deferred returns the formats at once with fidelity_status: "pending" and a fidelity_token; GET /v1/export/{tenant}/targets/fidelity/{token} returns the scored list when it is ready. Without fidelity=deferred the request waits for the scores, as it always has.

Large export downloads​

A finished export keeps its download for APIOME_EXPORT_ARTIFACT_RETENTION_HOURS (24 by default).

Download sizeWhere it is kept
Up to APIOME_EXPORT_ARTIFACT_DB_MAX_BYTES (32 MiB)The database
Above that, up to APIOME_EXPORT_ARTIFACT_MAX_BYTES (32 MiB)The document store (s3 or filesystem)
Above APIOME_EXPORT_ARTIFACT_MAX_BYTESNowhere: the export fails with EXPORT_ARTIFACT_TOO_LARGE

The two limits are equal by default, so every download goes to the database. To allow larger exports, configure s3 or filesystem and raise APIOME_EXPORT_ARTIFACT_MAX_BYTES. To move large downloads out of the database, lower APIOME_EXPORT_ARTIFACT_DB_MAX_BYTES.

With APIOME_DOCUMENT_STORE=db, an export above the database limit fails with EXPORT_ARTIFACT_STORE_UNAVAILABLE.

Downloads written to the database before you configured s3 or filesystem can be moved with the migration.

When a download expires it can no longer be fetched, but its object stays in the bucket or directory. Export downloads are not part of the document index, so retention does not remove them; only deleting the tenant does. Remove expired ones yourself if space matters.

Document records and the content stamp​

The database keeps a record of each stored document, apart from the bytes. Migration V403 adds two tables and one column:

NameWhat it records
document_objectsOne row per stored object: tenant, SHA-256, size, media type, content encoding, the backend that holds it (db, s3 or filesystem) and its key there. One row per tenant and SHA-256.
version_documentsWhich object a revision uses, and for what. See the roles below.
versions.content_stampA counter for each revision that goes up when the revision's content changes.

A row in version_documents has one of these roles:

RoleThe object is
originalThe file the revision was imported from. For a set of files (an Arazzo document with its sources, a multi-file protobuf), it is the manifest that lists the files.
original_partOne file of a set, with its path inside the set.
rendered_openapiThe published OpenAPI document generated from the revision (GET /v1/schema).
rendered_openapi_membersThe OpenAPI document the app shows a workspace member — see The document the app shows.
rendered_canonicalA canonical model document generated from the revision.
frozen_schemaA frozen schema snapshot.

A rendered document also records the content stamp it was generated at, and the generator and its version.

How the content stamp changes​

  • It goes up by one for each transaction that changes the revision's classes, properties, paths, operations, parameters, responses, servers, security schemes, component pins, canonical API model or the revision's own fields. A save that writes many rows still counts as one change.
  • Editing a shared property in the project library raises the stamp of every revision that uses it.
  • Reading never changes it. Neither do saves that change nothing, moving items on the canvas, or Apiome updating a revision's quality score.

A rendered document is current while its recorded stamp equals the revision's stamp. The stamp starts at 0 for every revision, including revisions that existed before the upgrade. The migration adds the column without rewriting the versions table, so it is safe to run on a large, live database.

Rendered documents​

Apiome generates a version's OpenAPI document from its classes, properties and paths. For a large version this takes many database reads, so Apiome generates the document once and stores the bytes. The next request for the same version reads the stored object.

WhenWhat Apiome does
The first request for a versionGenerates the document, writes it to the store and records it in version_documents with the role rendered_openapi.
A later request, version unchangedReads the stored bytes. It reads no class, property or path.
The version is editedThe content stamp goes up, so the next request generates a new document.
The project's slug, description or metadata changesThe next request generates a new document.
The version is publishedGenerates and stores the document straight away, so the first reader gets stored bytes.
Apiome's generator changes in an upgradeThe next request generates a new document.

GET /v1/schema/{tenant}/{project}/{version} serves these bytes. Its response has an ETag header, which is the SHA-256 of the document in double quotes. Send that value in If-None-Match and the answer is 304 Not Modified, with no body, while the document is unchanged:

curl -sI https://api.example.com/v1/schema/acme/payments-api/2.1.0 | grep -i etag
# etag: "7f2c…a041"

curl -s -o /dev/null -w '%{http_code}\n' \
-H 'If-None-Match: "7f2c…a041"' \
https://api.example.com/v1/schema/acme/payments-api/2.1.0
# 304

Things to know:

  • The document is the same as before. The stored bytes are exactly what the generator produces.
  • Older documents are removed later. An edit leaves the previous document in place until retention drops it, APIOME_DOCUMENT_GC_GRACE_HOURS after the newer one was written.
  • A store failure does not fail the request. If the bucket cannot be reached, Apiome generates the document for each request and serves it. The log has rendered document not stored.
  • Rendered documents are not compressed, so the stored object's SHA-256 is the ETag.
  • With APIOME_DOCUMENT_STORE=db, a document larger than APIOME_DOCUMENT_STORE_DB_MAX_BYTES is generated for each request. Use s3 or filesystem for very large versions.

A version with a canonical model (a non-OpenAPI import) also gets that model stored as JSON, with the role rendered_canonical, when it is published.

The document the app shows​

The app's View spec, Compare, catalog Versions diff and the Spec and Plain diff of a review or merge request read a second stored document of the same version, with the role rendered_openapi_members. It differs from the published one in two ways: it declares OpenAPI 3.2, and it keeps the operations marked private. A draft has one too.

Published documentThe document the app shows
RouteGET /v1/schema/{tenant}/{project}/{version}GET /v1/versions/{tenant}/{project id}/{version id}/document
Who can read itAnyone, for a public version; an API key for a private oneA signed-in member with versions:view
DraftsRefusedServed
OpenAPI version3.13.2
Private operationsLeft outKept, with x-private: true
Stored whenAt publish, and on the first request after a changeOn the first request after a change

It is stored, re-rendered and removed by the same rules as the table above. Its response has the same ETag, plus X-Apiome-Content-Sha256 (the same digest, without quotes) and X-Apiome-Document-Cache: hit when the stored bytes were served, miss when this request rendered them. The app sends If-None-Match, so an unchanged version is not downloaded twice.

Upgrading to this release renders every published document once more, because the generator changed: see the release note. The stored copies of the older generator are removed by retention.

Comparisons read the same stored documents: the classified diff, the compatibility check, a merge request's Changes tab, the published version's changelog and transitive checks. Their responses say hit or miss per side in the X-Apiome-Document-Cache header. See Which documents are compared.

Which features read the stored document​

Every REST feature that needs a stored version's OpenAPI document reads the published document from the store. The web app, the CLI and the MCP server reach these features through the REST server, so they all gain from it.

AreaFeatures
QualityLint report, lint fixes, quality capture, style-guide lint
Mocks and docsMock start, mock scenarios and Try it, Swagger UI
VersionsMerge preview, merge, rollback check, publish prechecks, the breaking-change guardrail, change reports and changelogs
ReviewReviews, pull requests back to a repository, repository federation
Source workspaceProvenance, preservation, source review, source apply
GovernanceConsumer contracts, blast radius, component governance
Moving specsSpec sync, import delta, export and conversion

A write that replaces a version's content in one step stores the new document straight away: a merge and an applied source change. The next reader gets stored bytes.

Four renders do not use the store, because what they render is not a stored version:

RenderWhy it is not stored
The component bulk-upgrade previewIt shows the version with pins it does not have yet.
The component materialization previewIt renders the version without its pins.
The document a source change would produceThe change is not written yet.
The current document inside a source applyIt is read inside the apply's own database transaction, so the check and the write see the same rows.

Two more readers keep generating. A freeze generates the document it stores, because it also counts the classes, properties and paths. The URL-import refresh check generates a copy without the project's name, which it uses only to tell whether a version was edited since its import.

Frozen schemas​

Freezing a version keeps its OpenAPI document byte-for-byte. The bytes are a store object, linked to the version with the role frozen_schema. The version_spec_snapshots row keeps the SHA-256, size, counts, who froze the version and the download count.

APIOME_DOCUMENT_STOREWhere the frozen bytes are
s3, filesystemIn the store only. The row's content column is empty.
dbIn the store and in the row's content column.
  • If the store write fails during a freeze, the bytes are kept in the row and the freeze succeeds.
  • A version frozen before this release keeps its bytes in the row and is served from there, until the migration moves them.
  • Unfreezing removes the row and the link. The object is deleted by retention once nothing else uses it.
  • If a frozen version's bytes cannot be read from the store, /v1/schema answers 503. It never falls back to a newly generated document, because that could differ from the frozen one.

Migration V404 makes the content column optional. It changes no rows.

Retention and integrity​

Stored objects are named by their content, so revisions share them: two imports of the same file use one object. Apiome therefore counts, for each object, the revisions that still use it, and deletes the object only when that count reaches zero.

What counts as a use​

document_objects.ref_count is the number of links (version_documents rows) from revisions that are not deleted, in tenants that are not deleted. The database keeps it current (migration V406), whichever screen or job made the change:

ChangeThe count
An import, render or freeze links an object to a revisionGoes up
A version is deleted, or pruned by version retentionGoes down
A tenant is deletedGoes to zero for all its objects
A project is deleted (but not permanently)Unchanged: the project can be restored
A deleted version or tenant is restored in the database (deleted_at cleared) before the grace period endsGoes back up

When the count reaches zero, document_objects.unreferenced_at records when.

When objects are deleted​

  • Deleting or pruning a version deletes, straight away, every object that version used and no other live revision uses. Deleting one of two revisions that share an original keeps the object; deleting both removes it.
  • The retention run, every APIOME_DOCUMENT_LIFECYCLE_INTERVAL_SECONDS (one hour), deletes:
    • objects unused for longer than APIOME_DOCUMENT_GC_GRACE_HOURS (24 hours), including objects a failed import wrote but never linked, and objects of permanently deleted projects;
    • rendered documents a newer render of the same revision replaced longer than the grace period ago;
    • everything a deleted tenant had in the store, once the tenant has been deleted for longer than the grace period: see Deleted tenants.

Each object is recounted under a lock just before it is deleted, so an import that starts using it again in the meantime keeps it. If the store refuses the delete, the index row is removed anyway and an object_purge_failed audit row names the key, so you can remove it by hand.

Deleted tenants​

Deleting a tenant in the admin console drops its objects' counts to zero. After the grace period the retention run deletes them, then deletes everything left under the tenant's folder (<prefix>/tenants/<tenant id>/) and under its slug (<prefix>/tenants/<slug>/, where export downloads are kept), in the active store and in the database store. The slug folder is left alone when a live tenant now uses the same slug. Each tenant is purged once; the purge is recorded in document_tenant_purges.

The integrity check​

Each retention run also re-hashes APIOME_DOCUMENT_INTEGRITY_SAMPLE objects (100), the least recently checked first, and compares the SHA-256 of the stored bytes with the one the object is named by:

ResultWhat Apiome does
The bytes matchRecords document_objects.verified_at (shown as Last integrity check)
A rendered document changed or is missingDrops it, so the next request renders it again
An original or frozen schema changed or is missingKeeps it and sets document_objects.integrity_failed_at. A later check that matches clears the flag
The store cannot be readSkips the object and tries again next run; an outage is not counted as damage

Every failure writes an integrity_failed audit row and an ERROR line in the REST log beginning document integrity failure. Point your log alerting at that text.

To check every object, or to see what a run would delete:

cd apiome-rest
PYTHONPATH=src python scripts/document_lifecycle.py --dry-run # what would be deleted
PYTHONPATH=src python scripts/document_lifecycle.py --integrity-only --all

The script prints a JSON report and exits 1 when an object failed its check, 2 when another run holds the lock. Only one run goes at a time across all REST instances.

The audit​

apiome.document_lifecycle_events has one row per purge and per integrity failure:

eventreason
object_purgedversion-deleted, unreferenced, stale-render or tenant-deleted
object_purge_failedThe same, with the store's error in detail
tenant_purgedtenant-deleted, with the number of objects deleted
integrity_failedmismatch or missing, with the SHA-256 found and the roles that use the object
rendered_droppedA rendered document dropped after a failed check
SELECT occurred_at, event, reason, tenant_id, storage_key
FROM apiome.document_lifecycle_events
ORDER BY occurred_at DESC
LIMIT 20;

Move existing documents into the store​

Changing APIOME_DOCUMENT_STORE does not move what the database already holds: the originals of earlier imports, schemas frozen earlier and unexpired export downloads. Readers find them where they are, so nothing breaks. To move them, run scripts/migrate_documents_to_store.py (or POST /v1/ops/document-migration): it copies each one into the store, verifies it and links it, and a separate --purge-db-copies run removes the database copies once each verifies. The steps are in Move documents to object storage.

What it writesWhere
An original (plus original_part rows for an archive)version_documents, and the sourceDocument pointer on format_metadata
A frozen_schemaversion_documents
An export download's objectexport_job_artifact.storage_uri; the purge switches the row to object_store
verified_at on every object it read backdocument_objects
How far each step gotdocument_migration_checkpoints (migration V405)

The same step also moves originals written to the db backend into s3 or filesystem after you switch backends, as long as the database copy is still there.

Troubleshooting​

Errors name the bucket and the provider's error code. Access keys and secret keys are never written to an error or a log.

MessageFix
APIOME_DOCUMENT_STORE=s3 needs APIOME_DOCUMENT_STORE_BUCKETSet the bucket.
APIOME_DOCUMENT_STORE_ENDPOINT_URL is refusedThe endpoint is on a private address. Set APIOME_DOCUMENT_STORE_ALLOW_PRIVATE=true.
… (NoSuchBucket: …)Create the bucket, or check the endpoint and region.
… (AccessDenied: …)Grant the key read, write and delete on the prefix.
… (SignatureDoesNotMatch: …)Check the secret key, and that REGION matches the service.
A host name like bucket.host does not resolveSet APIOME_DOCUMENT_STORE_ADDRESSING_STYLE=path.
/v1/schema answers 503 for a frozen versionThe frozen object is missing from the bucket or directory. Restore it from a backup, or unfreeze the version and freeze it again.
rendered document not stored in the REST logThe store refused the write. /v1/schema still works but generates the document for each request. Check the store settings above.
The REST API stops at startup with The document store (…) is not usableFix the setting the message names, or set APIOME_DOCUMENT_STORE_FALLBACK=db to start on the database store meanwhile. See At startup.
Test connection fails at Delete itThe key can write and read but not delete. Grant s3:DeleteObject on the prefix.
503 tenant-document-store-unavailableThe tenant's own bucket is down or its credential no longer works. The tenant administrator fixes the bucket or chooses a working credential in Document storage. See When a tenant's bucket stops answering.
403 tenant-document-store-disabledThe installation does not offer tenant buckets. Set APIOME_DOCUMENT_STORE_ALLOW_TENANT_BUCKETS=true.
A tenant's endpoint is refused when savingIt resolves to a private address. Use a public endpoint, or set APIOME_DOCUMENT_STORE_TENANT_ALLOW_PRIVATE=true if tenants run stores on your network.

Where next​