0

I am facing problem regarding AJV Schema Validator. I have following schema

{
    "$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"
            }
        }
    }
}

And my response is :

{ 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' }

Using the following code to validate :

let valid = ajv.validate(schema, res);
var detailedErrorMsg = "\n" + ajv.errorsText(ajv.errors, { separator: "\n" }) + "\n";
console.log(detailedErrorMsg);

AJV should return error as schema and response are different, but AJV is returning 'no errors'. Is there any problem with the code ?

4

1 回答 1

0

这可以通过在模式定义中添加所需的字段来解决。

{
    "$id": "create-offer.json#",
    "description": "",
    "title": "",
    "type": "object",
    "required": [
        /*mention objects which should be requird*/
    ]
}
于 2018-08-08T08:01:24.373 回答