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.

oneOf schema? [question]

See original GitHub issue

How 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:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
cb109commented, May 29, 2019

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() and yup.mixed().test(): https://gist.github.com/cb109/8eda798a4179dc21e46922a5fbb98be6

If you feel like there is a better way to tackle this please let me know, thanks.

1reaction
jquensecommented, Nov 27, 2018

You want to use lazy

Read more comments on GitHub >

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

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