Skip to content
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

SimpleSchema.oneOf Issue (simple example included) #112

Closed
zjzeit opened this issue May 4, 2017 · 22 comments
Closed

SimpleSchema.oneOf Issue (simple example included) #112

zjzeit opened this issue May 4, 2017 · 22 comments

Comments

@zjzeit
Copy link

zjzeit commented May 4, 2017

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.

@williamtetlow
Copy link

Is there any news on this bug? I can confirm I'm having a similar issue, simple example:

const schemaOne = new SimpleSchema({
  itemRef: String,
  partNo: String,
});

const schemaTwo = new SimpleSchema({
  anotherIdentifier: String,
  partNo: String,
});

const combinedSchema = new SimpleSchema({
  item: SimpleSchema.oneOf(schemaOne, schemaTwo),
});

Test.attachSchema(combinedSchema);

Test.insert({ itemRef: 'hhh', partNo: 'ttt' }); // Error: item.itemRef is not allowed by the schema

I don't mind helping submit a PR to fix this? Multiple schemas is going to make this package really powerful!

@TheGame2500
Copy link

@williamtetlow if you've got the time and the knowledge to do this, can you please go ahead and do it, as the issue's labeled with 'help wanted' ? Otherwise, I'll do it, but I'm not that familiar with the library's internals, so it would take longer.

@pilarArr
Copy link

pilarArr commented Sep 8, 2017

I've run on this issue too.

@zjzeit I found out that the last schema you put in the .oneOf() list is the one that prevails.
Any other insert or validation for the other schemas do not work.

Any new on this? @TheGame2500 did you manage to fix it?

@TheGame2500
Copy link

@pilarArr no. I was waiting on @williamtetlow to reply.

@williamtetlow
Copy link

williamtetlow commented Sep 12, 2017

@TheGame2500 Sorry been away on holiday. Yep I'll take a look at this over the next couple of days. From a quick scan of the code it doesn't look too difficult to fix.

@SnooHD
Copy link

SnooHD commented Nov 5, 2017

Also ran into this issue, any progress? :)
For now i'm just skipping the object with blackbox: true.. but i would prefer not to.

@blueyestar
Copy link

I have same problem.

@ejfrancis
Copy link

+1 still a problem

@aldeed
Copy link
Collaborator

aldeed commented 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.

@KG32
Copy link

KG32 commented Mar 25, 2018

+1

mutaphysis added a commit to sozialhelden/a11yjson that referenced this issue Jun 6, 2018
- SimpleSchema.oneOf does not work
- we can either have strings or objects, not both
- see longshotlabs/simpl-schema#112
@chrisbobbe
Copy link

Thanks for this useful package! Is help needed on this issue @aldeed ? I can see if I can put together a pull request, but I don't want to interfere if you have a substantial rewrite in progress.

@conorstrejcek
Copy link

We have a strong use-case for defining multiple schemas for a collection. Without full oneOf support, we are not able to validate more than one complex schema on a collection. Are there any plans to add support for nested Schemas within oneOf, and if not, would that be a welcome pull request?

@chrisbobbe
Copy link

Hi again, just checking in to see if there might be a solution in progress, or if you'd be interested in a pull request to fix this issue.

@chrisbobbe
Copy link

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.

@gerwinbrunner
Copy link

Is there any progress on this issue?

@gerwinbrunner
Copy link

Any news?

@Roshdy
Copy link

Roshdy commented Nov 10, 2019

So after 2 years and a half...now what? :D

@DrewHoo
Copy link

DrewHoo commented Dec 18, 2019

Yep, just hit this, would love to see a fix.

@aldeed
Copy link
Collaborator

aldeed commented Mar 24, 2020

Wow, needless to say this issue dropped off my radar. I really don't remember anything about what I was working on except that it was complicated to fix. I may have even given up trying but forgot to post here. Sorry, but if anyone can fix it without breaking any other tests, please submit a PR.

@baileywall
Copy link

any chance the above fix for this ^ is going to make it into the next release?

@weljoda
Copy link

weljoda commented Aug 20, 2022

Still facing the same Problem

@aldeed aldeed closed this as completed in e8f91dc Dec 11, 2022
@github-actions
Copy link

🎉 This issue has been resolved in version 3.3.0 🎉

The release is available on:

If this makes you happy, please consider becoming a sponsor.

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests