-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Make HttpContext available to OpenAPI transformers #56189
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
Comments
I intentionally avoided introducing the In this way, I like that having to access As far as usefulness, the It's a bit of a puritan take to not want to intermingle the two concepts (request pipeline and document construction) so closely and I'm open to having my mind changed if more compelling scenarios arise. Thoughts? |
I think that's a fair point to have on it. At first, I did what you'd alluded to in the epic, and used OpenAPI isn't as perf-critical as general request serving, and I didn't consider the tooling aspect, so it's not the end of the world to go down the I guess a semi-middleground could be to adjust the API suggestion to make the properties nullable and not required, but I imagine that would proliferate a lot of |
Yep, this is the gotcha I ran into as well (I'll post more notes related to this in the issue you linked). For now, I'd be curious to see what other scenarios exist that would merit making |
Background and Motivation
I was looking at how to wire up the
servers
property based on the current HttpContext like NSwag does after opening #56188, and noticed that theHttpContext
isn't immediately available to any OpenAPI transformers.It can be easily be made available via
IHttpContextAccessor
, but that's often frowned upon from a performance perspective, so I figured it would be worth raising the possibility of making it available from the request pipeline to avoid the need to do that.The
HttpContext
could be passed through intoOpenApiDocumentService.GetOpenApiDocumentAsync()
here:aspnetcore/src/OpenApi/src/Extensions/OpenApiEndpointRouteBuilderExtensions.cs
Line 46 in 2b5d2b3
Then it can be directly assigned into the various context objects passed to any transformers, as well as being available to the document service itself.
Proposed API
Usage Examples
Alternative Designs
None.
Risks
None?
The text was updated successfully, but these errors were encountered: