Skip to content

Conversation

@ChiragAgg5k
Copy link
Member

@ChiragAgg5k ChiragAgg5k commented Nov 10, 2025

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

  • Modified templates/dart/base/utils.twig map_parameter macro
  • Modified templates/flutter/base/utils.twig map_parameter macro

Implementation 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-17 and 26-28) where optional non-nullable parameters are checked with if not None before being added to api_params.

Generated Code Example

Before:

final Map<String, dynamic> apiParams = {
  'requiredParam': requiredParam,
  'optionalParam': optionalParam,  // Always included, even if null
};

After:

final Map<String, dynamic> apiParams = {
  'requiredParam': requiredParam,
  if (optionalParam != null) 'optionalParam': optionalParam,  // Only included when not null
};

Technical Details

  • Uses Dart's collection-if syntax for conditional parameter inclusion
  • Adds null assertion operator (!) for enum values when inside null check
  • Only applies to parameters that are both:
    • Not nullable (not parameter.nullable)
    • Not required (not parameter.required)

Test Plan

  • Generate Dart SDK and verify optional params are conditionally included
  • Generate Flutter SDK and verify optional params are conditionally included
  • Verify required parameters are always included
  • Verify nullable parameters are always included

Summary by CodeRabbit

  • Bug Fixes
    • Improved null-checking for non-nullable, non-required parameters so values are only included when present.
    • Fixed request-building behavior so null-valued parameters are preserved rather than dropped, affecting query and body generation.

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,
};
```
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 10, 2025

Walkthrough

Added conditional null-check emission to the map_parameter macro in both Dart and Flutter template utility files so non-nullable, non-required parameters are only emitted when not null, preserving enum formatting. Separately, removed a preprocessing step in both Dart and Flutter client_mixin.dart.twig templates that previously stripped entries with null values from params, so nulls now flow into request construction (query, multipart, and body paths).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Changes span four template files with two distinct concerns (macro emission logic and removal of null-stripping), increasing heterogeneity.
  • Review should focus on:
    • Correctness of the new map_parameter conditional and its effects on emitted request representations (including enum handling and punctuation).
    • Impact of removing the null-filtering step on GET query construction, multipart handling, and body encoding paths.
    • Potential runtime regressions where previously-removed nulls could change request shapes or cause downstream errors.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding conditional inclusion of non-nullable optional parameters in Dart/Flutter SDKs, which is the primary modification across the template files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-dart-flutter-optional-params

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a34b58 and e4f2bef.

📒 Files selected for processing (2)
  • templates/dart/lib/src/client_mixin.dart.twig (0 hunks)
  • templates/flutter/lib/src/client_mixin.dart.twig (0 hunks)
💤 Files with no reviewable changes (2)
  • templates/flutter/lib/src/client_mixin.dart.twig
  • templates/dart/lib/src/client_mixin.dart.twig
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: python (server)
  • GitHub Check: flutter (client)
  • GitHub Check: swift (server)

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants