【发布时间】:2021-03-03 16:57:56
【问题描述】:
我已经创建了一个 JSON Schema,但是当我尝试使用它来验证另一个对象时,该模式由于错误而失败,引用:
消息: 对象缺少必需的属性:信封。 架构路径: #/必填
但是,我可以清楚地看到信封内列出的所需数组是其属性的兄弟。在我在网上看到的每个模式中,都是这样显示的。我在下面包含了一个精简的模式选择,仍然看到相同的错误。谁能告诉我为什么会失败?
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"Envelope": {
"type": "object",
"properties": {
"TP_UNIQUE_NUM": {
"length": 50,
"type": "string"
},
"SENDER_ID": {
"length": 50,
"type": "string"
},
"TRANSMISSION_FORMAT": {
"length": 50,
"type": "string"
},
"RECEIVER_ID": {
"length": 50,
"type": "string"
},
"HEADER": {
"type": "object",
"properties": {
"door": {
"description": "Door at which product associated with ASN is scheduled to be unloaded",
"type": "string",
"mandatory": "Y",
"maxLength": 10
},
"notes": {
"description": "Comments associated with ASN",
"type": "string",
"mandatory": "Y",
"maxLength": 4000
},
"wareHouseReference": {
"description": "Additional notes or reference information for the warehouse",
"type": "string",
"mandatory": "Y",
"maxLength": 100
}
},
"required": [
"wareHouseReference"
]
},
"TP_TRANSMISSION_TYPE": {
"maxLength": 50,
"type": "string"
},
"FILE_NAME": {
"maxLength": 50,
"type": "string"
},
"TRANSMISSION_DATE_TIME": {
"maxLength": 50,
"type": "string"
},
"TRANSACTION_COUNT": {
"maxLength": 50,
"type": "string"
}
}
}
},
"required": [
"Envelope"
]
}
【问题讨论】:
-
您的架构没有问题。该错误听起来像是在告诉您正在验证的数据没有所需的属性“信封”。
标签: json jsonschema