express-openapi-validator icon indicating copy to clipboard operation
express-openapi-validator copied to clipboard

koa-openapi-validator cannot integrate with koa3

Open kovercjm opened this issue 4 years ago • 1 comments

Hello,

Describe the bug I have enjoyed express-openapi-validator and would like to implement on a koa_based api server as well. But seems report an error when following the instruction as recommended.

To Reproduce Please find my app source code here. Try GET from the 'http://localhost:3000/api/v1/example' endpoint. (May need to have DB connection as in README to get return result)

Actual behavior It cannot process with the actual API call and returns with the following:

19:40:20 ERROR [Sever] - TypeError: Cannot read property 'split' of undefined
    at lookupRoute (/Users/kover/Technical Study/Server Template/nodejs-openapi-server-template/node_modules/express-openapi-validator/src/middlewares/openapi.metadata.ts:63:34)
    at /Users/kover/Technical Study/Server Template/nodejs-openapi-server-template/node_modules/express-openapi-validator/src/middlewares/openapi.metadata.ts:28:21
    at /Users/kover/Technical Study/Server Template/nodejs-openapi-server-template/node_modules/express-openapi-validator/src/openapi.validator.ts:147:18

Expected behavior I would expect it works as express-openapi-validator.

My assumption I think it may be caused by this line of code, according to the error log:

const path = (req.originalUrl ?? req.url).split('?')[0];

May because of the Koa doesn't have 'req.originalUrl'. Should be 'ctx.originalUrl'?

Thanks for your time and great project!

Best regards, Kover

kovercjm avatar Jul 25 '21 11:07 kovercjm

I'm also facing this issue. Did you find a workaround? (though i have this issue with koa v2)

seems perhaps related to this

rek avatar Aug 06 '21 13:08 rek