You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
newOpenApiValidator({
apiSpec,operationHandlers: {basePath: path.join(__dirname,'routes'),resolver: (basePath,route)=>{// Pluck controller and function names from operationIdconst[controllerName,functionName]=route.schema['operationId'].split('.')// Get path to module and attempt to require itconstmodulePath=path.join(basePath,controllerName);consthandler=require(modulePath)// Simplistic error checking to make sure the function actually exists// on the handler moduleif(handler[functionName]===undefined){thrownewError(`Could not find a [${functionName}] function in ${modulePath} when trying to route [${route.method}${route.expressRoute}].`)}// Finally return our functionreturnhandler[functionName]}});
So route is supposed to have a schema property.
We can only access:
Yeah, I came across this issue as well and it should be noted that apiDoc is the full schema, not just the schema for this route. It wasn't exactly trivial to get the schema for the current route but I was able to get it. Below is the resolver I put together for async ESM modules. Hopefully this can help someone encountering the same issue!
importpathfrom"path"constesmresolver=basePath=>{return{
basePath,resolver: (basePath,route,apiDoc)=>{constpathKey=route.openApiRoute.substring(route.basePath.length)constschema=apiDoc.paths[pathKey][route.method.toLowerCase()]// x-eov-operation-id takes priority over operationIdconstfn=schema["x-eov-operation-id"]||schema["operationId"]// x-eov-operation-handler with fallback to routes.jsconsthandler=schema["x-eov-operation-handler"]||"routes"consthandlerFile=`${handler}.js`constmodP=import(path.join(basePath,handlerFile))returnasync(req,res,next)=>{try{constmod=awaitmodPmod[fn](req,res)}catch(err){console.error(err)next(newError(`Routing error ${handlerFile}:${fn}`))}}}}}exportdefaultesmresolver
Describe the bug
In the example given for custom operation resolver, we can read:
So route is supposed to have a
schema
property.We can only access:
Instead resolver has 3 arguments :
basePath
(which is the baseDirectory, not route.basePath),route
ANDapiDoc
!The example should mention
apiDoc
instead ofroute.schema
.The text was updated successfully, but these errors were encountered: