0

I find it very hard to work with the error message from Ajv when using notin my schema. In my use case, I want to validate two props not being of the same value. Consider this example:

schema.json

{
  "$schema": "http://json-schema.org/draft-06/schema",
  "properties": {
    "propA": {
      "type": "string"
    },
    "propB": {
      "type": "string",
      "not": {
        "const": {
          "$data": "1/propA"
        }
      }
    }
  }
}

data

{ propA: 'foo', propB: 'foo' }

output

[ { keyword: 'not',
    dataPath: '.propB',
    schemaPath: '#/properties/propB/not',
    params: {},
    message: 'should NOT be valid' } ]

The error message tells me that not is rejected, but the really relevant information would be that const was not satisfied.

Does anyone have a hint or workaround how I can get a meaningful error message for this use case?

Jakob Hohlfeld
  • 1,503
  • 1
  • 17
  • 31

1 Answers1

1

"const" actually was satisfied, and that's why "not" failed. The error object contains paths in data and in schema and with "verbose" option it would contain references to both data and schema that caused the failure; from these you should be able to interpret the error.

esp
  • 7,314
  • 6
  • 49
  • 79
  • `verbose` is outputting so much data, it's actually too verbose for my tests. I did it with the custom error messages plugin (`npm ajv-errors`). – Jakob Hohlfeld Sep 25 '17 at 15:12
  • I also think that ajv errors are borderline unusable. @esp has made the claim over and over that one can "interpret" the error, find the information, but the structure is so chaotic, so randomly structured, objects and array popping up all over the place without any kind of information on why and how, we have no way to know what to expect and how to parse it. – Ashnur Jul 18 '18 at 16:14