【发布时间】:2020-03-25 19:01:11
【问题描述】:
我知道这个问题经常出现,我在发布之前尝试过研究这个问题,但仍然不知道我错过了什么
我有一个包含嵌套对象的架构。我的架构期望 company 属性是一个对象。该对象具有必需的属性,但它们被忽略了。为什么它忽略了必需的属性?
架构:
{
'business_type': {
'type': 'string',
"enum": ['company', 'non_profit']
},
'email': {
'type': 'string'
},
'company': {
'type': 'object',
'properties': {
'address': {
'type': 'object',
'properties': {
'city': {
'type': 'string',
},
'country': {
'type': 'string',
'enum': ['US']
},
'line1': {
'type': 'string'
},
'line2': {
'type': 'string'
},
'postal_code': {
'type': 'string'
},
'state': {
'type': 'string'
}
},
'required': ['city', 'country', 'line1', 'postal_code', 'state'],
},
'name': {
'type': 'string'
},
'phone': {
'type': 'string'
}
},
'required': ['address', 'name', 'phone'],
},
'required' : ['business_type', 'email', 'company']
}
没有失败但应该失败的示例对象,因为它缺少电话属性
{
"business_type": "company",
"email": "email@email.com",
"company": {
"address": {
"city": "city",
"country": "US",
"line1": "line1",
"line2": "line2",
"postal_code": "00000",
"state": "AZ"
},
"name": "name"
}
}
如果缺少业务类型、电子邮件或公司,验证工作正常,因此它不会验证嵌套结构。
我假设我忽略了某些东西,我只是不知道我忽略了什么
【问题讨论】:
标签: node.js validation jsonschema