Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Some sort of middleware support #41

Closed
1 task done
djMax opened this issue May 3, 2023 · 4 comments
Closed
1 task done

Some sort of middleware support #41

djMax opened this issue May 3, 2023 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@djMax
Copy link

djMax commented May 3, 2023

Description

The request interception, response interception, etc is quite useful and I wouldn't think would add much to the library. Is there a way to simulate this on top of the library? (I don't see an obvious one)

Proposal

Add a single pre-flight and post-flight hook argument to the methods.

Checklist

@djMax djMax added enhancement New feature or request help wanted Extra attention is needed labels May 3, 2023
@drwpow
Copy link
Owner

drwpow commented May 3, 2023

I like the idea in general. But one difficulty to adding this is the type inference. The library gives you types that 100% match your schema, so any middleware transforms would have to basically not transform your types, otherwise your types are unreliable (if you overrode any response types generated by this library, then I’d argue this library isn’t doing anything for you).

Or should the middleware not be transform-based (and if not, what would be a good example)?

@djMax
Copy link
Author

djMax commented May 3, 2023

Yeah, it's an interesting question. I'd think some well placed generic type args probably do what's needed, but it's often more about "fetch like things." i.e. we currently do request timing and telemetry, header manipulation, generic retry handling, and oauth retry handling (got a 401 saying token expire? go run this async function and then try again. got a 403? return the error). It very well may be that this can all be done different ways (for example being able to pass in a fetch function), but if that's the case then the feature is examples/docs.

@brandonp-ais
Copy link

Just here to say that we use middleware in the same way: for metrics etc., which don't "care" about the types.

Of course it would always be nice to have types available in the middleware, but not imo a hard requirement.

@drwpow
Copy link
Owner

drwpow commented May 22, 2023

I still want to track this! But since I’m merging this repo in with openapi-typescript I’ve moved the discussion here.

@drwpow drwpow closed this as completed May 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants