validate including the key values in another listSee original GitHub issue
I’m looking to ways to validate that certain keys are included in a predefined list, an example can be
--- teachers: - Mike - Anna - Smith
And I want to add students where each student need to have a teacher str value which should be part of the given list above
--- students: - name: studentA teacher: Mike - name: StudentB teacher: NonExistingTeacher
going through the docs and examples it is not clear if this is even possible to do using yamale
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
If the list of teachers can be defined within the schema, then you could rewrite it as an enum (e.g.
teacher: enum('Mike', 'Anna', 'Smith')), that will work with yamale as-is.
So the schema would look like one of the two below:
students: list(include('student')) --- student: name: str() teacher: enum('Mike', 'Anna', 'Smith')
students: list(include('student')) --- student: name: str() teacher: enum( 'Mike', 'Anna', 'Smith' )
Otherwise (if it must be formatted as a list, and/or will be provided as part of the file to validate) there’s a lot of routes available, but they’d require tinkering:
- Expand or inherit from the Enum validator to accept
include()statements that correspond to lists of primitives (this sounds useful in general).
- Override multiple places (probably
Schema._validate, and adding a custom validator) to handle loading in the teachers from the data before/during validation.
- Write a script that runs before yamale and fills in the teacher enum using a list from the data (which could be validated beforehand, something like
yamale(doc, first schema) -> script(doc, incomplete second schema) -> yamale(doc, second schema)).