JKHeadley / rest-hapi

🚀 A RESTful API generator for Node.js
https://resthapi.com
MIT License
1.19k stars 153 forks source link

Support for later @hapi versions and plugins #220

Closed yoieh closed 4 years ago

yoieh commented 4 years ago

Is your feature request related to a problem? Please describe.

npm WARN deprecated @hapi/joi@14.5.0: This version is no longer maintained

and is the latest version of joi that still exists and I can get this to work with.

I tried to upgrade hapi-swagger to later versions and there required versions of @hapi/hapi and @hapi/joi with no luck.

hapi-swagger Compatibility tabel:

Version Hapi Joi Node
v12.x >=19.0.0 @hapi/hapi >=17.0.0 >=12
v11.x >=18.4.0 @hapi/hapi >=16.0.0 >=8
v10.x >=18.3.1 @hapi/hapi >=14.0.0 >=8

joi 16 and up semis to need validators in custom api routs with out any modules like validate.payload.object be raped in Joi.object() witch breaks swagger.json given an 500 error when accessing swagger ui and this error:

Debug: internal, implementation, error 
    TypeError: Cannot read property 'properties' of undefined
    at Object.parameters.fromProperties (...\node_modules\rest-hapi\node_modules\hapi-swagger\lib\parameters.js:50:17)
    at module.exports.internals.paths.internals.paths.getSwaggerStructures (...\node_modules\rest-hapi\node_modules\hapi-swagger\lib\paths.js:420:32)
    at ...\node_modules\rest-hapi\node_modules\hapi-swagger\lib\paths.js:194:32
    at Array.forEach (<anonymous>)
    at module.exports.internals.paths.internals.paths.buildRoutes (...\node_modules\rest-hapi\node_modules\hapi-swagger\lib\paths.js:161:10)
    at module.exports.internals.paths.internals.paths.build (C:\Users\Yoieh\Documents\projects\nerdsofsweden\satsa\satsa-    at Object.builder.getSwaggerJSON (...\node_modules\rest-hapi\node_modules\hapi-swagger\lib\builder.js:102:24)
    at handler (...\node_modules\rest-hapi\node_modules\hapi-swagger\lib\index.js:114:42)
    at module.exports.internals.Manager.execute (...\node_modules\@hapi\hapi\lib\toolkit.js:41:33)
    at Object.internals.handler (...\node_modules\@hapi\hapi\lib\handler.js:46:48)
    at exports.execute (...\node_modules\@hapi\hapi\lib\handler.js:31:36)
    at Request._lifecycle (...\node_modules\@hapi\hapi\lib\re    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Request._execute (...\node_modules\@hapi\hapi\lib\request.js:221:9)

Not using Joi.object() in >16 gives error

Error starting server: Error: Invalid schema content: (email.$_root.alternatives)
    at new module.exports (...\node_modules\@hapi\hapi\node_modules\@hapi\joi\node_modules\@hapi\hoek\lib\error.js:23:19)
    at Object.module.exports [as assert] (...\node_modules\@hapi\hapi\node_modules\@hapi\joi\node_modules\@hapi\hoek\lib\assert.js:20:11)
    at Object.exports.schema (...\node_modules\@hapi\hapi\node_modules\@hapi\joi\lib\cast.js:50:10)
    at internals.Object.keys (...\node_modules\@hapi\hapi\node_modules\@hapi\joi\lib\types\object\index.js:363:35)
    at Object.exports.schema (...\node_modules\@hapi\hapi\node_modules\@hapi\joi\lib\cast.js:31:29)
    at internals.Object.keys (...\node_modules\@hapi\hapi\node_modules\@hapi\joi\lib\types\object\index.js:363:35)
    at Object.exports.schema (...\node_modules\@hapi\hapi\node_modules\@hapi\joi\lib\cast.js:31:29)
    at internals.Object.keys (...\node_modules\@hapi\hapi\node_modules\@hapi\joi\lib\types\object\index.js:363:35)
    at Object.exports.schema (...\node_modules\@hapi\hapi\node_modules\@hapi\joi\lib\cast.js:31:29)
    at module.exports.internals.Any.root.compile (...\node_modules\@hapi\hapi\node_modules\@hapi\joi\lib\index.js:157:25)
    at Object.exports.compile (...\node_modules\@hapi\hapi\lib\validation.js:21:49)
    at ...\node_modules\@hapi\hapi\lib\route.js:196:43       
    at Array.forEach (<anonymous>)
    at module.exports.internals.Route._setupValidation (...\node_modules\@hapi\hapi\lib\route.js:194:60)
    at new module.exports.internals.Route (...\node_modules\@    at internals.Server._addRoute (...\node_modules\@hapi\hapi\lib\server.js:485:23)
    at internals.Server.route (...\node_modules\@hapi\hapi\lib\server.js:478:22)
    at ...\api\auth.js:12:12
    at module.exports (...\api\auth.js:38:5)
    at module.exports (...\node_modules\rest-hapi\utilities\api-generator.js:34:42)
    at generateRoutes (...\node_modules\rest-hapi\rest-hapi.js:274:10)
    at Object.register (...\node_modules\rest-hapi\rest-hapi.js:107:9) {
  path: 'email.$_root.alternatives'
}

Hapi 19 added a requirement to register validators as joi

No joi schema compiler is loaded by default and must be explicitly loaded using server.validator(require('@hapi/joi')) if uncompiled schemas are using in configuration

Adding this to the rout works but this version dosen't work and brakes generation from models from this package.

Also there are vulnerabilities detected in the dependencies of this package.

Describe the solution you'd like First of all I do understand that this package is a major shortcut to develop a rest api and has an MIT that has no warranty but is still a awesome concept. But if this package in the future ever would be used for more than just prototyping an api the package and dependencies need to be up to date with hapi. Also the different demo projects would have to be updated.

Describe alternatives you've considered If this packages purpose is to no longer be maintained it should be presented like an out dated/deprecated packages not to be used in any production environment and just to build prototypes.

Additional context I'm in no way and expert on Node.js, hapi or joi. There could be a solution for this to be used in newer versions with out vulnerabilities.

JKHeadley commented 4 years ago

@yoieh thanks for the thorough report! I agree, it is due time to upgrade some of rest-hapi's major dependencies. This project is still being maintained, though resources are very limited. The needed updates (especially joi) look to require a sizable amount of work, which is why they've been put off until now.

Note that there has been an effort to keep dependencies somewhat up to date: https://github.com/JKHeadley/rest-hapi/pull/201/files#diff-b9cfc7f2cdf78a7f4b91a753d10865a2

I will begin an effort to update all of the @hapi family dependencies. In the meantime, thank you for your patience, and feel free to contribute!

JKHeadley commented 4 years ago

@yoieh rest-hapi v2.0 is now available with updated hapi modules and plugins. Please see the release notes for changes: https://github.com/JKHeadley/rest-hapi/issues/230

yoieh commented 4 years ago

awesome! and thanks for the grate work to you all and this awesome project it saves a major chunk of time!