Spectral / JSON and YAML Linter¶
JSON and YAML files can be linted with custom rules using Spectral. The goal of using this linter is to ensure that best practice is followed.
Configuration¶
Each repo will need one configuration file in the root of the repository.
.spectral.yml
- Configures rules, which can be used to lint the JSON or YAML files.
There are rules available to be used or customization is possible too. For more information, please visit Spectral Document
Usage¶
The linter can be used in different purpose,
so a FUNCTION
named BUILD_SPECTRAL
is implemented
to make it suit the purpose.
BUILD_SPECTRAL
contains four main arguments
file_type
: the file type that will be lint. If it is set tojson
, minifying the JSON files will be performed. JSON and YAML linting are not allowed simultaneously to prevent conflicts. Enforcing separate linting ensures accurate analysis for each file type in a folder, avoiding errors.dir
: A directory that contains files to be lint.src
: The root directoryrule_set
: Rules set that is used
Example¶
The example of using the linter can be found in link.
The target check-lint-openapi
is currently used for linting OpenAPI JSON file.
The current rules set that is being used are:
The example of OpenAPI documentation can be found in link.
Warning
Please note that this OpenAPI documentation provided in this repository is used for example purposes only.
For more information about OpenAPI Specification, please visit the official documentation.