![](/img/Folder-Light.png)
Validator
The airnode-validator is used internally by the Docker Images to validate the configuration files you provide when deploying an Airnode.
However, validator can also be used as a standalone package to verify the correctness of the configuration files without deploying the Airnode. The recommended way is to use the validator CLI, but for advanced use cases you can use the validator SDK.
CLI Usage
The simplest way to run the CLI is using npx. Alternatively, you can install the validator package as a dependency in your project.
npx @api3/airnode-validator --config "config.json" --secrets "secrets.env"
alternatively
# First install the package
npm install @api3/airnode-validator
# Run the validator CLI
npx airnode-validator --config "config.json" --secrets "secrets.env"
2
3
4
5
Examples
Assuming the configurations files inside current working directory are valid, executing:
npx @api3/airnode-validator --config "valid-config.json" --secrets "valid-secrets.env"
yields:
✔ The configuration is valid
When there is an error during validation, the command prints out the error and fails with a non zero status code.
npx @api3/airnode-validator --config "valid-config.json" --secrets "non-existent-secrets.env"
yields:
✖ Unable to read secrets file at "non-existent-secrets.env". Reason: Error: ENOENT: no such file or directory, open (...omitted for brevity)
SDK Usage
The validator package contains an API that can be used to validate Airnode configuration files programatically.
The following functions can be used:
parseConfigWithSecrets(config, secrets)
- Interpolatessecrets
intoconfig
and validates the interpolated configuration. Expects bothconfig
andsecrets
to be JSON objects.parseConfig(config)
- Validates theconfig
. Expects theconfig
to be a JSON object.parseSecrets(secrets)
- Validates thesecrets
. Expects thesecrets
to be a JSON object.parseReceipt(receipt)
- Validates thereceipt
. Expects thereceipt
to be a JSON object.unsafeParseConfigWithSecrets(config, secrets)
- Interpolatessecrets
intoconfig
but does not perform any validation afterwards. Use this function only when you can guarantee that the configuration is valid.
Validator has also full TypeScript support. All of these functions return a typed object.
Examples
const validator = require('@api3/airnode-validator');
const dotenv = require('dotenv');
const fs = require('fs');
const config = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
const secrets = dotenv.parse(fs.readFileSync('secrets.env', 'utf-8'));
const parseResult = validator.parseConfigWithSecrets(config, secrets);
if (parseResult.success) {
const config = parseResult.data;
// ... (do something with valid "config")
} else {
console.error(parseResult.error);
}
2
3
4
5
6
7
8
9
10
11
12
13
14
or:
import * as validator from '@api3/airnode-validator';
import { join } from 'path';
import dotenv from 'dotenv';
import { readFileSync } from 'fs';
const config = JSON.parse(readFileSync('config.json', 'utf-8'));
const secrets = dotenv.parse(readFileSync('secrets.env', 'utf-8'));
const parseResult = validator.parseConfigWithSecrets(config, secrets);
if (parseResult.success) {
const config = parseResult.data;
// ... (do something with valid "config")
} else {
console.error(parseResult.error);
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Build Manually
See the build instructions for the validator in the airnode package repository.
FLEX_END_TAG