'How to validate schema of list of dicts in python?
I have a dictionary with config info:
“request”:
{
“request_id”: uuid,
"points": {
"<point_id>": {"weight": float},
}
}
For example
"request":{
"request_id": "553380e1-fa37-4666-886e-7f56c0540ed8",
"points": {
"0": {
"weight": 5
},
"1": {
"weight":10
}
}
}
It should be like this?
"request": {
"type": "object",
"properties": {
"request_id": {
"type": "string",
},
"points":{
"type": "array",
"items": {
????
}
}
}
I am not able to find the validation schema in my flask project. Is there any solution for this?
Solution 1:[1]
points is an object, not an integer. You can specify variable property names with a regular expression in patternProperties, or if the property names can be anything, use additionalProperties to constrain the values.
...
"points": {
"patternProperties": {
"^[0-9]+$": {
"type": "object",
"properties": {
"weight": {
"type": "integer"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jason Desrosiers |
