1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-29 15:11:58 +00:00
immich/open-api/templates/mobile/serialization/native/native_class.mustache.patch
2024-09-23 15:41:41 -04:00

60 lines
2.5 KiB
Diff

--- native_class.mustache 2024-09-19 11:41:07.855683995 -0400
+++ native_class_temp.mustache 2024-09-19 11:41:57.113249395 -0400
@@ -91,14 +91,14 @@
{{/isDateTime}}
{{#isNullable}}
} else {
- json[r'{{{baseName}}}'] = null;
+ // json[r'{{{baseName}}}'] = null;
}
{{/isNullable}}
{{^isNullable}}
{{^required}}
{{^defaultValue}}
} else {
- json[r'{{{baseName}}}'] = null;
+ // json[r'{{{baseName}}}'] = null;
}
{{/defaultValue}}
{{/required}}
@@ -111,20 +111,10 @@
/// [value] if it's a [Map], null otherwise.
// ignore: prefer_constructors_over_static_methods
static {{{classname}}}? fromJson(dynamic value) {
+ upgradeDto(value, "{{{classname}}}");
if (value is Map) {
final json = value.cast<String, dynamic>();
- // Ensure that the map contains the required keys.
- // Note 1: the values aren't checked for validity beyond being non-null.
- // Note 2: this code is stripped in release mode!
- assert(() {
- requiredKeys.forEach((key) {
- assert(json.containsKey(key), 'Required key "{{{classname}}}[$key]" is missing from JSON.');
- assert(json[key] != null, 'Required key "{{{classname}}}[$key]" has a null value in JSON.');
- });
- return true;
- }());
-
return {{{classname}}}(
{{#vars}}
{{#isDateTime}}
@@ -215,6 +205,10 @@
? {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}
: {{/isNullable}}{{{datatypeWithEnum}}}.parse('${json[r'{{{baseName}}}']}'),
{{/isNumber}}
+ {{#isDouble}}
+ {{{name}}}: (mapValueOfType<num>(json, r'{{{baseName}}}'){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}}).toDouble(),
+ {{/isDouble}}
+ {{^isDouble}}
{{^isNumber}}
{{^isEnum}}
{{{name}}}: mapValueOfType<{{{datatypeWithEnum}}}>(json, r'{{{baseName}}}'){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}},
@@ -223,6 +217,7 @@
{{{name}}}: {{{enumName}}}.fromJson(json[r'{{{baseName}}}']){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}},
{{/isEnum}}
{{/isNumber}}
+ {{/isDouble}}
{{/isMap}}
{{/isArray}}
{{/complexType}}