-
Notifications
You must be signed in to change notification settings - Fork 190
fix: strip non-nullable optional params in Dart/Flutter SDKs #1252
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
Conversation
This change updates the Dart and Flutter SDK templates to conditionally
include non-nullable optional parameters in the request params map only
when they are not null.
Previously, all parameters were always included in the params map,
which could lead to unnecessary null values being sent in API requests.
This implementation matches the Python SDK behavior (templates/python/base/params.twig)
where optional non-nullable parameters are checked with "if not None" before
being added to api_params.
Changes:
- Modified templates/dart/base/utils.twig map_parameter macro
- Modified templates/flutter/base/utils.twig map_parameter macro
- Uses Dart's collection-if syntax for conditional parameter inclusion
- Adds null assertion operator (!) for enum values when inside null check
Example generated code:
```dart
final Map<String, dynamic> apiParams = {
'requiredParam': requiredParam,
if (optionalParam != null) 'optionalParam': optionalParam,
};
```
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds conditional emission in the Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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 updates the Dart and Flutter SDK templates to conditionally include non-nullable optional parameters in API request maps only when they are not null, aligning with Python SDK behavior.
- Modified parameter mapping logic to use collection-if syntax for non-nullable optional params
- Removed
removeWherenull filtering from client request preparation - Added null assertion operator for enum values within null checks
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| templates/dart/base/utils.twig | Added conditional inclusion logic for non-nullable optional parameters using collection-if syntax |
| templates/flutter/base/utils.twig | Added conditional inclusion logic for non-nullable optional parameters using collection-if syntax |
| templates/dart/lib/src/client_mixin.dart.twig | Removed removeWhere call that filtered null values from params map |
| templates/flutter/lib/src/client_mixin.dart.twig | Removed removeWhere call that filtered null values from params map |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
487b18f to
ecfc5fb
Compare
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
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
templates/dart/lib/src/client_mixin.dart.twig(2 hunks)templates/flutter/lib/src/client_mixin.dart.twig(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- templates/flutter/lib/src/client_mixin.dart.twig
Summary
This PR updates the Dart and Flutter SDK templates to conditionally include non-nullable optional parameters in the request params map only when they are not null, matching the behavior of the Python SDK.
Changes
templates/dart/base/utils.twigmap_parameter macrotemplates/flutter/base/utils.twigmap_parameter macroImplementation Details
Previously, all parameters were always included in the params map, which could lead to unnecessary null values being sent in API requests.
This implementation matches the Python SDK behavior (
templates/python/base/params.twig:15-17and26-28) where optional non-nullable parameters are checked withif not Nonebefore being added toapi_params.Generated Code Example
Before:
After:
Technical Details
!) for enum values when inside null checknot parameter.nullable)not parameter.required)Test Plan
Summary by CodeRabbit