我正在使用mule validate JSON架构组件来验证我的传入json请求。 它验证类型,但不验证必需的字段属性
{
"type": "object",
"$schema": "http://json-schema.org/draft-04/schema",
"properties": {
"Employees": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"properties": {
"BirthDate": {
"type": "string",
"format": "date-time"
},
"EmpNum": {
"type": "number"
},
"FirstName": {
"type": "string"
},
"Gender": {
"type": "string"
},
"LastName": {
"type": "string"
},
"LicenseNumber": {
"type": "string"
},
"ZipCode": {
"type": "string"
}
},
"required": ["EmpNum", "LastName", "FirstName", "Street", "ZipCode", "BirthDate" ]
}
}
}
}
我有如下所示的json:
{
"Employees": [
{
"EmpNum": 3,
"FirstName": "Finder",
"LastName": "Path",
"Street": "392 CDI CDIJUW",
"ZipCode": "12345",
"BirthDate": "1943-05-19T04:00:00Z",
"Gender": "M"
},
{
"EmpNum": 3,
"FirstName": "",
"LastName": "Path",
"Street": "392 CDI CDIJUW",
"ZipCode": "12345",
"BirthDate": "1943-05-19T04:00:00Z",
"Gender": "M"
}
]
}
即使我已将字段设置为空字符串,它仍然需要作为有效请求并继续进行。
答案 0 :(得分:3)
如果您故意将FirstName设置为空字符串并想要使其无效,请尝试添加minLength:
"FirstName": {
"type": "string",
"minLength": 1
},