-
Notifications
You must be signed in to change notification settings - Fork 10.5k
OpenAPI: Fix ModelMetadata null reference exception in emitted XMLComment transformers #63872
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: main
Are you sure you want to change the base?
Conversation
…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
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.
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 |
Thanks for your PR, @@desjoerd. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
...pshots/AddOpenApiTests.CanInterceptAddOpenApi#OpenApiXmlCommentSupport.generated.verified.cs
Outdated
Show resolved
Hide resolved
As I think this was the encoding before my change
@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 😊. |
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