oneOf schema? [question]
See original GitHub issueHow to write correctly following pseudocode?:
let mySchema = yup.object().shape({
language: yup.mixed().oneOf([yup.string(), yup.array().of(yup.string())]).required()
});
So both objects should be correct:
{ language: 'en' }
{ language: ['en', 'de']}
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
JSON Schema "oneOf" each?
Is it possible to make a JSON Schema which validates that an array ... I can't use oneOf because, again, I can have...
Read more >How to properly use oneOf and anyOf in Rest Schema?
Hmmm strange - that looks like a valid use of oneOf to me. The only weird bit I see across the whole schema...
Read more >Multiple JSON Schemas with *oneOf* - M100
Here oneOf is a keyword construct in the JSON Schema, which is used to provide an array of criteria where, if exactly one...
Read more >Solved: schema via oneOf with additional common properties
schema via oneOf with additional common properties ... Did my reply answer your question? Give Kudos or Accept it as a Solution to...
Read more >Understanding JSON Schema
own car—er, writing their own JSON Schema validator—just yet. ... oneOf (page 57): (XOR) Must be valid against exactly one of the subschemas....
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 came across this while trying to validate that array items are of one of multiple allowed shapes/schemas. I solved it writing a custom method making use of
yup.addMethod()
andyup.mixed().test()
: https://gist.github.com/cb109/8eda798a4179dc21e46922a5fbb98be6If you feel like there is a better way to tackle this please let me know, thanks.
You want to use
lazy