krakenjs / swaggerize-routes

Swagger document driven route builder.
Other
58 stars 57 forks source link

fail to validate query parameter #83

Closed kangchals closed 7 years ago

kangchals commented 7 years ago

Hi, First of all, Thank for all your endeavors for this projects.

I tried to validate query parameter but fail.

Can you give me some guide or advise?

below is the OpenAPI schema for the route. "get": { "summary": "pingping", "operationId": "ping", "tags": [ "pets" ], "parameters": [ { // I want to validate this "name": "skip", "in": "query", "description": "number of items to skip", "required": true, "type": "string" } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/test" } }, "default": { "description": "unexpected error", "schema": { "$ref": "#/definitions/Error" } } }, "security": [ { "admin_key": [] } ] }, When I run the hapi server and request like GET /ping?skip=123, it works fine.

However, the request like GET /ping occurs internal server error. the error stack is below Debug: internal, implementation, error TypeError: child.schema._getLabel is not a function at _base (C:\Users\kangcs.SOLID\myTest\swaggerize-hapi\node_modules\joi\lib\types\object\index.js:160:93) at _validate (C:\Users\kangcs.SOLID\myTest\swaggerize-hapi\node_modules\joi\lib\types\any\index.js:590:37) at _validateWithOptions (C:\Users\kangcs.SOLID\myTest\swaggerize-hapi\node_modules\joi\lib\types\any\index.js:650:29) at root.validate (C:\Users\kangcs.SOLID\myTest\swaggerize-hapi\node_modules\joi\lib\index.js:121:23) at Object.internals.input (C:\Users\kangcs.SOLID\myTest\swaggerize-hapi\node_modules\hapi\lib\validation.js:147:20) at exports.query (C:\Users\kangcs.SOLID\myTest\swaggerize-hapi\node_modules\hapi\lib\validation.js:30:22) at each (C:\Users\kangcs.SOLID\myTest\swaggerize-hapi\node_modules\hapi\lib\request.js:404:16) at iterate (C:\Users\kangcs.SOLID\myTest\swaggerize-hapi\node_modules\items\lib\index.js:36:13) at done (C:\Users\kangcs.SOLID\myTest\swaggerize-hapi\node_modules\items\lib\index.js:28:25) at authenticated (C:\Users\kangcs.SOLID\myTest\swaggerize-hapi\node_modules\hapi\lib\auth.js:417:20)

I traced the errors, the problem is enjoi i guess.

first of all, enjoi convert the openAPI json file to the enjoi object.

and the child.schema is enjoi object especially from internal string constructor ?

And enjoi's internal string object is different from joi object which has _getLabel method.

I am not sure what I wrote is correct or not.....

Anyway, I need normal error process when the request was failed to meet the validation. But now, It emits internal server error and it is not acceptable.

Can you check these thing? Thank you!!

kangchals commented 7 years ago

I found that this repository using 6.10.1 version on joi . However My repository is using 10.6.0. I don't know why it happens. the package.json of mine is below

{ "name": "hapitest", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "hapi": "*", "hapi-auth-jwt": "^4.0.0", "inert": "^4.2.0", "jsonwebtoken": "^7.4.1", "swaggerize-hapi": "*", "vision": "^4.1.1" } }

kangchals commented 7 years ago

I figure out what is the problem. The last commit(6ca934fbb) at swaggerize-hapi is not including yet. And the operation of the last commit is to make validators are Joi schemas. Especially https://github.com/krakenjs/swaggerize-hapi/blob/master/lib/index.js#L147 line solve the problem So. right now, you can solve the problem like npm install krakenjs/swaggerize-hapi --save