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

DefaultValue not working #16

Open
safiresh opened this issue Oct 31, 2017 · 1 comment
Open

DefaultValue not working #16

safiresh opened this issue Oct 31, 2017 · 1 comment

Comments

@safiresh
Copy link

const Ajv = require('ajv');
const ajv = new Ajv({
  allErrors: true,
  format: 'full',
  useDefaults: true,
  coerceTypes: false,
  errorDataPath: 'property',
  sourceCode: false,
});
require('ajv-merge-patch')(ajv);
const base = {
  type: 'object',
  properties: {
    operation: {
      type: 'string',
      enum: ['create', 'update', 'delete'],
    },
    id: {
      type: 'string',
    },
  },
};

const schema = {
  $merge: {
    source: base,
    with: {
      type: 'object',
      properties: {
        test: {
          type: 'integer',
          default: 0,
        },
      },
    }
  }
};

const params = {
  operation: 'delete'
};
const validate = ajv.compile(schema);
const isValidParams = validate(params);
console.log(params);

Actual :
{ operation: 'delete' }
Expected :
{ operation: 'delete' , test: 0}

@nick4fake
Copy link

@epoberezkin are there any workarounds for it? So far even defining default in "with" is simply ignored.

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

No branches or pull requests

3 participants