question: validate a list
See original GitHub issueMaybe I’m just approaching this all wrong, but I was wondering if the following is possible:
item = {
'appid': {'type': 'integer', 'min': 1, 'required': True},
'rank': {'type': 'integer', 'min': 1, 'required': True},
'weight': {'type': 'float', 'required': True},
}
schema = {
'type': 'list',
'minlength': 1,
'required': True,
'schema': {
'type': 'dict', 'schema': item
}
}
I want to use the above to assert that a list I have, contains at least one element, and that each element of the list adheres to the item schema.
However, the above does not work since schema can only be applied to a dict.
So, as I understand it, I would have to wrap my list in a dict (e.g. {'list': list}
), and then change my schema
definition to:
schema = {
'list': {
'type': 'list',
'minlength': 1,
'required': True,
'schema': {
'type': 'dict', 'schema': item
}
}
}
I would really like to avoid this redundant nesting though but still use cerberus for the list validation, not “plain native” python (e.g. if isinstance(list, collections.Iterable) and len(list) > 0:
).
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
python - validate list of lists with a unique and common element
I need to validate this list and it will be valid if only one element is repeated in all the lists and the...
Read more >Validate text answer against a list of words - LimeSurvey forums
Hi guys, I have a kill list of words that I'm trying to use to validate a particular short text answer. The question...
Read more >Advanced Concepts — Questionary 1.9.0 documentation
Many of the prompts support a validate argument, which allows the answer to be validated before being ... A question to select an...
Read more >Solved For this discussion, you are given a list of | Chegg.com
For this discussion, you are given a list of questions related to form validation. Simply answer the questions in your own words, using...
Read more >Take in 10 numbers, validate each input, append then in a list ...
Please be sure to answer the question. Provide details and share your research! ... Asking for help, clarification, or responding to other answers ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
have you looked at http://docs.python-cerberus.org/en/stable/usage.html#schema-list ?
Did you end up with wrapping in object or not?