我遇到有关AJV模式验证程序的问题。 我有以下架构
$scope.isSelected = function() {
var cnt = 0;
Object.keys($scope.modelCheck).forEach(function (e) {
if ($scope.modelCheck[e]) {
cnt + = 1;
}
});
if (cnt > 0) {
return true;
}
else {
return false;
}
}
我的回答是:
{
"$id": "create-offer.json#",
"body": {
"type": "object",
"properties": {
"statusCode": {
"type": "number"
},
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"status": {
"type": "string"
},
"type": {
"type": "string"
},
"routePlanId": {
"type": "string"
},
"currencyId": {
"type": "string"
},
"autoRateUpdateActive": {
"type": "boolean"
}
}
}
}
使用以下代码进行验证:
{ statusCode: 2006,
statusPhrase: 'Error: ORA-00001: unique constraint (SPHERE_D1.CHECK_UNIQUE_RATE_NAME) violated\nORA-06512: at "SPHERE_D1.PKG_RATE_TABLES_V2", line 102\nORA-06512: at "SPHERE_D1.PKG_RATE_TABLES_V2", line 54\nORA-06512: at line 1' }
AJV应该返回错误,因为架构和响应不同,但是AJV返回“无错误”。 代码有什么问题吗?
答案 0 :(得分:0)
这可以通过在架构定义中添加必需的字段来解决。
{
"$id": "create-offer.json#",
"description": "",
"title": "",
"type": "object",
"required": [
/*mention objects which should be requird*/
]
}