我使用jsonschema来验证JSON blob,其中的特定属性可以是日期或日期时间。因此,我希望format
关键字允许多种可能的格式
例如,以下代码起作用:
import rfc3339_validator
schema = {
"title": "example",
"type": "object",
"required": ["example_property"],
"properties": {
"example_property": {
"type": "string",
"format": "date-time"
}
}
}
validate(instance, schema, format_checker=jsonschema.FormatChecker())
但理想情况下,我会将format
与潜在格式列表一起使用,例如["date-time", "date"]
有没有办法做到这一点?我的临时解决方法是使用pattern
关键字来确保属性至少包含一个日期
尝试使用^{} 关键字,如下所示:
相关问题 更多 >
编程相关推荐