Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix OpenAPI server URLs for Aspire scenarios#60673

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
wtgodbe merged 3 commits intorelease/9.0fromcs/openapi-servers-fix
Mar 10, 2025

Conversation

@captainsafia
Copy link
Member

@captainsafiacaptainsafia commentedFeb 28, 2025
edited
Loading

Description

This PR supports respecting he X-Forwarded-Proto and X-Forwarded-Host headers when generating server URLs in OpenAPI documents. When these headers are present in the request, the OpenAPI document service will use them to generate the correct server URLs instead of using the original host and scheme values derived from the service configuration.

This is particularly useful in environments where the API is behind a proxy, load balancer, or gateway, allowing the generated OpenAPI document to correctly reference the public-facing URL rather than the internal service URL.

Fixes#57332

Customer Impact

Without this change, documents served behind reverse proxies or forwarded endpoints do not reflect the correct service URl, particularly impact for the ASP.NET Core + Aspire scenario. While the issue is easy to workaround, we want a smoother experience with Aspire out-of-the-box.

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Low-risk, becase change as it only affects the generation of server URLs in OpenAPI documents and does not impact the actual API functionality.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

* Support resolving OpenAPI server URLs from HttpRequest* Try passing optional params everywhere
CopilotAI review requested due to automatic review settingsFebruary 28, 2025 23:54
@captainsafiacaptainsafia requested a review froma team as acode ownerFebruary 28, 2025 23:54
@ghostghost added the area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates labelFeb 28, 2025
@dotnet-policy-servicedotnet-policy-servicebot added this to the9.0.x milestoneFeb 28, 2025
Copy link
Contributor

CopilotAI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR fixes the generation of OpenAPI server URLs in proxy scenarios by properly using X-Forwarded-Proto and X-Forwarded-Host headers to compute the externally accessible URLs.

  • Adds new tests to validate behavior with different forwarded header values.
  • Updates the OpenApiDocumentService API to accept an optional HttpRequest parameter and adjust server URL construction accordingly.
  • Modifies the endpoint extension to propagate the HttpRequest to the document service.

Reviewed Changes

FileDescription
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiDocumentService/OpenApiDocumentServiceTests.Servers.csIntroduces tests validating the use of forwarded headers and expected URL generation.
src/OpenApi/src/Services/OpenApiDocumentService.csUpdates method signatures and logic to use the optional HttpRequest for URL generation.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiDocumentServiceTestsBase.csUpdates verification calls to pass null for the httpRequest parameter where not applicable.
src/OpenApi/src/Extensions/OpenApiEndpointRouteBuilderExtensions.csAdjusts method calls to pass the HttpRequest in order to leverage the new URL generation logic.

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

@wtgodbewtgodbe added Servicing-approvedShiproom has approved the issue and removed Servicing-considerShiproom approval is required for the issue labelsMar 10, 2025
@wtgodbe
Copy link
Member

Approved over email

@wtgodbewtgodbe merged commit561e31a intorelease/9.0Mar 10, 2025
23 of 25 checks passed
@wtgodbewtgodbe deleted the cs/openapi-servers-fix branchMarch 10, 2025 20:01
@dotnet-policy-servicedotnet-policy-servicebot modified the milestones:9.0.x,9.0.4Mar 10, 2025
This was referencedNov 17, 2025
This was referencedNov 24, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@BrennanConroyBrennanConroyBrennanConroy approved these changes

Assignees

No one assigned

Labels

area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-openapiServicing-approvedShiproom has approved the issue

Projects

None yet

Milestone

9.0.4

Development

Successfully merging this pull request may close these issues.

4 participants

@captainsafia@wtgodbe@BrennanConroy

[8]ページ先頭

©2009-2025 Movatter.jp