-
Notifications
You must be signed in to change notification settings - Fork 50
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
Validating top-level arrays #62
Comments
It's not really designed to work with top-level arrays, but a PR is welcome. I don't think there's a lot that needs to be done for it to work. |
Yeah I dug around a bit and found that the reliance on having a "path" for each prop is what stops this from working as I hoped it would. I believe I would have encountered the same problem if I would try to make a schema that represents just a number or just a boolean or anything really that isn't an object at the top level. |
+1 |
If you wanted to define a fixed width array, you could do it like this: const myArraySchema = new Schema([
{
type: String,
required: true
}, {
type: Number,
required: true
}, {
type: undefined,
}
]);
const myValidArray = ['hi', 1];
console.log('myValidArray', myArraySchema.validate(myValidArray)); Of course it would be best to just add the ability to create a schema with just an array or just a type. |
I have been trying to write a schema that validates the properties of an array without much luck. Here is what I am trying:
Is there a trick that I'm missing?
The text was updated successfully, but these errors were encountered: