Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4 bug: select doesn't work with boolean #150

Closed
kpkonghk01 opened this issue Jan 7, 2021 · 1 comment
Closed

v4 bug: select doesn't work with boolean #150

kpkonghk01 opened this issue Jan 7, 2021 · 1 comment
Labels

Comments

@kpkonghk01
Copy link

kpkonghk01 commented Jan 7, 2021

Before I upgrade ajv form 6 to 7, ajv-keywords from 3 to 4

this worked:

const { default: Ajv } = require('ajv');

const validator = new Ajv({
  $data: true,
  useDefaults: true,
  coerceTypes: true,
  allErrors: true,
});

require('ajv-keywords')(validator, 'select');

const schema = {
  type: 'object',
  properties: {
    cond: {
      type: 'object',
      properties: {
        enabled: {
          type: 'boolean',
        },
      },
      select: {
        $data: '0/enabled',
        someString: {
          type: 'string',
        },
      },
      selectCases: {
        true: {
          required: ['someString', 'someNum'],
          properties: {
            someNum: {
              type: 'number',
            },
          },
        },
      },
    },
  },
};

validator.validate(schema, {
  cond: {
    enabled: true,
  },
});

// Can check the required fields
console.log(validator.errors);

and now it doesn't work unless I change the type of enabled to string which is unexpected

@kpkonghk01
Copy link
Author

Hello, any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants