我有一本包含配置資訊的字典:
“request”:
{
“request_id”: uuid,
"points": {
"<point_id>": {"weight": float},
}
}
例如
"request":{
"request_id": "553380e1-fa37-4666-886e-7f56c0540ed8",
"points": {
"0": {
"weight": 5
},
"1": {
"weight":10
}
}
}
應該是這樣的嗎?
"request": {
"type": "object",
"properties": {
"request_id": {
"type": "string",
},
"points":{
"type": "array",
"items": {
????
}
}
}
我無法在我的燒瓶專案中找到驗證模式。有什么解決辦法嗎?
uj5u.com熱心網友回復:
points是一個物件,而不是一個整數。您可以在 中使用正則運算式指定變數屬性名稱patternProperties,或者如果屬性名稱可以是任何名稱,則使用它additionalProperties來約束值。
...
"points": {
"patternProperties": {
"^[0-9] $": {
"type": "object",
"properties": {
"weight": {
"type": "integer"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/472804.html
標籤:Python 验证 图式 jsonschema
