Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update needed to support new version of Hapi and Joi #163

Open
rmothilal opened this issue Oct 10, 2019 · 10 comments
Open

Update needed to support new version of Hapi and Joi #163

rmothilal opened this issue Oct 10, 2019 · 10 comments

Comments

@rmothilal
Copy link

Hapi and Joi have had a massive refactor of their libraries hapijs/joi#2037 hapi-openapi relies on this library to validate a swagger. The enjoi library also needs an update to use these latest libraries so that the hapi-openapi can operate correctly. My project has a dependency on this library and we would really appreciate any assistance with this matter

@edward-whittle
Copy link
Contributor

I'm getting an error when trying to render the /documentation endpoint due to the Joi versioning:
Debug: internal, implementation, error Error: Cannot mix different versions of joi schemas

All of the packages in my project use Joi 16.x.x, where hapi-openapi uses 13.x.x which I believe is causing the error
"hapi-openapi": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/hapi-openapi/-/hapi-openapi-1.2.6.tgz", "integrity": "sha512-8YP3pInoUAb8yYpPmKgfdbv7kGntrWbpaAjS4Hr7zr8uf2kiadhdR4AdBj9dXJNmgmkHApKFEGMOPWWFwC/1uA==", "requires": { "dot-prop": "^4.2.0", "enjoi": "^4.0.0", "hoek": "^5.0.3", "joi": "^13.6.0", "js-yaml": "^3.11.0", "merge-object-files": "^2.0.0", "swagger-parser": "^4.1.0" }

@rmothilal
Copy link
Author

Hi @edward-whittle there is a new version release. Can you confirm if this fixed your issue

@rodoabad
Copy link

rodoabad commented May 7, 2020

@rmothilal anyway to disable joi validation?

@ajbowler
Copy link

ajbowler commented May 7, 2020

Here's an issue that we've run into since upgrading.

Context

We use this plugin in a large "mock" API server that abstracts away our actual API so frontend development can work without depending on services being available. All of the endpoints we design using this plugin mirror the actual service endpoints used in production today, with mock JSON returned/mock errors thrown/other real world scenarios mocked.

Issue

Since upgrading, many of our defined endpoints with request bodies are failing Joi validation on objects being passed with empty strings, due to the nature of how our frontends have been implemented. By default, Joi does not allow empty strings, you have to explicitly .allow('') and since this plugin hides the underlying Joi validation on the transformed Swagger request bodies, we have no workaround. Changing our frontend app implementations for this isn't the right answer since they're already used in production and work as intended with actual services.

We discovered this problem yesterday and it's going to affect multiple teams of developers, so a quick fix is greatly desired.

Potential Solutions

  • Have this plugin provide a top-level field that tags an .allow('') to all request body fields
  • Have this plugin provide a top-level field that can toggle Joi validation completely

@ajbowler
Copy link

ajbowler commented May 9, 2020

I'd be happy to open a PR for this one if the Kraken team can provide some guidance on the right approach, so I don't go against standards.

@rmothilal
Copy link
Author

@tlivings thanks for bringing the changes from the enjoi library and @sprootshift for the additions required to cater for updated versions of Hapi and Joi

@rmothilal
Copy link
Author

@edward-whittle there is a new library released could you please let me know if your issues are resolved

@rmothilal
Copy link
Author

@rmothilal anyway to disable joi validation?

@rodoabad im not sure that is possible maybe @tlivings would be able to give a concrete answer

@sprootshift
Copy link
Contributor

I believe this is caused by a change in enjoi: tlivings/enjoi#74
I don't think it is correct and agree with tlivings/enjoi#73 (comment), but it's up to @tlivings to roll back that change

@dcharbonnier
Copy link
Contributor

This issue is solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants