krakenjs/hapi-openapi

Update needed to support new version of Hapi and Joi

rmothilal opened this issue · 10 comments

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

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" }

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

@rmothilal anyway to disable joi validation?

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

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.

@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

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

@rmothilal anyway to disable joi validation?

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

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

This issue is solved