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

Array + Stripping + Required returns unexpected errors #55

Open
doomfalc opened this issue Jun 15, 2018 · 1 comment
Open

Array + Stripping + Required returns unexpected errors #55

doomfalc opened this issue Jun 15, 2018 · 1 comment

Comments

@doomfalc
Copy link

Consider the following example:

const Schema = require("validate")

const input = [{
    prop1: "value1",
    prop2: "value2"
}]

const schema = new Schema([{
    prop1: { required: true }
}]);

console.log("Before validation (no stripping)", input);
const errors = schema.validate(input, { strip: false });
console.log("Errors (no stripping)", errors);
console.log("After validation (no stripping)", input);

console.log("\r\nBefore validation (with stripping)", input);
const moreErrors = schema.validate(input, { strip: true });
console.log("Errors (with stripping)", moreErrors);
console.log("After validation (with stripping)", input);

Yields the following output:

Before validation (no stripping) [ { prop1: 'value1', prop2: 'value2' } ]
Errors (no stripping) []
After validation (no stripping) [ { prop1: 'value1', prop2: 'value2' } ]

Before validation (with stripping) [ { prop1: 'value1', prop2: 'value2' } ]
Errors (with stripping) [ Error: 0.prop1 is required.
... StackTrace...
After validation (with stripping) [ {} ]

Whether stripping is enabled or not, we should expect validate to return the same errors (or lack thereof).

@eivindfjeldstad
Copy link
Owner

This library is not really designed to work with top level arrays. There are no tests for this use case, so bugs are sort of expected. I'm not opposed to adding this functionality though

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

No branches or pull requests

2 participants