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 uses only last sub schema. #174

Closed
TheGame2500 opened this issue Aug 23, 2017 · 1 comment
Closed

SimpleSchema.oneOf uses only last sub schema. #174

TheGame2500 opened this issue Aug 23, 2017 · 1 comment

Comments

@TheGame2500
Copy link

Tried using SimpleSchema.oneOf with sub schemas (I know, bad idea considering the kindly written note that it's experimental).

It seems like it's only using the last schema fed in for validation, as can be seen with the following snippets :

Snippet 1 :

var sampleSchema = new SimpleSchema({
	property : SimpleSchema.oneOf(
	new SimpleSchema({
		subProperty : String,
	}),
	new SimpleSchema({
		subProperty : Number,
	}))
})

sampleSchema.validate({
	property : {
		subProperty : 1,
	}
}) // OK

sampleSchema.validate({
	property : {
		subProperty : 'stringy string',
	}
}) // ClientError: Sub property must be of type Number

Snippet 2 :

var sampleSchema = new SimpleSchema({
	property : SimpleSchema.oneOf(
	new SimpleSchema({
		subProperty : Number,
	}),
	new SimpleSchema({
		subProperty : String,
	}))
})

sampleSchema.validate({
	property : {
		subProperty : 'stringy string',
	}
})

sampleSchema.validate({
	property : {
		subProperty : 1,
	}
}) // ClientError: Sub property must be of type String
@TheGame2500
Copy link
Author

TheGame2500 commented Aug 30, 2017

Duplicates #112

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

No branches or pull requests

1 participant