@hapi/validate schemas in the context of hapi-swagger use
- Dominant language
- JavaScript
- Stars
- 14.8k
- Forks
- 1.4k
- Avg merge
- 22d 3h
- Merged PRs (30d)
- 1
Description
#### Support plan
* *is this issue currently blocking your project?* (yes/no): no
* *is this issue affecting a production system?* (yes/no): no
#### Context
* *node version*: 14.16.0
* *module version*: 20.1.0
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): hapi-swagger@14.1.0
* *any other relevant information*:
#### How can we help?
I'm starting an issue here, but I don't really know if it's up to hapi or hapi-swagger to fix the issue, I'd say hapi, but you may disagree.
There is currently an error thrown from hapi-swagger that looks like this:
```
Error: Cannot mix different versions of joi schemas
at new module.exports (./node_modules/@hapi/hoek/lib/error.js:23:19)
at module.exports (./node_modules/@hapi/hoek/lib/assert.js:20:11)
at Object.exports.isSchema (./node_modules/joi/lib/common.js:132:5)
at Object.utilities.isJoi (./node_modules/hapi-swagger/lib/utilities.js:236:24)
at Object.utilities.hasJoiChildren (./node_modules/hapi-swagger/lib/utilities.js:246:19)
at ./node_modules/hapi-swagger/lib/paths.js:291:21
[...]
```
The root cause is coming from [this line](https://github.com/hapijs/hapi/blob/bae179241e756f45ffee85184782c06cb3cbc4fa/lib/validation.js#L27). When hapi-swagger is checking that all the schemas are joi objects, this one is not, so the throw is totally expected.
Now I see 2 solutions to that :
- use the validator to create that schema so that it uses the correct joi version, but it doesn't seem easy to add the `allow(null)` part if we're not sure that we're getting a joi object back from the validator
- keep the false as it is and do some special treatment during the validation, but it has imho one major drawback, it's going to be hard to throw joi-compatible errors, which could cause some problems for people catching errors in failAction or any other hook
What do you think?
Contributor guide
Assessment
This issue has not been assessed yet.