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

filter() constructor doesn't seem to show errors. #44

Open
dkran opened this issue Mar 14, 2015 · 3 comments
Open

filter() constructor doesn't seem to show errors. #44

dkran opened this issue Mar 14, 2015 · 3 comments

Comments

@dkran
Copy link

dkran commented Mar 14, 2015

I have a small validator written as such:

var vState = validator.filter({
  required: true,
  type: 'object',
  properties: {
    state_iso: {
      required: true,
      type: 'string'
    },
    state_name: {
      required: true,
      type: 'string'
    },
    fips_code: {
      required: false,
      type: 'number'
    }
  },
  additionalProperties: false
});

Long story short, if I take off the .filter, it will throw errors if I take off required fields and the like, but also throw errors on fields that need to be stripped. if I put filter on, it seems the validator won't pass, but the errors array is always undefined.
simple route logic right now just to test this is:

console.log(req.body)
  vState(req.body)
  console.log(req.body)
  console.log(vState.errors)
  res.end()

my actual code is commented out

@jonasfj
Copy link

jonasfj commented Mar 29, 2015

I've run into the same issue... It's a problem with the generated code giving options {filter: true} to validator doesn't work either. Ie. validator(schema, {filter: true, verbose: true}), it just ignores any type errors.

As a temporary work around I'm doing:

var validator = require('is-my-json-valid')
var filter    = validator.filter(schema);
var validate  = validator(schema, {
  verbose:    true,
  greedy:     true
});

var filterAndValidate = function(data) {
  filter(data);
  validate(data);
  console.log(validate.errors);
};

It's obviously slower, so not a fix... Just including it as context.

@dkran
Copy link
Author

dkran commented Mar 31, 2015

I have something similar going on as a workaround. I also started poking around at the imjv source to see if I could trace it back, but it's a bit confusing to me.

jonasfj added a commit to jonasfj/is-my-json-valid that referenced this issue Apr 13, 2015
  * Make errors available when using this feature
  * Ignore errors from `additionalProperties: false`
  * Formalize semantics in `README.md`
  * Warn about input mutation.
  * Warn that this is a non-standard feature.
  * Added test cases covering the `filter` feature
@dkran
Copy link
Author

dkran commented May 2, 2015

I wish this was getting a little attention here.

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

No branches or pull requests

2 participants