Skip to content

Commit

Permalink
Ensure that safe enum logic is propogated for all enum generation code (
Browse files Browse the repository at this point in the history
  • Loading branch information
walsha2 authored Nov 13, 2023
1 parent dfaec8c commit 675646d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/src/generators/schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ class SchemaGenerator extends BaseGenerator {
);
if (schema.defaultValue is String &&
(o.values?.contains(schema.defaultValue) ?? false)) {
defaultFallback =
'return $uFactory(${o.title}.${schema.defaultValue.toString().camelCase},);';
final enumValue = _safeEnumValue(schema.defaultValue);
defaultFallback = 'return $uFactory(${o.title}.$enumValue,);';
}
// Place this as first check in fromJson
// So that it takes precedence over string constructor (if present)
Expand Down Expand Up @@ -936,8 +936,7 @@ class SchemaGenerator extends BaseGenerator {
c += "String ${nullable ? '?' : ''} $name,\n\n";
} else {
if (p.defaultValue != null && !required) {
final value = p.defaultValue!.replaceAll('.', '').camelCase;
c += "@Default(${p.ref}.${_safeEnumValue(value)}) ";
c += "@Default(${p.ref}.${_safeEnumValue(p.defaultValue!)}) ";
}
if (required) {
c += "required ";
Expand Down

0 comments on commit 675646d

Please sign in to comment.