diff --git a/src/ansiblelint/schemas/ansible.json b/src/ansiblelint/schemas/ansible.json index 3272790fb0..94846d0525 100644 --- a/src/ansiblelint/schemas/ansible.json +++ b/src/ansiblelint/schemas/ansible.json @@ -627,7 +627,17 @@ }, "vars_files": { "items": { - "type": "string" + "oneOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + } + ] }, "title": "Vars Files", "type": ["array", "string", "null"] diff --git a/src/ansiblelint/schemas/playbook.json b/src/ansiblelint/schemas/playbook.json index d9c704e05e..983033f820 100644 --- a/src/ansiblelint/schemas/playbook.json +++ b/src/ansiblelint/schemas/playbook.json @@ -642,7 +642,17 @@ }, "vars_files": { "items": { - "type": "string" + "oneOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + } + ] }, "title": "Vars Files", "type": [ diff --git a/test/schemas/negative_test/playbooks/var_files_list_number.yml.md b/test/schemas/negative_test/playbooks/var_files_list_number.yml.md index 6ecc15e454..e9155933fe 100644 --- a/test/schemas/negative_test/playbooks/var_files_list_number.yml.md +++ b/test/schemas/negative_test/playbooks/var_files_list_number.yml.md @@ -54,7 +54,25 @@ "params": { "type": "string" }, - "schemaPath": "#/properties/vars_files/items/type" + "schemaPath": "#/properties/vars_files/items/oneOf/0/type" + }, + { + "instancePath": "/0/vars_files/0", + "keyword": "type", + "message": "must be array", + "params": { + "type": "array" + }, + "schemaPath": "#/properties/vars_files/items/oneOf/1/type" + }, + { + "instancePath": "/0/vars_files/0", + "keyword": "oneOf", + "message": "must match exactly one schema in oneOf", + "params": { + "passingSchemas": null + }, + "schemaPath": "#/properties/vars_files/items/oneOf" }, { "instancePath": "/0", @@ -106,9 +124,17 @@ stdout: "path": "$[0].vars_files", "message": "[0] is not of type 'object'" }, + { + "path": "$[0].vars_files[0]", + "message": "0 is not valid under any of the given schemas" + }, { "path": "$[0].vars_files[0]", "message": "0 is not of type 'string'" + }, + { + "path": "$[0].vars_files[0]", + "message": "0 is not of type 'array'" } ] } diff --git a/test/schemas/negative_test/playbooks/var_files_list_of_list_number.yml b/test/schemas/negative_test/playbooks/var_files_list_of_list_number.yml new file mode 100644 index 0000000000..7170010fd1 --- /dev/null +++ b/test/schemas/negative_test/playbooks/var_files_list_of_list_number.yml @@ -0,0 +1,5 @@ +--- +- name: var_files should not accept array[number] + hosts: localhost + vars_files: + - [0, 1] diff --git a/test/schemas/negative_test/playbooks/var_files_list_of_list_number.yml.md b/test/schemas/negative_test/playbooks/var_files_list_of_list_number.yml.md new file mode 100644 index 0000000000..349449838e --- /dev/null +++ b/test/schemas/negative_test/playbooks/var_files_list_of_list_number.yml.md @@ -0,0 +1,157 @@ +# ajv errors + +```json +[ + { + "instancePath": "/0", + "keyword": "required", + "message": "must have required property 'ansible.builtin.import_playbook'", + "params": { + "missingProperty": "ansible.builtin.import_playbook" + }, + "schemaPath": "#/oneOf/0/required" + }, + { + "instancePath": "/0", + "keyword": "required", + "message": "must have required property 'import_playbook'", + "params": { + "missingProperty": "import_playbook" + }, + "schemaPath": "#/oneOf/1/required" + }, + { + "instancePath": "/0", + "keyword": "oneOf", + "message": "must match exactly one schema in oneOf", + "params": { + "passingSchemas": null + }, + "schemaPath": "#/oneOf" + }, + { + "instancePath": "/0", + "keyword": "additionalProperties", + "message": "must NOT have additional properties", + "params": { + "additionalProperty": "hosts" + }, + "schemaPath": "#/additionalProperties" + }, + { + "instancePath": "/0/vars_files", + "keyword": "type", + "message": "must be object", + "params": { + "type": "object" + }, + "schemaPath": "#/patternProperties/vars/type" + }, + { + "instancePath": "/0/vars_files/0", + "keyword": "type", + "message": "must be string", + "params": { + "type": "string" + }, + "schemaPath": "#/properties/vars_files/items/oneOf/0/type" + }, + { + "instancePath": "/0/vars_files/0/0", + "keyword": "type", + "message": "must be string", + "params": { + "type": "string" + }, + "schemaPath": "#/properties/vars_files/items/oneOf/1/items/type" + }, + { + "instancePath": "/0/vars_files/0/1", + "keyword": "type", + "message": "must be string", + "params": { + "type": "string" + }, + "schemaPath": "#/properties/vars_files/items/oneOf/1/items/type" + }, + { + "instancePath": "/0/vars_files/0", + "keyword": "oneOf", + "message": "must match exactly one schema in oneOf", + "params": { + "passingSchemas": null + }, + "schemaPath": "#/properties/vars_files/items/oneOf" + }, + { + "instancePath": "/0", + "keyword": "oneOf", + "message": "must match exactly one schema in oneOf", + "params": { + "passingSchemas": null + }, + "schemaPath": "#/items/oneOf" + } +] +``` + +# check-jsonschema + +stdout: + +```json +{ + "status": "fail", + "errors": [ + { + "filename": "negative_test/playbooks/var_files_list_of_list_number.yml", + "path": "$[0]", + "message": "{'name': 'var_files should not accept array[number]', 'hosts': 'localhost', 'vars_files': [[0, 1]]} is not valid under any of the given schemas", + "has_sub_errors": true, + "best_match": { + "path": "$[0]", + "message": "'hosts' does not match any of the regexes: '^(ansible\\\\.builtin\\\\.)?import_playbook$', 'name', 'tags', 'vars', 'when'" + }, + "sub_errors": [ + { + "path": "$[0]", + "message": "'hosts' does not match any of the regexes: '^(ansible\\\\.builtin\\\\.)?import_playbook$', 'name', 'tags', 'vars', 'when'" + }, + { + "path": "$[0]", + "message": "{'name': 'var_files should not accept array[number]', 'hosts': 'localhost', 'vars_files': [[0, 1]]} is not valid under any of the given schemas" + }, + { + "path": "$[0]", + "message": "'ansible.builtin.import_playbook' is a required property" + }, + { + "path": "$[0]", + "message": "'import_playbook' is a required property" + }, + { + "path": "$[0].vars_files", + "message": "[[0, 1]] is not of type 'object'" + }, + { + "path": "$[0].vars_files[0]", + "message": "[0, 1] is not valid under any of the given schemas" + }, + { + "path": "$[0].vars_files[0]", + "message": "[0, 1] is not of type 'string'" + }, + { + "path": "$[0].vars_files[0][0]", + "message": "0 is not of type 'string'" + }, + { + "path": "$[0].vars_files[0][1]", + "message": "1 is not of type 'string'" + } + ] + } + ], + "parse_errors": [] +} +``` diff --git a/test/schemas/test/playbooks/var_files.yml b/test/schemas/test/playbooks/var_files.yml index eef44fd7ba..263028773f 100644 --- a/test/schemas/test/playbooks/var_files.yml +++ b/test/schemas/test/playbooks/var_files.yml @@ -11,3 +11,8 @@ hosts: localhost vars_files: - /dev/null + +- name: var_files should accept array of array[string] + hosts: localhost + vars_files: + - ["/dev/null"]