openapi-backend
Advanced tools
Comparing version
@@ -86,2 +86,6 @@ "use strict"; | ||
'unauthorizedHandler', | ||
'preRoutingHandler', | ||
'postRoutingHandler', | ||
'postSecurityHandler', | ||
'preOperationHandler', | ||
'postResponseHandler', | ||
@@ -227,2 +231,7 @@ ]; | ||
context.request = this.router.parseRequest(req); | ||
// preRoutingHandler | ||
const preRoutingHandler = this.handlers['preRoutingHandler']; | ||
if (preRoutingHandler) { | ||
await preRoutingHandler(context, ...handlerArgs); | ||
} | ||
// match operation (routing) | ||
@@ -233,2 +242,7 @@ try { | ||
catch (err) { | ||
// postRoutingHandler on routing failure | ||
const postRoutingHandler = this.handlers['postRoutingHandler']; | ||
if (postRoutingHandler) { | ||
await postRoutingHandler(context, ...handlerArgs); | ||
} | ||
let handler = this.handlers['404'] || this.handlers['notFound']; | ||
@@ -247,2 +261,7 @@ if (err instanceof Error && err.message.startsWith('405')) { | ||
context.request = this.router.parseRequest(req, context.operation); | ||
// postRoutingHandler on routing success | ||
const postRoutingHandler = this.handlers['postRoutingHandler']; | ||
if (postRoutingHandler) { | ||
await postRoutingHandler(context, ...handlerArgs); | ||
} | ||
// get security requirements for the matched operation | ||
@@ -306,2 +325,7 @@ // global requirements are already included in the router | ||
}; | ||
// postSecurityHandler | ||
const postSecurityHandler = this.handlers['postSecurityHandler']; | ||
if (postSecurityHandler) { | ||
await postSecurityHandler(context, ...handlerArgs); | ||
} | ||
// call unauthorizedHandler handler if auth fails | ||
@@ -334,5 +358,10 @@ if (!authorized && securityRequirements.length > 0) { | ||
} | ||
// preOperationHandler – runs just before the operation handler | ||
const preOperationHandler = this.handlers['preOperationHandler']; | ||
if (preOperationHandler) { | ||
await preOperationHandler(context, ...handlerArgs); | ||
} | ||
// get operation handler | ||
const routeHandler = this.handlers[operationId]; | ||
if (!routeHandler) { | ||
const operationHandler = this.handlers[operationId]; | ||
if (!operationHandler) { | ||
// 501 not implemented | ||
@@ -346,3 +375,3 @@ const notImplementedHandler = this.handlers['501'] || this.handlers['notImplemented']; | ||
// handle route | ||
return routeHandler(context, ...handlerArgs); | ||
return operationHandler(context, ...handlerArgs); | ||
}).bind(this)(); | ||
@@ -349,0 +378,0 @@ // post response handler |
{ | ||
"name": "openapi-backend", | ||
"description": "Build, Validate, Route, Authenticate and Mock using OpenAPI definitions. Framework-agnostic", | ||
"version": "5.12.0", | ||
"version": "5.13.0", | ||
"author": "Viljami Kuosmanen <viljami@viljami.io>", | ||
@@ -6,0 +6,0 @@ "funding": "https://github.com/sponsors/anttiviljami", |
Sorry, the diff of this file is not supported yet
158774
1.43%2514
1.17%