Error using Joi.forbidden in conditional '.when'
See original GitHub issueContext
- 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:
- Created 6 years ago
- Reactions:7
- Comments:6
Top 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 >
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 Free
Top 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
@robmcguinness it’s aligned with what other PR’s https://github.com/glennjones/hapi-swagger/issues/338 the PR would have been in here https://github.com/glennjones/hapi-swagger/pull/428/files#diff-327455fa29663c58312adf5955056773R496
However, it was commented out when got merged in https://github.com/glennjones/hapi-swagger/blame/2edaebb6793ac52527cea42e5e57c00693f60168/lib/properties.js#L517 now still left commented out https://github.com/glennjones/hapi-swagger/blob/master/lib/properties.js#L516
May you take a look please? Thanks
There are plenty of PRs for this issue. Let’s fix it, please? @glennjones