@airnode/validator
Package for JSON specifications validation. Validation process can be configured with validator templates.
Usage
The validator can be run as a yarn script, by providing template of specification, and the path to the JSON file of
specification that will be validated:
yarn run validate --template="[template]" --specs="[specsFile]"
Templates are case-insensitive, valid templates are: config
, OIS
, apiSpecifications
/apiSpecs
, endpoints
and
receipt
:
yarn run validate --template="config" --specs="exampleSpecs/config.specs.json"
Validator will automatically validate the latest available version of provided template, in case a specific version
should be used in validation, it can be appended to template argument:
yarn run validate --template="config@0.2.0" --specs="exampleSpecs/config.specs.json"
Custom templates can be used, by providing path to the validator template file in place of template
:
yarn run validate --template="templates/0.2.0/config.json" --specs="exampleSpecs/config.specs.json"
Output
Above mentioned commands will return json in following format:
{
valid: boolean,
messages: { level: "error" | "warning", message: string }[]
}
valid
is set to true
in case there are no errors, however there can be still warnings in the messages
.
Templates
Validator behavior can be configured with validator templates, which are regular json
files using special keywords for
specification validation. Usage of these keywords is described in the following chapters:
@airnode/convertor
Built-in validator extension capable of conversions between various specifications, conversions are configured using
validator templates with conversion actions.
Usage
Convertor works the same way as validator and can be invoked with the convert
command, for example:
yarn run convert --template="conversions/oas@3.0.0------ois@0.2.0.json" --specs="exampleSpecs/OAS.specs.json"
Conversions can be invoked without providing any template, specifying which format provided specification is in and to
which format it should be converted into, is enough:
yarn run convert --from="OAS" --to="OIS" --specs="exampleSpecs/OAS.specs.json"
Specification formats are case-insensitive, currently available conversions are from OAS
to OIS
or from OIS
to
config
. Version of the format can be provided as in validate
command:
yarn run convert --from="OIS@pre-alpha" --to="config@pre-alpha" --specs="exampleSpecs/ois.specs.json"
Output
On top of validator output, convertor provides an output
object, which contains the converted specification:
{
valid: boolean,
messages: { level: "error" | "warning", message: string }[],
output: object
}
Alternatively command can be ran with argument --specs-only
, which will return only the converted specification.
Templates
Convertor uses the same templates as validator. The resulting specification can be written into output
object with
actions.
Documentation
Source documentation markdown files are located in docs/src/
directory. All template related examples are located in
test/fixtures/
and injected into markdown using
markdown-snippet-injector by running yarn run docs
.
Generated markdown files can be found in docs/
, test files using the same examples can be found in test/
directory.