Skip to content

[OpenApi] Support derived FromKeyedServices types to ignore parameters #62926

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

martincostello
Copy link
Member

Support derived FromKeyedServices

Ignore endpoint parameters using derived [FromKeyedServices] attributes.

Description

  • Support for ignoring OpenAPI parameters decorated with attributes derived from FromKeyedServicesAttribute.
  • Add test for existing support for ignoring parameters decorated with attributes derived from FromServicesAttribute.

Fixes #58739

- Support attributes derived from `FromKeyedServicesAttribute`.
- Add test for existing support for attributes derived from `FromServicesAttribute`.

Resolves dotnet#58739.
@Copilot Copilot AI review requested due to automatic review settings July 25, 2025 12:13
@martincostello martincostello requested review from captainsafia, a team and halter73 as code owners July 25, 2025 12:13
@github-actions github-actions bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jul 25, 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 adds support for derived FromKeyedServicesAttribute types to be properly ignored as OpenAPI parameters, matching the existing behavior for derived FromServicesAttribute types.

  • Changes the equality check to use IsAssignableFrom for FromKeyedServicesAttribute to support inheritance
  • Adds comprehensive test coverage for both derived FromServicesAttribute and FromKeyedServicesAttribute attributes
  • Ensures consistent behavior across OpenAPI generation and API description providers

Reviewed Changes

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

Show a summary per file
File Description
src/OpenApi/src/Services/OpenApiGenerator.cs Updates the attribute check to use IsAssignableFrom for FromKeyedServicesAttribute inheritance support
src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs Same inheritance support change for API description generation
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiGeneratorTests.cs Adds test cases for derived attributes and custom attribute classes
src/Mvc/Mvc.ApiExplorer/test/EndpointMetadataApiDescriptionProviderTest.cs Adds test cases for derived attributes and custom attribute classes
src/Mvc/Mvc.ApiExplorer/test/DefaultApiDescriptionProviderTest.cs Adds comprehensive test method and custom attribute classes for derived services
Comments suppressed due to low confidence (1)

src/Mvc/Mvc.ApiExplorer/test/DefaultApiDescriptionProviderTest.cs:11

  • This unused import removal appears unrelated to the PR's purpose of supporting derived FromKeyedServices types. Consider including this change in a separate cleanup commit or PR.
using Microsoft.AspNetCore.Http;

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jul 25, 2025
Copy link
Contributor

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

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 community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Services injected with attribute derived from FromKeyedServicesAttribute appear as request body in swagger
1 participant