Skip to content

Environments and secrets

vars in the config are the defaults for every environment. To change them for one environment, put them in .specbook/environments/<env>.env, or under environments.<env>.vars in the config. A service’s address is a variable, so each environment can point somewhere else:

services: { petstore: { spec: './openapi/petstore.json', baseUrl: '{{petstoreUrl}}' } }
.specbook/environments/staging.env
petstoreUrl=https://staging.petstore.example/api/v3

Name your secrets in the config, for example secrets: { PETSTORE_API_KEY: {} }. Specbook reads each one from an environment variable first, then from --secrets-file, the environment’s <env>.secrets.env and secrets.local.env. The folder’s .gitignore keeps the secrets files out of your repository.

Run specbook secrets --env staging to see where each secret resolves from. It never prints a value. A test run masks every secret value wherever it appears, including its URL-encoded, JSON-escaped and base64 forms, and removes credentials from reports.

A published portal never holds a secret. A visitor types credentials once per tab, they are kept per API origin, and a key typed for one API is never sent to another. An embed keeps them in memory only.

A relative address such as /api/petstore resolves against the page, so one environment file serves every host a site is published on. This site’s demo environment works that way.