我正在为在Postman中使用的JSON模式创建一个包含多个架构定义的JSON模式。我需要根据该模式验证的JSON与其中一个架构定义匹配。
示例模式
{
"oneOf": [
{
"$ref": "#/definitions/schema1"
},
{
"$ref": "#/definitions/schema2"
},
{
"$ref": "#/definitions/schema3"
}
],
"definitions": {
"schema1": {
"type": "object",
"properties": {
"propertyA": {
"type": "string"
}
},
"required": [
"propertyA"
]
},
"schema2": {
"type": "object",
"properties": {
"propertyB": {
"type": "string"
}
},
"required": [
"propertyB"
]
},
"schema3": {
"type": "object",
"properties": {
"propertyC": {
"type": "string"
}
},
"required": [
"propertyC"
]
}
}
}
示例JSON数据
该JSON数据将根据模式进行验证,并正确标记为无效(因为需要字符串):
{
"propertyA": 123
}
问题
根据https://www.jsonschemavalidator.net/,此示例返回4个错误:
- 消息:JSON与“oneOf”中没有模式匹配。 模式路径:#/oneOf
- 消息:无效类型。 期望的是字符串,但得到的是整数。 模式路径:#/definitions/schema1/properties/propertyA/type
- 消息:对象缺少必需的属性:propertyC。
模式路径:#/definitions/schema3/required - 消息:对象缺少必需的属性:propertyB。
模式路径:#/definitions/schema2/required
我只对期望一个字符串的错误消息感兴趣。 在保持模式定义在1个单独文件中的同时,如何避免其他错误消息?