简体   繁体   中英

AJV is not validating my schema

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 ?

This is resolved by adding required feilds in schema definition.

{
    "$id": "create-offer.json#",
    "description": "",
    "title": "",
    "type": "object",
    "required": [
        /*mention objects which should be requird*/
    ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM