fix: handle nullable types in @Query and @Param parsing#149
Conversation
There was a problem hiding this comment.
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 treatint?/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; |
There was a problem hiding this comment.
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.
| 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'); |
📄 Description
Fixes the generated
_parse<PType>()function to correctly handle nullable types (int?,double?,bool?). Previously,_parse<int?>('42')would fall through to theelsebranch and throwtype 'String' is not a subtype of type 'int?'becauseint? != intin Dart's type system.🔄 Changes Made
_typeOf<T>()helper to the generated code for runtime nullable type comparison_parsetype checks to match both non-nullable and nullable variants (intandint?,doubleanddouble?,boolandbool?)✅ Checklist
🔗 Related Issue
Resolves #93