I want to validate YAML files in Python with my own scheme. A valid YAML shall look like this:
JavaScript
x
8
1
input:
2
- name1
3
split_to:
4
windows:
5
- split1
6
other:
7
- split2
8
While [windows, other] are dynamic, any name shall allowed there (i.e. “solaris”, “mac”, “templeOS”)
I’m using validate from jsonschema like described here: Validating a yaml document in python
Any other module where this works would be also okay.
Advertisement
Answer
You’re searching for additionalProperties:
JavaScript
1
14
14
1
type: object
2
properties:
3
input:
4
type: array
5
items:
6
type: string
7
split_to:
8
type: object
9
additionalProperties:
10
type: array
11
items:
12
type: string
13
additionalProperties: false
14
Setting it to false
disallows unknown properties in the root mapping. Since JSON Schema is for JSON, keys will always be strings and you can set only the value type for additional properties.