-
Notifications
You must be signed in to change notification settings - Fork 0
Code Review Bench PR #64401 - [release/10.0] Fix ModelMetadata null reference exception in emitted XMLComment transformers #8
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
base: base_pr_64401_20260125_1476
Are you sure you want to change the base?
Changes from all commits
fef8c44
c1441a7
11f5b24
bbc5308
45b170b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,3 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Collections.Immutable; | ||
| using System.IO; | ||
|
|
@@ -382,7 +379,7 @@ public Task TransformAsync(OpenApiOperation operation, OpenApiOperationTransform | |
| } | ||
| if (methodComment.Remarks is { } remarks) | ||
| { | ||
| operation.Description = remarks; | ||
| operation.Summary = remarks; | ||
| } | ||
| if (methodComment.Parameters is { Count: > 0}) | ||
| { | ||
|
|
@@ -444,14 +441,15 @@ public Task TransformAsync(OpenApiOperation operation, OpenApiOperationTransform | |
| foreach (var parameterDescription in context.Description.ParameterDescriptions) | ||
| { | ||
| var metadata = parameterDescription.ModelMetadata; | ||
| if (metadata.MetadataKind == ModelMetadataKind.Property | ||
| if (metadata is not null | ||
| && metadata.MetadataKind == ModelMetadataKind.Property | ||
| && metadata.ContainerType is { } containerType | ||
| && metadata.PropertyName is { } propertyName) | ||
| { | ||
| var propertyDocId = DocumentationCommentIdHelper.CreateDocumentationId(containerType, propertyName); | ||
| if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(propertyDocId), out var propertyComment)) | ||
| { | ||
| var parameter = operation.Parameters?.SingleOrDefault(p => p.Name == metadata.Name); | ||
| var parameter = operation.Parameters?.SingleOrDefault(p => p.Name == propertyName); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| var description = propertyComment.Summary; | ||
| if (!string.IsNullOrEmpty(description) && !string.IsNullOrEmpty(propertyComment.Value)) | ||
| { | ||
|
|
@@ -465,7 +463,6 @@ public Task TransformAsync(OpenApiOperation operation, OpenApiOperationTransform | |
| { | ||
| if (operation.RequestBody is not null) | ||
| { | ||
| operation.RequestBody.Description = description; | ||
| if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) | ||
| { | ||
| var content = operation.RequestBody.Content?.Values; | ||
|
|
@@ -479,6 +476,7 @@ public Task TransformAsync(OpenApiOperation operation, OpenApiOperationTransform | |
| mediaType.Example = parsedExample; | ||
| } | ||
| } | ||
| operation.RequestBody.Description = description; | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change from
operation.Description = remarkstooperation.Summary = remarks(line 382) means that when both<summary>and<remarks>XML tags are present on a method, the remarks text will overwrite the summary that was just set on line 374.Previously:
<summary>→operation.Summary<remarks>→operation.DescriptionNow:
<summary>→operation.Summary<remarks>→operation.Summary(overwrites the summary!)This seems semantically incorrect. If both tags are provided, the summary is silently lost. The original behavior of mapping remarks to
operation.Descriptionmakes more sense in the OpenAPI context, where Summary and Description are distinct fields.Additionally, this change is NOT reflected in any of the 9 snapshot files (they all still have
operation.Description = remarks), so the snapshot tests will fail when regenerated.Was this helpful? React with 👍 / 👎