【发布时间】:2020-10-31 18:20:20
【问题描述】:
我想编写验证对象列表的架构的一部分,其中列表中的对象没有名称:
"some list": [
{
"thing 1": "foo",
"thing 2": 100
},
{
"thing 1": "foo",
"thing 2": 100
},
{
"thing 1": "foo",
"thing 2": 100
},
]
我有一个工作模式,其中包含我想要删除的额外键名,标记为I WANT TO GET RID OF THIS NAME。我猜你可以认为它没有该对象的属性名称。
{
"$schema": "http://json-schema.org/draft-07/schema#",
"id": "v2",
"properties": {
"some list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"I WANT TO GET RID OF THIS NAME": {
"type": "object",
"properties": {
"thing 1": {
"type": "string",
"description": "a string"
},
"thing 2": {
"type": "integer",
"minimum": 0,
"description": "Default time to expose a single image layer for."
}
},
"additionalProperties": false
},
"additionalProperties": false
}
}
}
}
}
我不能仅仅因为模式规范期望它而删除名称,但我也无法弄清楚如何告诉它那些对象没有名称。我正在使用 jsonschema Draft7Validator 使用 Python 3.7 运行此示例
【问题讨论】:
标签: python json schema jsonschema