Skip to content

Commit 49377b8

Browse files
authored
Add support for json schema validation (#2035)
1 parent 5abb26b commit 49377b8

42 files changed

Lines changed: 3073 additions & 25 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.config/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ isdir
7676
isdisjoint
7777
iskeyword
7878
isort
79+
jsonschema
7980
junitxml
8081
kubernetes
8182
libera

.github/workflows/tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ jobs:
155155
WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:TOX_PARALLEL_NO_SPINNER
156156
# Number of expected test passes, safety measure for accidental skip of
157157
# tests. Update value if you add/remove tests.
158-
PYTEST_REQPASS: 625
158+
PYTEST_REQPASS: 629
159159

160160
steps:
161161
- name: Activate WSL1

.pre-commit-config.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ repos:
2828
examples/playbooks/templates/not-valid.yaml|
2929
examples/playbooks/with-umlaut-.*|
3030
examples/playbooks/with-skip-tag-id.yml|
31-
test/fixtures/formatting-before/.*
31+
test/fixtures/formatting-before/.*|
32+
src/ansiblelint/schemas/.*
3233
)$
3334
additional_dependencies:
3435
- prettier
@@ -60,6 +61,7 @@ repos:
6061
(?x)^(
6162
examples/playbooks/(with-skip-tag-id|unicode).yml|
6263
examples/playbooks/example.yml|
64+
test/eco/.*.result|
6365
test/fixtures/formatting-before/.*
6466
)$
6567
- id: mixed-line-ending
@@ -72,6 +74,10 @@ repos:
7274
rev: v2.1.0
7375
hooks:
7476
- id: codespell
77+
exclude: >
78+
(?x)^(
79+
src/ansiblelint/schemas/.*\.json
80+
)$
7581
- repo: https://github.com/PyCQA/doc8
7682
rev: 0.11.1
7783
hooks:
@@ -126,10 +132,11 @@ repos:
126132
- rich>=11.0.0
127133
- ruamel.yaml
128134
- sphinx>=4.4.0
129-
- types-pyyaml>=6.0.4
130135
- types-dataclasses
131136
- types-docutils
137+
- types-jsonschema>=4.4.2
132138
- types-pkg_resources
139+
- types-pyyaml>=6.0.4
133140
- wcmatch
134141
- yamllint
135142
exclude: >
@@ -147,6 +154,7 @@ repos:
147154
- docutils
148155
- enrich
149156
- flaky
157+
- jsonschema>=4.5.1
150158
- pytest
151159
- pyyaml
152160
- rich>=11.0.0

conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import importlib
33
import os
44
import sys
5+
from typing import Any
6+
7+
from ansiblelint.schemas import refresh_schemas
58

69
# checking if user is running pytest without installing test dependencies:
710
missing = []
@@ -18,3 +21,10 @@
1821

1922
os.environ["NO_COLOR"] = "1"
2023
pytest_plugins = ["ansiblelint.testing.fixtures"]
24+
25+
26+
def pytest_configure(config: Any) -> None:
27+
"""Configure pytest."""
28+
# run only on master node (xdist):
29+
if not hasattr(config, "slaveinput"):
30+
refresh_schemas()

cspell.config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ignorePaths:
1717
- docs/requirements.in
1818
# Test fixtures generated from outside
1919
- test/**/*.result
20+
- src/ansiblelint/schemas/*.json
2021
# Other
2122
- "*.svg"
2223
allowCompoundWords: true

examples/galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ dependencies:
1111
other_namespace.collection2: ">=2.0.0,<3.0.0"
1212
anderson55.my_collection: "*" # note: "*" selects the highest version available
1313
license:
14-
- GPL
14+
- GPL # <-- invalid license values based on galaxy schema
1515
- Apache

examples/playbooks/command-check-failure.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
ansible.builtin.shell: echo blah
1111
args:
1212
chdir: X
13+
become_method: xx
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
- name: This should raise json-schema error, due to hosts missing the last letter
3+
host: localhost
4+
tasks: []
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
foo
3+
# This file is valid YAML but from our point of view is an error, as is
4+
# neither a Sequence or a Mapping.
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
foo
2-
# This file is valid YAML but from our point of view is an error, as is
3-
# neither a Sequence or a Mapping.
1+
# This file is valid YAML and passed JSON Schema validation but not ansible
2+
# own syntax check.
3+
4+
- hosts: localhost
5+
tasks:
6+
- name: invalid syntax
7+
x.y.z.w: {}

0 commit comments

Comments
 (0)