krakenjs / hapi-openapi

Build design-driven apis with OpenAPI (formerly swagger) 2.0 and hapi.
Other
210 stars 75 forks source link

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

Open rmothilal opened 4 years ago

rmothilal commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

rodoabad commented 4 years ago

@rmothilal anyway to disable joi validation?

ajbowler commented 4 years ago

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

ajbowler commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

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

rmothilal commented 4 years ago

@rmothilal anyway to disable joi validation?

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

sprootshift commented 4 years ago

I believe this is caused by a change in enjoi: https://github.com/tlivings/enjoi/pull/74 I don't think it is correct and agree with https://github.com/tlivings/enjoi/issues/73#issuecomment-616542744, but it's up to @tlivings to roll back that change

dcharbonnier commented 3 years ago

This issue is solved