oneOf inside another oneOf
See original GitHub issueI’m getting this error:
Cannot match against ‘undefined’ or ‘null’. (from /express-validator/check/select-fields.js:71:33)
When using a oneOf inside another one. Like this:
oneOf([
[
check('role').equals('student'),
check('student.school.id', 'Invalid student.school.id.').isInt(),
], [
check('role').equals('teacher'),
check('teacher.school.id', 'Invalid teacher.school.id.').isInt(),
oneOf([
[
check('teacher.classes').exists(),
check('teacher.classes.*.id', 'Invalid teacher.classes.*.id').isInt(),
],
[/* Do nothing (no classes found) */]
])
]
])
If a remove the oneOf within the parent one, it works. Maybe I’m doing something wrong? I just want to check the classes (array of objects) in case they are found.
I’m using version 4.3.0.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
OneOf, nested inside of another OneOf is not shown...
Hello,. I am developing a Spring app with OpenApi. For open API spec (schema.txt) java code is generated by the maven code generator...
Read more >oneOf, anyOf, allOf, not - Swagger
Use the oneOf keyword to ensure the given data is valid against one of the specified schemas. ... The example above shows how...
Read more >yaml - using oneOf with shared elements in a property object
oneOf inside properties results in a property with that name to be expected. But since you don't want a oneOf property, you'd have...
Read more >oneOf rendered as pulldown in API Reference
Our OAS has "oneOf" objects specified in component schemas, similar to the example below. Although they render correctly in Swagger Editor, ...
Read more >How to properly use oneOf and anyOf in Rest Schema?
Thank you Sally. So for the oneOf its not about the propertie's keys, but propertie's schema? Because my schema have different properties inside...
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
Right. There’s no difference between the 2 snippets, they work exactly the same.
Anyway, a new major release is coming soon, and conditional validation will be available in the package.
Ok, then I’ll stick with V3 as it handles this kind of situation easily.