ajv-keywords icon indicating copy to clipboard operation
ajv-keywords copied to clipboard

`select` errors have no `dataPath`

Open victorandree opened this issue 8 years ago • 3 comments

TypeScript input:

import * as Ajv from 'ajv';
import * as AjvKeywords from 'ajv-keywords';

const ajv = new Ajv({
  $data: true,
  messages: true,
  verbose: true,
  allErrors: true
});

AjvKeywords(ajv);

const schema = {
  type: 'object',
  properties: {
    Fee: {
      select: { $data: '1/Type' },
      selectCases: {
        TYPE1: { maximum: 100 },
        TYPE2: { maximum: 200 }
      },
      type: 'number'
    },
    Type: {
      type: 'string'
    }
  }
};

const validate = ajv.compile(schema);
const valid = validate({
  Type: 'TYPE1',
  Fee: 150
});

if (!valid) {
  console.log(validate.errors);
}

Output:

[ { keyword: 'maximum',
    dataPath: '',
    schemaPath: '#/properties/Fee/select',
    params: { comparison: '<=', limit: 100, exclusive: undefined },
    message: 'should be <= 100',
    schema: 'TYPE1',
    parentSchema: { maximum: 100 },
    data: 150 } ]

I would expect dataPath to be .Fee but it's empty.

"dependencies": {
    "ajv": "^5.0.4-beta",
    "ajv-keywords": "2.0.1-beta.2"
  }

victorandree avatar Apr 11 '17 10:04 victorandree

https://runkit.com/esp/58f244ff90f8c30014c36698

epoberezkin avatar Apr 15 '17 16:04 epoberezkin

Same goes for "deepRequired" it seems..

koenfaro90 avatar May 11 '17 13:05 koenfaro90

Hello, I think https://github.com/ajv-validator/ajv-keywords/pull/54#issuecomment-685903741 is related to this issue. Please let me know if I am mistaken and I will delete this comment.

Thank you !

vedant15 avatar Sep 02 '20 18:09 vedant15

Per the README, select is deprecated. I doubt this will be fixed. As the author of the issue, I'm closing it.

victorandree avatar May 22 '23 08:05 victorandree