Skip to content

fix: handle nullable types in @Query and @Param parsing#149

Merged
Barba2k2 merged 1 commit intomainfrom
fix/nullable-query-param-parsing
Mar 8, 2026
Merged

fix: handle nullable types in @Query and @Param parsing#149
Barba2k2 merged 1 commit intomainfrom
fix/nullable-query-param-parsing

Conversation

@Barba2k2
Copy link
Copy Markdown
Contributor

@Barba2k2 Barba2k2 commented Mar 8, 2026

📄 Description

Fixes the generated _parse<PType>() function to correctly handle nullable types (int?, double?, bool?). Previously, _parse<int?>('42') would fall through to the else branch and throw type 'String' is not a subtype of type 'int?' because int? != int in Dart's type system.

🔄 Changes Made

  • Added _typeOf<T>() helper to the generated code for runtime nullable type comparison
  • Extended _parse type checks to match both non-nullable and nullable variants (int and int?, double and double?, bool and bool?)

✅ Checklist

  • Tests have been added or updated.
  • Documentation has been updated (if necessary).
  • Code review completed.

🔗 Related Issue

Resolves #93

@Barba2k2 Barba2k2 requested a review from Copilot March 8, 2026 02:08
@Barba2k2 Barba2k2 merged commit 47eb84a into main Mar 8, 2026
2 checks passed
Copy link
Copy Markdown

Copilot AI left a 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 backend generated vaden_application.dart runtime parsing helper to correctly parse nullable query/path/header parameter types (e.g., int?, double?, bool?) by adding a _typeOf<T>() helper and extending _parse<PType>() type checks to match both nullable and non-nullable variants.

Changes:

  • Add _typeOf<T>() helper to enable runtime comparison against nullable types.
  • Update _parse<PType>() to treat int?/double?/bool? the same as their non-nullable counterparts during parsing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return double.parse(value) as PType;
} else if(PType == bool) {
} else if (PType == bool || PType == _typeOf<bool?>()) {
return bool.parse(value) as PType;
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nullable-type parsing behavior change here is not covered by a regression test. Since this affects generated request parsing for @Query/@param across all apps, please add a test that exercises a generated route/controller with int?/double?/bool? query/param values (including null and a valid value) to prevent regressions.

Suggested change
return bool.parse(value) as PType;
final lower = value.toLowerCase();
if (lower == 'true') {
return true as PType;
} else if (lower == 'false') {
return false as PType;
}
throw FormatException('Invalid bool: \$value');

Copilot uses AI. Check for mistakes.
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.

[BUG] Nullable query or param annotated data types are not working.

2 participants