Check API collection files in CI and in a pre-commit hook

When a collection lives in the repository as YAML, people edit it in two ways: in Requestarium, and by hand in a pull request. Hand edits are where things go wrong: a file copied with its id line, a broken indent, an Authorization header pasted with a real token. requestarium sync validate catches all of these before merge, and it runs without signing in.

Run it once

Terminal
npx --yes @requestarium/cli@latest sync validate
Output
Billing (/collections/billing): 12 requests, 3 folders, 2 environments
.requestarium/sync.yaml: valid
error   collections/billing/users/copy.request.yaml: id 6d0a… is also the id of collections/billing/users/list.request.yaml; copy a file without its id line
warning collections/billing/health.request.yaml: the Authorization header holds a typed value; use a {{variable}}
Not valid: 1 error, 1 warning.

Values are never printed, so the output is safe in a public CI log.

What it checks

CheckResult
.requestarium/sync.yaml against its schema: unknown keys, nested folders, limitserror
A collection, folder, request or environment file that isn't valid YAMLerror
The same id in two files, or two collections with the same iderror
An environment value for a variable not in secrets.allowedVariableserror
A typed credential in a credential-like header or the Authorization tabwarning, or error with secrets.policy: refuse
A credential-like environment variable with a value, not marked secretwarning
A file without an id (added by hand; the next push writes one)warning

Exit code 0 means valid (warnings are printed but don't fail), 1 means errors were found (or warnings with --strict), and 2 means the check couldn't run, for example the folder doesn't exist.

In CI

GitHub Actions

.github/workflows/collections.yml
name: Collection files
on: pull_request
jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
      - run: npx --yes @requestarium/cli@latest sync validate --strict

Inside GitHub Actions, problems are also printed as annotations, so they appear on the changed files of the pull request.

GitLab CI

.gitlab-ci.yml
requestarium-validate:
  image: node:22-alpine
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  script:
    - npx --yes @requestarium/cli@latest sync validate

As a pre-commit hook

Plain Git, in .git/hooks/pre-commit (make it executable):

Terminal
#!/bin/sh
if git diff --cached --name-only | grep -Eq '(^|/)(requestarium\.yaml|_folder\.yaml|[^/]+\.request\.yaml|[^/]+\.env\.yaml)$|^\.requestarium/'; then
  npx --yes @requestarium/cli@latest sync validate "$(git rev-parse --show-toplevel)" || exit 1
fi

It only runs when a commit touches collection files. The same line works in Husky or Lefthook.

The other check: nothing left unpushed

Validation looks at the files. The opposite problem is a collection changed in Requestarium and never pushed, so the repository quietly falls behind. This job asks Requestarium and fails when that happens:

Terminal
REQUESTARIUM_TOKEN=… requestarium sync push --all --check
CommandFails when
sync push --all --checka collection has changes not in the repository, or a conflict
sync status --all --checkanything to push or to pull, or a conflict

These need a token. On the Team plan, Settings ▸ Sync ▸ CI tokens creates a token that can only run sync, belongs to the organization and always expires. A personal token works on every plan.