-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
fix oneOf #431
fix oneOf #431
Conversation
I just realised this will fall over on modifiers :'( |
@znewsham Welcome to the complexity of SimpleSchema! Thanks for giving it a shot. This looks like a good start. I will do some careful review and see if we can get it through. |
@aldeed Ha! Yes, I've been "hacking" around this bug for a while in my project, thought I'd give it a go. These changes + one other change that probably doesn't make sense to be in the class (a function that specifies WHICH schema defined by It's currently in use on a fairly complicated project involving nested, schemas that change based on fields within the document - so I'm relatively sure this is going to work in the majority of cases! |
@znewsham An option to narrow the accepted one-ofs at validation time sounds interesting. It should be a separate future PR, but seems like something others would benefit from. |
closed in favour of #435 - this PR was against my main branch, which causes trouble. |
This ended up being quite a lot larger than I initially planned. Initially it looked like it was going to be fairly simple, but alas not. All tests are passing and I added a handful of others.
I believe this fixes #428 and #410
There are a few small changes that look large, and a couple of actual large ones:
checkObj
- move everything after thevalidate
call into a new function calledrecurse
- this is called bycheckObj
in the case that we don't want to validate a key (or initially when we dont have a key) but also byvalidate
which may also change the "schema" used from the root schema to the current branch schema.def.type.some
completes with multiple options. At which point it either discards the entire array (in the case of a pass) or continues to concat.subSchema
subSchemaAffectedKey
andsubSchemaAffectedKeyGeneric
(sometimes) are now additionally passed around - these represent the current sub schema and the affected key relative to the sub schemaaffectedKey
andaffectedKeyGeneric
refer to the current key relative to the root schema.oneOfKeys()
andrecursiveKeys()
functions to accumulate all keys in a schema (including child schemas) and those that are inside of aoneOf
.checkModifier
to check if a key is inside aoneOf
and if so run the check against each subSchemaThanks for providing such a vast library of test cases - it made implementing this very safe. I'm going to include this in my project where I've been hacking around this limitation for ages, and will ensure that all my schemas work, as I make heavy use of
oneOf(schema1, schema2, ...)