question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SimpleSchema.oneOf Issue (simple example included)

See original GitHub issue

Below 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:closed
  • Created 6 years ago
  • Reactions:12
  • Comments:22

github_iconTop GitHub Comments

5reactions
aldeedcommented, Dec 28, 2017

I’ve done some work on this, but it’s a substantial rewrite to the validation flow. Hopefully will have a solution.

2reactions
chrisbobbecommented, May 21, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found