JSON架构格式验证不起作用



我正在使用strict-rfc3339作为项目的依赖项,并尝试验证json模式的日期和日期时间格式。如果我只传递日期,它运行良好,但当我作为JSON(键值对(传递时,它不进行验证。

以下是样本

from jsonschema import validate, FormatChecker       
# throws validation error as expected        
validate( {"2001-02"}, {"type": "string", "format": "date"}, format_checker=FormatChecker()) 
# Doesn't throw error which is wrong
validate({"dob": "2001-02"}, {"dob": {"type": "string", "format": "date"}}, format_checker=FormatChecker()) 

有人能帮忙吗?我是不是错过了什么?

您的第二个模式编写不正确。应该是:

{
"type": "object",
"properties": {
"dob": {
"type": "string",
"format": "date"
}
}
}

有关指定嵌套对象和特性的详细信息,请访问https://json-schema.org/understanding-json-schema/reference/object.html.

最新更新