Below is the example case. If I un-comment type: FirstSchema and comment out the next line, no error is produced. Thus: when the type is specifically FirstSchema there is not error but if the type is oneOf a list that includes FirstSchema, an error is produced, which is not the intent of oneOf (unless my understanding is mistaken). Shouldn't oneOf test for String, then Number, then FirstSchema, and pass once it tests FirstSchema to be a match?
// Import
import SimpleSchema from 'simpl-schema';
// Instantiate
Test = new Mongo.Collection('test');
// Define Schema
ZeroSchema = new SimpleSchema({
zeroAlpha: Number,
zeroBravo: Number
});
FirstSchema = new SimpleSchema({
firstAlpha: String,
firstBravo: String
});
SecondSchema = new SimpleSchema({
secondAlpha: String,
secondBravo: {
//type: FirstSchema,
type: SimpleSchema.oneOf(String, Number, FirstSchema, ZeroSchema)
}
});
// Attach Schema
Test.attachSchema(SecondSchema);
// Sample Data
myData = {
secondAlpha: "test",
secondBravo: {
firstAlpha: "test",
firstBravo: "test"
}
};
Test.insert(myData); // Error: secondBravo.firstAlpha is not allowed by the schema
Also interesting note: if I do type: SimpleSchema.oneOf(String, Number, FirstSchema), i.e., remove the ZeroSchema part, it validates/inserts successfully.
Below is the example case. If I un-comment
type: FirstSchema
and comment out the next line, no error is produced. Thus: when the type is specificallyFirstSchema
there is not error but if the type is oneOf a list that includes FirstSchema, an error is produced, which is not the intent of oneOf (unless my understanding is mistaken). Shouldn't oneOf test for String, then Number, then FirstSchema, and pass once it tests FirstSchema to be a match?Also interesting note: if I do
type: SimpleSchema.oneOf(String, Number, FirstSchema)
, i.e., remove theZeroSchema
part, it validates/inserts successfully.