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.

Error using Joi.forbidden in conditional '.when'

See original GitHub issue

Context

  • hapi-swgger version: all versions
  • any other relevant information: Joi schemas

What are you trying to achieve or the steps to reproduce ?

At the moment, hapi-swagger is not able to resolve Joi.forbidden with .when, see the following JOI schema example:

const Joi = require('joi');
const payloadValidation = Joi.object({
 a: Joi.string()
    .when('b', {
       is: Joi.exist(),
       then: Joi.forbidden()      // specifying Joi.forbidden() is resulting error here :(
    }), 
 b: Joi.string()
});

What result did you get?

Debug: internal, implementation, error
    TypeError: Uncaught error: Cannot set property 'x-alternatives' of undefined
    at module.exports.internals.properties.internals.properties.parseAlternatives (.../node_modules/hapi-swagger/lib/properties.js:529:40)
    at module.exports.internals.properties.internals.properties.parseProperty (.../node_modules/hapi-swagger/lib/properties.js:185:25)
    at joiObj.forEach (.../node_modules/hapi-swagger/lib/properties.js:391:45)
    at Array.forEach (<anonymous>)
    at module.exports.internals.properties.internals.properties.parseObject (.../node_modules/hapi-swagger/lib/properties.js:381:12)
    at module.exports.internals.properties.internals.properties.parseProperty (.../node_modules/hapi-swagger/lib/properties.js:144:29)
    at module.exports.internals.paths.internals.paths.getSwaggerStructures (.../node_modules/hapi-swagger/lib/paths.js:459:41)
    at routes.forEach (.../node_modules/hapi-swagger/lib/paths.js:217:38)
    at Array.forEach (<anonymous>)
    at module.exports.internals.paths.internals.paths.buildRoutes (.../node_modules/hapi-swagger/lib/paths.js:179:12)

What did you expect ?

It should not throw error, and able to resolve and see hapi swagger in (for example) localhost:3000/docs

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:6

github_iconTop GitHub Comments

1reaction
Y-LyN-10commented, Sep 12, 2018

There are plenty of PRs for this issue. Let’s fix it, please? @glennjones

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error using Joi.forbidden in conditional '.when' #469 - GitHub
At the moment, hapi-swagger is not able to resolve Joi.forbidden with .when , see the following JOI schema example: const Joi ...
Read more >
Joi Validation - Field is not required when the condition is not ...
I tried using strict() after the field and in the top level but nothing is working. is there any way to achieve that?...
Read more >
Joi: checking against multiple values in `conditional()`
If a is included in array , b is a required string; otherwise b is forbidden. Solution to the array problem. We need...
Read more >
17.7.0 API Reference - joi.dev
The joi API. ... joi lets you describe your data using a simple, intuitive, and readable ... If the input is valid, then...
Read more >
Using Joi for JavaScript Model Validation | Portfolio
One way is to use a model validator like Joi, which can take a defined schema with types explicitly declared, and validate a...
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