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 inside another oneOf

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
gustavohenkecommented, Jan 24, 2018

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.

1reaction
emipccommented, Jan 24, 2018

Ok, then I’ll stick with V3 as it handles this kind of situation easily.

Read more comments on GitHub >

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

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