[英]required and additionalProperties is not working for jsonschema module Python
I have following code : 我有以下代码:
from jsonschema import validate
schema_data = {
"type" : "object",
"properties" : {
"price" : {"type" : "number"},
"name" : {"type" : "string"},
"additional" : {"type" : "number"},
},
"required": ["price", "name", "additional"],
"additionalProperties": False
}
json_data = {"name" : "Eggs", "price" : 34.99, "new": 90}
This should give me an error for both required
and additionalProperties
as additional
is not present in json_data
and new
is not present in schema_data
. 两个这应该给我一个错误
required
和additionalProperties
作为additional
没有出现在json_data
和new
没有出现在schema_data
。 But script is not giving any error . 但是脚本没有给出任何错误 。
Do I need some extra to install? 我需要额外安装吗? I am having following configuration:
我有以下配置:
Python 2.7.12,
jsonschema==3.0.1
attrs==19.1.0
six==1.12.0
pyrsistent==0.14.11
You need to run below command for getting error 您需要在命令下运行以获取错误
validate(json_data, schema_data)
So first you'll get error 所以首先你会得到错误
'additional' is a required property
After fixing you'll get error for 修复后,您将得到错误
Additional properties are not allowed ('new' was unexpected)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.