OpenAPI: Fix ModelMetadata null reference exception in emitted XMLComment transformers#63872
OpenAPI: Fix ModelMetadata null reference exception in emitted XMLComment transformers#63872captainsafia merged 4 commits intodotnet:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a null reference exception in the OpenAPI source generator that occurs when processing route parameters that don't have bound models. The fix adds a null check for ModelMetadata before accessing its properties.
- Adds null safety check for ModelMetadata in XML comment transformer generation
- Updates all generated test snapshots to reflect the fix
- Includes a new test case to verify the fix works correctly
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/OpenApi/gen/XmlCommentGenerator.Emitter.cs | Adds null check before accessing ModelMetadata properties |
| src/OpenApi/test/.../OperationTests.Controllers.cs | Adds test case for unused route parameters scenario |
| Multiple snapshot files | Updates generated code snapshots to include the null check |
...pshots/AddOpenApiTests.CanInterceptAddOpenApi#OpenApiXmlCommentSupport.generated.verified.cs
Outdated
Show resolved
Hide resolved
|
@captainsafia could you review this? Maybe it's still possible to backport this fix into .NET 10. Also when thinking of fixing potential review comments 😊. |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
I see that one of the snapshot tests is failing, will check this evening! |
…ment transformers When a route parameter does not have a bound model it would case a null reference exception because the ModelMetadata on the ParameterDescriptor was null. This is fixed by adding a null reference check Fixes dotnet#63757
As I think this was the encoding before my change
Head branch was pushed to by a user without write access
9098768 to
24a032f
Compare
24a032f to
1c4cdd9
Compare
|
@captainsafia the build is green, the problem was some whitespace in one of the snapshots 😅 |
|
I think the automerge is canceled because of fixing the whitespace in the snapshot 😅 |
|
LGTM! 😁 |
|
/backport to release/10.0 |
|
Started backporting to |
When a route parameter does not have a bound model it would case a null reference exception because the ModelMetadata on the ParameterDescriptor was null. This is fixed by adding a null reference check
Fixes #63757