Skip to content

Commit ebbad72

Browse files
committed
make generated array mappings null-safe
Remove null-forgiving operator (!) from optional array mappings and use null-safe casting to preserve null vs empty semantics in generated models.
1 parent cc2cd62 commit ebbad72

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/SDK/Language/DotNet.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,8 @@ public function getFunctions(): array
514514
if ($property['type'] === 'array') {
515515
$arraySource = $required
516516
? "((IEnumerable<object>){$mapAccess})"
517-
: "({$v} as IEnumerable<object>)";
518-
return "{$arraySource}?.Select(it => {$subSchema}.From(map: (Dictionary<string, object>)it)).ToList()!";
517+
: "({$v} as IEnumerable<object>)?";
518+
return "{$arraySource}.Select(it => {$subSchema}.From(map: (Dictionary<string, object>)it)).ToList()";
519519
} else {
520520
if ($required) {
521521
return "{$subSchema}.From(map: (Dictionary<string, object>){$mapAccess})";
@@ -541,7 +541,7 @@ public function getFunctions(): array
541541
$src = $required ? $mapAccess : $v;
542542
$arraySource = $required
543543
? "((IEnumerable<object>){$src})"
544-
: "({$src} as IEnumerable<object>)";
544+
: "({$src} as IEnumerable<object>)?";
545545

546546
$selectExpression = match($itemsType) {
547547
'string' => 'x.ToString()',
@@ -551,7 +551,7 @@ public function getFunctions(): array
551551
default => 'x'
552552
};
553553

554-
return "{$arraySource}?.Select(x => {$selectExpression}).ToList()!";
554+
return "{$arraySource}.Select(x => {$selectExpression}).ToList()";
555555
}
556556

557557
// Handle integer/number

0 commit comments

Comments
 (0)