So I'm using Simple-Schema/Collection2, and I thought my schema definitions were fine, as they caught malformed fields, and records inserted succesfully when properly formed.
However, I'm trying to run MySchemas.Schema.validate(document)
and running into a validation error inside of a chai expect()
block
Error: expected [Function] to not throw 'Error' but 'ClientError: fieldOne.fieldTwo.0 is not allowed by the schema' was thrown
The fields are failing on a subschema. The actual document is complicated, but here is the relevant skeleton.
const testSchema = new SimpleSchema({
fieldOne: {
...,
...,
fieldOne.fieldTwo: {
type: subSchema,
},
...,
});
const subSchema = new SimpleSchema({
fieldTwo: {
type: Array,
},
"fieldTwo.$": {
type: Object,
}
"fieldTwo.$.foo": {
type: String,
},
....,
};
Example Object:
{ fieldOne: {
fieldTwo: [
{ foo: "bar"},
{ foo: "bar"},]
}
}
Essentially, I have a subschema for an array of objects with some fields. The record inserts perfectly well, without returning an error, and is properly formatted, but it fails validation. Any idea why?