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
@dotnet-policy-service
Copy link
Contributor

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

Copilot finished reviewing on behalf of khellang November 26, 2025 08:49
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
Copilot finished reviewing on behalf of khellang November 26, 2025 09:30
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.

@khellang khellang force-pushed the fix/openapi-name-provider branch from 16a616e to d6a6aaa Compare November 26, 2025 10:11
@khellang khellang requested a review from Copilot November 26, 2025 11:13
Copilot finished reviewing on behalf of khellang November 26, 2025 11:15
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.

@khellang khellang requested a review from Copilot November 26, 2025 11:40
Copilot finished reviewing on behalf of khellang November 26, 2025 11:42
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

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.

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.

/// <param name="userId">The id of the user.</param>
[HttpGet("{userId}")]
public string Get()
public string Get(int userId)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I should have given this test a better name. It's added to make sure the xml document generator works for the case where the parameter is omitted or added. See #63872

Copy link
Member Author

@khellang khellang Nov 28, 2025

Choose a reason for hiding this comment

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

Ah, sorry about that. Will revert and move to another test case. Should I rename it to something clearer?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am fine if you rename it. Or maybe we can just add a comment in the description of that controller, to keep the diff a bit smaller in regards to snapshots

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 feature-openapi

Projects

None yet

3 participants