openapi-backend icon indicating copy to clipboard operation
openapi-backend copied to clipboard

Is there a way to inject middleware before hitting the operation logic?

Open nathanenglert opened this issue 5 years ago • 1 comments

First, I love this tool! Thanks a bunch for putting this together.

Second, I'm looking for something like a "preResponseHandler" of sorts. I'm looking to check a specific header on the request and potentially circumvent the operation if a condition exists. Is there something like that today?

nathanenglert avatar May 19 '20 21:05 nathanenglert

Currently there is no equivalent of preResponseHandler.

Closest thing to what you're describing would be a security handler, but that's really meant to be specific for authorizing requests against OpenAPI security schemes.

The reason there's no catch-all preResponseHandler implemented is that I've had no need for it so far. All the pre-handling I've needed to do has been easy to do before calling handleRequest(), but thinking more about this I can definitely see cases similar to what you described where it would be nice to hook before calling the operation handler but still have access to the OpenAPI Context object.

I'll put this into the backlog of ideas! Feel free to submit a PR. Should be pretty easy to add this. :)

anttiviljami avatar May 23 '20 08:05 anttiviljami