Skip to content

Add IEndpointMetadataProvider to UnauthorizedHttpResult - #65611

Merged
Youssef1313 merged 7 commits into
dotnet:mainfrom
martincostello:gh-65491
Jul 20, 2026
Merged

Youssef1313 merged 7 commits into
dotnet:mainfrom
martincostello:gh-65491

Conversation

@martincostello

Copy link
Copy Markdown
Member

Add IEndpointMetadataProvider to UnauthorizedHttpResult

Implement IEndpointMetadataProvider on UnauthorizedHttpResult.

Description

Adds IEndpointMetadataProvider to UnauthorizedHttpResult to improve OpenAPI document generation.

Will leave in draft until #65491 is approved, but I already had a Copilot generated branch that implemented these changes so figured I'd clean it up and push it now anyway.

Fixes #65491

Implement `IEndpointMetadataProvider` on `UnauthorizedHttpResult`.

Resolves dotnet#65491.
@github-actions github-actions Bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Mar 2, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Mar 2, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @@martincostello. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@Youssef1313
Youssef1313 marked this pull request as ready for review July 15, 2026 16:34
Copilot AI review requested due to automatic review settings July 15, 2026 16:34
@Youssef1313
Youssef1313 requested review from a team, BrennanConroy and halter73 as code owners July 15, 2026 16:34

@Youssef1313 Youssef1313 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR implements IEndpointMetadataProvider on UnauthorizedHttpResult so endpoints that return it (including via Results<...> unions) contribute a 401 response to endpoint metadata, improving OpenAPI document generation. It also updates OpenAPI integration snapshots and adds regression tests to validate metadata extraction.

Changes:

  • Implement IEndpointMetadataProvider.PopulateMetadata on UnauthorizedHttpResult to emit ProducesResponseTypeMetadata for HTTP 401.
  • Add test coverage in Http.Results and MVC application model tests to validate metadata extraction (including Results<...> union return types).
  • Extend the OpenAPI sample and update OpenAPI snapshot baselines to include the new 401 response on the affected endpoint.

Reviewed changes

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

Show a summary per file
File Description
src/Http/Http.Results/src/UnauthorizedHttpResult.cs Adds IEndpointMetadataProvider implementation to emit 401 response metadata.
src/Http/Http.Results/test/UnauthorizedResultTests.cs Adds unit tests validating PopulateMetadata behavior and null-guarding.
src/Mvc/Mvc.Core/test/ApplicationModels/DefaultApplicationModelProviderTest.cs Adds MVC regression test verifying return-type metadata extraction for Results<...> unions.
src/OpenApi/sample/Endpoints/MapSchemasEndpoints.cs Adds a sample endpoint using a Results<...> union including UnauthorizedHttpResult to drive OpenAPI generation.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApiDocumentLocalizationTests.VerifyOpenApiDocumentIsInvariant.verified.txt Updates baseline to include the new 401 response for the added sample endpoint.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=schemas-by-ref.verified.txt Updates OpenAPI 3.0 baseline with the new endpoint responses.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_1/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=schemas-by-ref.verified.txt Updates OpenAPI 3.1 baseline with the new endpoint responses.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_2/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=schemas-by-ref.verified.txt Updates OpenAPI 3.2 baseline with the new endpoint responses.

@Youssef1313

Copy link
Copy Markdown
Member

@martincostello Could you please address the small comments from Copilot? This will be ready to merge after that 🎉 🚀

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@Youssef1313
Youssef1313 merged commit 58c5632 into dotnet:main Jul 20, 2026
26 checks passed
@Youssef1313

Copy link
Copy Markdown
Member

Thanks for the contribution @martincostello 🎉

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 community-contribution Indicates that the PR has been added by a community member feature-openapi

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add IEndpointMetadataProvider to UnauthorizedHttpResult

3 participants