Skip to content

Commit

Permalink
schema: allow jinja in diff keyword (#2774)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Dec 3, 2022
1 parent 8885f24 commit 7e98294
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
16 changes: 8 additions & 8 deletions src/ansiblelint/schemas/ansible.json
Expand Up @@ -145,8 +145,8 @@
"type": "string"
},
"diff": {
"title": "Diff",
"type": "boolean"
"$ref": "#/$defs/templated-boolean",
"title": "Diff"
},
"environment": {
"$ref": "#/$defs/environment"
Expand Down Expand Up @@ -319,8 +319,8 @@
"type": "string"
},
"diff": {
"title": "Diff",
"type": "boolean"
"$ref": "#/$defs/templated-boolean",
"title": "Diff"
},
"environment": {
"$ref": "#/$defs/environment"
Expand Down Expand Up @@ -685,8 +685,8 @@
"type": "string"
},
"diff": {
"title": "Diff",
"type": "boolean"
"$ref": "#/$defs/templated-boolean",
"title": "Diff"
},
"environment": {
"$ref": "#/$defs/environment"
Expand Down Expand Up @@ -893,8 +893,8 @@
"type": "string"
},
"diff": {
"title": "Diff",
"type": "boolean"
"$ref": "#/$defs/templated-boolean",
"title": "Diff"
},
"environment": {
"$ref": "#/$defs/environment"
Expand Down
18 changes: 9 additions & 9 deletions src/ansiblelint/schemas/playbook.json
Expand Up @@ -154,8 +154,8 @@
"type": "string"
},
"diff": {
"title": "Diff",
"type": "boolean"
"$ref": "#/$defs/templated-boolean",
"title": "Diff"
},
"environment": {
"$ref": "#/$defs/environment"
Expand Down Expand Up @@ -334,8 +334,8 @@
"type": "string"
},
"diff": {
"title": "Diff",
"type": "boolean"
"$ref": "#/$defs/templated-boolean",
"title": "Diff"
},
"environment": {
"$ref": "#/$defs/environment"
Expand Down Expand Up @@ -706,8 +706,8 @@
"type": "string"
},
"diff": {
"title": "Diff",
"type": "boolean"
"$ref": "#/$defs/templated-boolean",
"title": "Diff"
},
"environment": {
"$ref": "#/$defs/environment"
Expand Down Expand Up @@ -915,8 +915,8 @@
"type": "string"
},
"diff": {
"title": "Diff",
"type": "boolean"
"$ref": "#/$defs/templated-boolean",
"title": "Diff"
},
"environment": {
"$ref": "#/$defs/environment"
Expand Down Expand Up @@ -1214,7 +1214,7 @@
"type": "object"
}
},
"$id": "https://raw.githubusercontent.com/ansible-lint/main/src/ansiblelint/schemas/ansible-playbook.json",
"$id": "https://raw.githubusercontent.com/ansible-lint/main/src/ansiblelint/schemas/playbook.json",
"$schema": "http://json-schema.org/draft-07/schema",
"examples": [
"playbooks/*.yml",
Expand Down
10 changes: 5 additions & 5 deletions src/ansiblelint/schemas/tasks.json
Expand Up @@ -106,8 +106,8 @@
"type": "string"
},
"diff": {
"title": "Diff",
"type": "boolean"
"$ref": "#/$defs/templated-boolean",
"title": "Diff"
},
"environment": {
"$ref": "#/$defs/environment"
Expand Down Expand Up @@ -367,8 +367,8 @@
"type": "string"
},
"diff": {
"title": "Diff",
"type": "boolean"
"$ref": "#/$defs/templated-boolean",
"title": "Diff"
},
"environment": {
"$ref": "#/$defs/environment"
Expand Down Expand Up @@ -564,7 +564,7 @@
]
}
},
"$id": "https://raw.githubusercontent.com/ansible-lint/main/src/ansiblelint/schemas/ansible-tasks.json",
"$id": "https://raw.githubusercontent.com/ansible-lint/main/src/ansiblelint/schemas/tasks.json",
"$schema": "http://json-schema.org/draft-07/schema",
"examples": [
"tasks/*.yml",
Expand Down
2 changes: 1 addition & 1 deletion test/schemas/package.json
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"compile": "tsc -p ./src",
"deps": "npx npm-check-updates -u && npm install --ignore-scripts",
"test": "mocha"
"test": "python3 src/rebuild.py && mocha"
},
"devDependencies": {
"@types/chai": "^4.3.3",
Expand Down
6 changes: 3 additions & 3 deletions test/schemas/src/rebuild.py
Expand Up @@ -80,7 +80,7 @@ def is_ref_used(obj: Any, ref: str) -> bool:
invalid_var_names.remove("__peg_parser__")
print("Updating invalid var names")

with open("f/ansible-vars.json", "r+", encoding="utf-8") as f:
with open("f/vars.json", "r+", encoding="utf-8") as f:
vars_schema = json.load(f)
vars_schema["anyOf"][0]["patternProperties"] = {
f"^(?!({'|'.join(invalid_var_names)})$)[a-zA-Z_][\\w]*$": {}
Expand Down Expand Up @@ -121,7 +121,7 @@ def is_ref_used(obj: Any, ref: str) -> bool:
sub_json["$comment"] = "Generated from ansible.json, do not edit."
sub_json[
"$id"
] = f"https://raw.githubusercontent.com/ansible-lint/main/src/ansiblelint/schemas/ansible-{subschema}.json"
] = f"https://raw.githubusercontent.com/ansible-lint/main/src/ansiblelint/schemas/{subschema}.json"

# Remove all unreferenced ($ref) definitions ($defs) recursively
while True:
Expand All @@ -135,6 +135,6 @@ def is_ref_used(obj: Any, ref: str) -> bool:
if not spare:
break

with open(f"f/ansible-{subschema}.json", "w", encoding="utf-8") as f:
with open(f"f/{subschema}.json", "w", encoding="utf-8") as f:
json.dump(sub_json, f, indent=2, sort_keys=True)
f.write("\n")
4 changes: 4 additions & 0 deletions test/schemas/test/playbooks/tasks/diff.yml
@@ -0,0 +1,4 @@
- action: foo
diff: true
- action: foo
diff: "{{ true }}"

0 comments on commit 7e98294

Please sign in to comment.