我正在尝试学习JSON Schema,但是有些事情对我来说行不通。 我正在尝试运行这个例子:http://json-schema.org/understanding-json-schema/reference/conditionals.html#id4,用于dependentSchemas,但它无法通过验证。
我正在使用以下架构:
check_schema = {"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string" },
"credit_card": { "type": "number" }
},
"required": ["name"],
"dependentSchemas": {
"credit_card": {
"properties": {
"billing_address": { "type": "string" }
},
"required": ["billing_address"]
}
}
}
并且这个 JSON 缺少键 billing_address
,因此应该引发错误:
check_dict={
"name": "John Doe",
"credit_card": 5555555555555555
}
但是当我使用jsonschema.validate(dic_check, schema_check)
(使用Python语言,jsonschema软件包版本4.2.1)时,验证通过且没有问题。
我做错了什么?