Skip to content

Support resolving OpenAPI server URLs from HttpRequest #60617

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

Merged
merged 3 commits into from
Feb 27, 2025

Conversation

captainsafia
Copy link
Member

Closes #57332.

I was previously squeamish about introducing a dependency on HttpRequest in OpenApiDocumentService.GetOpenApiDocumentAsync because it ends up being called from the build-time generation codepath but considering some ideas I have in that space I think it's fine for us to introduce a dependency on the HttpRequest for this codepath.

I've retained the codepath that uses the ServerAddressFeature for back-compat in the case that an HttpContext is not available.

Note: this is a backport candidate.

@Copilot Copilot AI review requested due to automatic review settings February 25, 2025 22:23
@captainsafia captainsafia requested a review from a team as a code owner February 25, 2025 22:23
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

src/OpenApi/src/Services/OpenApiDocumentService.cs:223

  • Returning an empty collection using square brackets is invalid in C#. Replace with a valid initializer, for example: return new List();
return [];

Copy link
Contributor

@mikekistler mikekistler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍

@captainsafia captainsafia added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-web-frameworks labels Feb 26, 2025
@captainsafia captainsafia enabled auto-merge (squash) February 27, 2025 17:41
@captainsafia captainsafia merged commit 8b77ff5 into main Feb 27, 2025
27 checks passed
@captainsafia captainsafia deleted the cs/servers-uri-bugfix branch February 27, 2025 19:49
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview3 milestone Feb 27, 2025
captainsafia added a commit that referenced this pull request Feb 28, 2025
* Support resolving OpenAPI server URLs from HttpRequest

* Try passing optional params everywhere
wtgodbe pushed a commit that referenced this pull request Mar 10, 2025
* Support resolving OpenAPI server URLs from HttpRequest (#60617)

* Support resolving OpenAPI server URLs from HttpRequest

* Try passing optional params everywhere

* Fix up handling for forwarded headers

* Revert "Fix up handling for forwarded headers"

This reverts commit bf991f6.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Server URLs in OpenAPI document are incorrect when application used with .NET Aspire
3 participants