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
npx --yes @requestarium/cli@latest sync validateBilling (/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
| Check | Result |
|---|---|
.requestarium/sync.yaml against its schema: unknown keys, nested folders, limits | error |
| A collection, folder, request or environment file that isn't valid YAML | error |
The same id in two files, or two collections with the same id | error |
An environment value for a variable not in secrets.allowedVariables | error |
| A typed credential in a credential-like header or the Authorization tab | warning, or error with secrets.policy: refuse |
| A credential-like environment variable with a value, not marked secret | warning |
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
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 --strictInside GitHub Actions, problems are also printed as annotations, so they appear on the changed files of the pull request.
GitLab CI
requestarium-validate:
image: node:22-alpine
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- npx --yes @requestarium/cli@latest sync validateAs a pre-commit hook
Plain Git, in .git/hooks/pre-commit (make it executable):
#!/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
fiIt 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:
REQUESTARIUM_TOKEN=… requestarium sync push --all --check| Command | Fails when |
|---|---|
sync push --all --check | a collection has changes not in the repository, or a conflict |
sync status --all --check | anything 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.