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

removeAdditional should only remove properties if the schema is valid #552

Closed
sberan opened this issue Aug 25, 2017 · 1 comment
Closed

Comments

@sberan
Copy link

sberan commented Aug 25, 2017

For the following schema, validation fails when removeAdditional is used. The issue is that the property b is removed when testing the first schema, and then the validation of the second schema fails because b no longer exists on the object. I propose that removeAdditional would only mutate the data if it passes validation. Thoughts?

const Ajv = require('ajv')
const ajv = new Ajv({ allErrors: true, removeAdditional: true  })
const validate = ajv.compile({
  oneOf: [{
    properties: {
      a: { type: 'string' }
    },
    additionalProperties: false
  },{
    properties: {
      b: { type: 'string' }
    },
    additionalProperties: false
  }]
})
const data = { b: 'foo' }
console.log(validate(data)) // false
console.log(validate.errors[0].message) //  'should match exactly one schema in oneOf'
console.log(data) // {}
@epoberezkin
Copy link
Member

@sberan It's a duplicate of #129 and many other similar issues.

Please review them and if you have something to add, comment there.

Also see FAQ.

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

No branches or pull requests

2 participants