SimpleSchema.oneOf Issue (simple example included)
See original GitHub issueBelow is the example case.
One case has type: FirstSchema
The other case has type: SimpleSchema.oneOf(String, Number, FirstSchema, ZeroSchema)
Given the second case contains the first case within oneOf
, it should work.
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, // Comment the below and un-comment this to switch cases
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.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:12
- Comments:22
Top Results From Across the Web
SimpleSchema.oneOf Issue (simple example included) #112
Below is the example case. One case has type: FirstSchema. The other case has type: SimpleSchema.oneOf(String, Number, FirstSchema, ZeroSchema)
Read more >Developers - SimpleSchema.oneOf Issue (simple example included) -
Below is the example case. One case has type: FirstSchema. The other case has type: SimpleSchema.oneOf(String, Number, FirstSchema, ZeroSchema)
Read more >aldeed:simple-schema - Packosphere
SimpleSchema. aldeed:simple-schema. A simple, reactive schema validation package for Meteor. It's used by the Collection2 and AutoForm packages, ...
Read more >python - JSON Schema oneOf Validation Issue - Stack Overflow
I have created a very simple schema using "oneOf" and a simple JSON file to demonstrate the issue. JSON Schema:
Read more >How to combine TypeScript and SimpleSchema? - community
github.com/aldeed/meteor-simple-schema · Issue: Use with typescript? ... 2 Likes. Typescript - replace SimpleSchema or use alongside it?
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve done some work on this, but it’s a substantial rewrite to the validation flow. Hopefully will have a solution.
Hello @aldeed , if you add the “Help Wanted” flag again, I’ll feel more comfortable working on a pull request. Again, I don’t want to interfere if you’re already working on it. Or, is there anyone else who’s familiar with the internals of the package? It might take me longer, since I’m not, but I’m willing to go ahead with it because this is so important.