-
-
Notifications
You must be signed in to change notification settings - Fork 507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow onRequest middleware to add headers that the schema requires #2073
Comments
This is tricky because there’s no way to store that information in a way that’s currently-accessible by the static types. You’ve stated a clear problem that all users of this library have, and would be a good improvement! But your description doesn’t outline enough of a proposal here to describe exactly how to solve this problem. I’d love to see this expanded into more of a complete solution that describes how we could achieve this—how can static typing “peer into” what you have or have not done in middleware? As an aside, I’ve added a new “openapi-fetch-codegen” label to this issue, because I’m not sure that this would even be possible without having some sort of intermediary codegen step for openapi-fetch. But perhaps it is, and I’m just not thinking of it! Either way, there are a number of related issues that currently don’t have known solutions for. Like everything, it‘s a tradeoff—openapi-fetch relies on no codegen, and some of the absolute fastest performance possible by its design. But this is one of the tradeoffs—repetition in runtime code like this. If users are willing to sacrifice a little more memory usage, and a little more footprint, and a codegen step, we could come up with solutions. |
Hi! Jumping in to provide at least a temporary workaround that lets our linters sleep easy :) Remove
|
To my understanding, if one has multiple protected routes, say
/auth/*
, which are specified in the schema and require an Authorization header, currently it is required to set the header with each request.While the current implementation of middleware allows for setting a request header, TS still requires an authorization to be set with each individual request. So doing the following becomes not possible.
While this does not invalidate many of the use cases for middleware, which are great, this use case would be a welcome addition.
The text was updated successfully, but these errors were encountered: