How to automatically validate QDT files¶
In order to minimize friction and maximize productivity, the project provides a schema.json for scenarios and profiles files.
Text editors (IDE)¶
If your editor supports JSON and YAML schema validation, it’s definitely recommended to set it up. Here is a demonstration on how it works in Visual Studio Code:
Visual Studio Code¶
Profiles¶
Add the following line at the top of your JSON file:
{
"$schema": "https://raw.githubusercontent.com/Guts/qgis-deployment-cli/main/docs/schemas/profile/qgis_profile.json"
[...]
}
Scenarios¶
Install the vscode-yaml extension for YAML language support.
Add the schema under the
yaml.schemas
key in your user or workspacesettings.json
:
{
"yaml.schemas": {
"https://raw.githubusercontent.com/Guts/qgis-deployment-cli/main/docs/schemas/scenario/schema.json": "*.qdt.yml"
}
}
Using pre-commit¶
Since it’s strongly recomended to use Git to store and publish QDT profiles and scenarios, it’s possible to use git hooks to automatically validate QDT files.
Here comes a typical configuration for the pre-commit micro-framework (see upstream instructions to install it):
exclude: ".venv|tests/dev/|tests/fixtures/"
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-byte-order-marker
- repo: https://gitlab.com/bmares/check-json5
rev: v1.0.0
hooks:
- id: check-json5
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.0
hooks:
- id: check-jsonschema
name: Check QDT profiles
files: ^profiles/.*\.json$
args:
- --schemafile
- https://raw.githubusercontent.com/Guts/qgis-deployment-cli/main/docs/schemas/profile/qgis_profile.json
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.0
hooks:
- id: check-jsonschema
name: Check QDT scenarios
files: ^qdt_scenarii/.*\.yml$
args:
- --default-filetype
- yaml
- --base-uri
- https://raw.githubusercontent.com/Guts/qgis-deployment-cli/main/docs/schemas/scenario/
- --schemafile
- https://raw.githubusercontent.com/Guts/qgis-deployment-cli/main/docs/schemas/scenario/schema.json