-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Fix RequestDelegateFactory to handle nullable types correctly in empty request body scenarios #62861
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
…y request body scenarios
Thanks for your PR, @@opuzakov. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
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 an issue where RequestDelegateFactory incorrectly handled nullable parameter types when the request body is empty, ensuring behavior consistency with controller-based APIs.
- Adds nullable type detection to distinguish between regular value types and nullable value types
- Updates the default value assignment logic to leave nullable types as null when the request body is empty
- Includes comprehensive test coverage for the nullable parameter scenario
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
RequestDelegateFactory.cs | Adds nullable type detection and fixes default value assignment logic for empty request bodies |
RequestDelegateFactoryTests.cs | Adds test case to verify nullable parameters are handled correctly with empty request bodies |
|
||
if (allowEmptyRequestBody && bodyType.IsValueType && !isNullableType) // Nullable types should be left null |
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.
[nitpick] Consider extracting the complex condition into a well-named local variable or method to improve readability. For example: var shouldCreateDefaultValueType = allowEmptyRequestBody && bodyType.IsValueType && !isNullableType;
if (allowEmptyRequestBody && bodyType.IsValueType && !isNullableType) // Nullable types should be left null | |
var shouldCreateDefaultValueType = allowEmptyRequestBody && bodyType.IsValueType && !isNullableType; | |
if (shouldCreateDefaultValueType) // Nullable types should be left null |
Copilot uses AI. Check for mistakes.
@dotnet-policy-service agree |
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
Fix RequestDelegateFactory to handle nullable types correctly in empty request body scenarios
Description
This change fixes an issue where RequestDelegateFactory would incorrectly handle nullable parameter types when the request body is empty (aligning behavior with the controller-based API)
The changes include:
Fixes #57055