Respect IModelNameProvider when matching OpenAPI parameters#64535
Open
khellang wants to merge 19 commits into
Open
Respect IModelNameProvider when matching OpenAPI parameters#64535khellang wants to merge 19 commits into
khellang wants to merge 19 commits into
Conversation
Contributor
There was a problem hiding this comment.
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
GetOperationParameterhelper method that considers both the parameter's original name and any custom names fromIModelNameProviderattributes - Adds early null check for
parameterInfobefore 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 |
68d5b6f to
16a616e
Compare
16a616e to
d6a6aaa
Compare
khellang
commented
Nov 26, 2025
1 task
Member
Author
|
Rebased and fixed latest comments. Sorry for the long delay 😞 |
366015a to
1edd423
Compare
Member
Member
Author
Youssef1313
reviewed
Jul 8, 2026
Youssef1313
reviewed
Jul 8, 2026
Youssef1313
reviewed
Jul 8, 2026
…eter is bound to it This avoids applying documentation for parameters that aren't part of the OpenAPI surface, like CancellationToken or [FromServices] parameters, to the request body description.
- Compute model names once per parameter instead of recomputing in GetOperationParameter and IsRequestBodyParameter - Treat form/form-file binding sources as request-body parameters so form parameter documentation is applied to the request body - Guard the property-loop request-body fallback with the binding source so only body-bound properties apply their docs to the request body
…erit attributes - Simplify GetModelNames call to use parameterComment.Name directly - Add GetPropertyInfo helper to avoid AmbiguousMatchException on shadowed properties while preserving inherited-property resolution - Read model-name attributes with inherit: true
d84c6aa to
eb4cb7e
Compare
Covers the case where a bound model inherits a documented property from a base type. The property is enumerated under the derived ContainerType while its DeclaringType is the base, so resolving it requires walking the hierarchy (a lookup restricted to the container type alone would drop the description).
Covers a bound model that redeclares a base property with `new` and a different type. A plain Type.GetProperty(name) throws AmbiguousMatchException for this shape; the property lookup must resolve the most-derived declaration and apply its documentation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This makes sure any attribute implementing
IModelNameProvideris respected when matching OpenAPI operation parameters with .NET action parameters.It also replaces the
CancellationTokenworkaround from the initial review with a proper check againstBindingSource.Body, so documentation for parameters that aren't part of the OpenAPI surface (e.g.CancellationTokenor[FromServices]parameters) is no longer applied to the request body description.Fixes #64534
Fixes #64521
Fixes #67076
Fixes #65805