Skip to content

Conversation

@khellang
Copy link
Member

@khellang khellang commented Nov 26, 2025

Description

This makes sure any attribute implementing IModelNameProvider is respected when matching OpenAPI operation parameters with .NET action parameters.

Fixes #64534
Fixes #64521

Copilot AI review requested due to automatic review settings November 26, 2025 08:45
@khellang khellang requested review from a team and captainsafia as code owners November 26, 2025 08:45
@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 Nov 26, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Nov 26, 2025
Copy link
Contributor

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 pull request adds support for respecting IModelNameProvider attributes (like FromQuery(Name = "...")) when matching OpenAPI operation parameters with .NET action parameters for XML comment documentation. This ensures that XML documentation comments are correctly applied to parameters that have custom names specified via model binding attributes.

Key Changes:

  • Introduces a new GetOperationParameter helper method that considers both the parameter's original name and any custom names from IModelNameProvider attributes
  • Adds early null check for parameterInfo before attempting to match operation parameters
  • Updates generated code across all snapshot test files to include the new logic

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

File Description
src/OpenApi/gen/XmlCommentGenerator.cs Adds System.Reflection using statement for ParameterInfo type
src/OpenApi/gen/XmlCommentGenerator.Emitter.cs Implements the core logic for parameter matching with IModelNameProvider support; adds GetOperationParameter helper method and includes Microsoft.AspNetCore.Mvc.ModelBinding namespace
src/OpenApi/test/.../snapshots/*.verified.cs Updates all snapshot test files to reflect the generated code changes from the source generator

@martincostello martincostello added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Nov 26, 2025
@khellang khellang force-pushed the fix/openapi-name-provider branch 3 times, most recently from 68d5b6f to 16a616e Compare November 26, 2025 09:27
@khellang khellang requested a review from Copilot November 26, 2025 09:27
Copy link
Contributor

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

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Copy link
Contributor

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

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

var requestBody = operation.RequestBody;
if (requestBody is not null)
{
requestBody.Description = parameterComment.Description;
Copy link
Member Author

Choose a reason for hiding this comment

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

@captainsafia Do you know why this fallback exists? We're seeing the CancellationToken argument being applied to the request body because of this, which is weird 🤔

Copy link
Member Author

@khellang khellang Nov 26, 2025

Choose a reason for hiding this comment

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

Added a check to skip CancellationToken to avoid applying its XML doc to the request body. I can't see a scenario where you'd ever want to include a cancellation token in your OpenAPI docs 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally, instead of checking against typeof(CancellationToken) directly, it should probably check against the binding source to see if it's BindingSource.Body instead of just blindly falling back to setting the request body description.

Copy link
Contributor

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

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

@silkfire
Copy link

@khellang Could this be merged soon?

@khellang
Copy link
Member Author

khellang commented Dec 30, 2025

@khellang Could this be merged soon?

Sure. If it was up to me, this would've shipped long ago, as it's a major blocker for .NET 10 adoption for us. Unfortunately I don't control the review and merge process here. Someone on the ASP.NET team needs to review and merge it. And judging by the lack of activity here, it looks like it could take a while 😅

@khellang khellang closed this Dec 30, 2025
@khellang khellang reopened this Dec 30, 2025
@dotnet-policy-service dotnet-policy-service bot added this to the 11.0-preview1 milestone Dec 30, 2025
@mikekistler
Copy link
Contributor

Thank you for this contribution!

I spent a little time this morning investigating and it appears that this problem also exists for Minimal APIs. I'm going to add that tag to the PR. Could you add a test in

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/OperationTests.MinimalApis.cs

that verifies the fix also works for Minimal APIs?

@mikekistler mikekistler added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Dec 31, 2025
@khellang
Copy link
Member Author

khellang commented Jan 6, 2026

Could you add a test in

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/OperationTests.MinimalApis.cs

that verifies the fix also works for Minimal APIs?

Will add it and check 👍🏻

@khellang khellang force-pushed the fix/openapi-name-provider branch 2 times, most recently from 78cbcd9 to d6049c6 Compare January 6, 2026 09:51
@khellang khellang force-pushed the fix/openapi-name-provider branch from d6049c6 to 99560e2 Compare January 6, 2026 11:06
@khellang
Copy link
Member Author

khellang commented Jan 6, 2026

I've reverted the change from @desjoerd's comment and added a test that verifies the fix for Minimal APIs as well. This should be ready for review again.

Copy link
Contributor

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

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

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 I will defer to you for formal approval, but this all looks good to me.

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 community-contribution Indicates that the PR has been added by a community member feature-openapi pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

5 participants