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

Issue with Default Handler in resolver

Open kesha-shah opened this issue 2 years ago • 1 comments

Describe the bug With this commit, there is one issue caused which is blocking us to use default exported functions in APIs

To Reproduce

  1. Use any version > 4.13.2 - This bug got introduced in version 4.13.4
  2. Create one HTTP API function, export it as default function, set it as operationId and set its path in x-eov-operation-handler
  3. Try to invoke that API

Actual behavior It gives error Route.get() requires a callback function but got a [object Object] Stacktrace :

Route.get() requires a callback function but got a [object Object]\n at Route. [as get] (/Users/keshashah/work/api-framework/node_modules/express/lib/router/route.js:211:15)\n at Function.proto. [as get] (/Users/keshashah/work/api-framework/node_modules/express/lib/router/index.js:521:19)\n at OpenApiValidator.installOperationHandlers (/Users/keshashah/work/api-framework/node_modules/express-openapi-validator/src/openapi.validator.ts:314:37)\n at /Users/keshashah/work/api-framework/node_modules/express-openapi-validator/src/openapi.validator.ts:215:30\n at processTicksAndRejections (internal/process/task_queues.js:95:5)","timestamp":"2023-05-18T06:02:49.057Z","type":"app-log"}

Expected behavior It should return JSON or any expected response.

Examples and context This bug got created because https://github.com/cdimascio/express-openapi-validator/blob/01950b7558209a6ecefeea5699d5a30c05023662/src/resolvers.ts#L38 here if tmpModules[modulePath][oId] does not exist then it should first check handler from tmpModules[modulePath].default[oId] if that does not exist then only return tmpModules[modulePath].default

Is there any specific reason for this? or should I create a PR for this. Currently all our function with exports.default with operationId are not working with this upgrade.

kesha-shah avatar May 18 '23 07:05 kesha-shah

Proposed PR : https://github.com/cdimascio/express-openapi-validator/pull/846

kesha-shah avatar May 19 '23 05:05 kesha-shah