Skip to content

Skip IResult in metadata if it implements IEndpointMetadataProvider #63157

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 1 commit into from
Aug 7, 2025

Conversation

captainsafia
Copy link
Member

Closes #57801, specifically #57801 (comment).

Current implementation assumes that any IResult type in metadata is one that implements IEndpointMetadataProvider to populate its value type, but that's not the case for all types that implement IResult.

Note, there is a case that doesn't work with this current check:

class MyResult : IResult, IEndpointMetadataProvider
{
  public string Content { get; set; }
  public PopulateMetadata()
  {
     builder.Metadata.Add(new ProducesResponseTypeMetadata(typeof(MyResult));
  }
}

But I'm inclined that scenarios like the above should be modeled like:

class MyResult<T> : IResult, IEndpointMetadataProvider
{
  public T Value { get; }
  public PopulateMetadata()
  {
     builder.Metadata.Add(new ProducesResponseTypeMetadata(typeof(T));
  }
}

@Copilot Copilot AI review requested due to automatic review settings August 6, 2025 17:43
@captainsafia captainsafia requested review from a team and halter73 as code owners August 6, 2025 17:43
@github-actions github-actions bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Aug 6, 2025
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.

Pull Request Overview

This PR fixes an issue where custom IResult implementations were being incorrectly excluded from OpenAPI metadata generation. The fix distinguishes between built-in framework IResult types (that implement IEndpointMetadataProvider and handle their own metadata) and custom IResult implementations that should be included in API documentation.

  • Updated the response metadata filtering logic to only skip IResult types that also implement IEndpointMetadataProvider
  • Added test coverage for custom IResult implementations in API documentation
  • Updated snapshot tests to reflect the new behavior with custom IResult types appearing in OpenAPI schemas

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Mvc/Mvc.ApiExplorer/src/ApiResponseTypeProvider.cs Core fix - modified condition to only skip IResult types that implement IEndpointMetadataProvider
src/Mvc/Mvc.ApiExplorer/test/ApiResponseTypeProviderTest.cs Added test for custom IResult return types with metadata
src/Mvc/Mvc.ApiExplorer/test/EndpointMetadataApiDescriptionProviderTest.cs Added test for response metadata with custom IResult implementor
src/OpenApi/sample/Endpoints/MapSchemasEndpoints.cs Added sample endpoint demonstrating custom IResult usage
Various snapshot files Updated test snapshots to include new CustomIResultImplementor schema

@captainsafia captainsafia merged commit d72b3c2 into main Aug 7, 2025
30 checks passed
@captainsafia captainsafia deleted the safia/fix-57801 branch August 7, 2025 20:36
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-rc1 milestone Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix ProducesResponseType on IResult handling in OpenApiGenerator and ApiResponseTypeProvider
2 participants