@@ -38,14 +38,43 @@ namespace {{ spec.title | caseUcfirst }}.Models
38
38
{%~ endif %}
39
39
}
40
40
41
- public static {{ definition .name | caseUcfirst | overrideIdentifier }} From(Dictionary<string , object > map) => new {{ definition .name | caseUcfirst | overrideIdentifier }}(
41
+ public static {{ definition .name | caseUcfirst | overrideIdentifier }} From(Dictionary<string , object > map) => new {{ definition .name | caseUcfirst | overrideIdentifier }}(
42
42
{%~ for property in definition .properties %}
43
- {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}: {% if property.sub_schema %}{% if property.type == 'array' %}((JArray)map["{{ property.name }}"]).ToObject<List<Dictionary<string, object>>>().Select(it => {{property.sub_schema | caseUcfirst | overrideIdentifier}}.From(map: it)).ToList(){% else %}{{property.sub_schema | caseUcfirst | overrideIdentifier}}.From(map: ((JObject)map["{{ property.name }}"]).ToObject<Dictionary<string, object>>()!){% endif %}{% else %}{% if property.type == 'array' %}((JArray)map["{{ property.name }}"]).ToObject<{{ property | typeName }}>(){% else %}{% if property.type == "integer" or property.type == "number" %}{% if not property.required %}map["{{ property.name }}"] == null ? null : {% endif %}Convert.To{% if property.type == "integer" %}Int64{% else %}Double{% endif %}(map["{{ property.name }}"]){% else %}{% if property.type == "boolean" %}({{ property | typeName }}{% if not property.required %}?{% endif %})map["{{ property.name }}"]{% else %}map{% if not property.required %}.TryGetValue("{{ property.name }}", out var {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}) ? {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}?.ToString() : null{% else %}["{{ property.name }}"]{% if not property.required %}?{% endif %}.ToString(){% endif %}{% endif %}{% endif %}{% endif %}{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %}
44
-
43
+ {{ property .name | caseCamel | escapeKeyword | removeDollarSign }}:
44
+ {%- if property .sub_schema %}
45
+ {%~ if property .type == ' array' %}
46
+ ((JArray)map["{{ property .name }}"])
47
+ .ToObject<List <Dictionary <string , object >>>()
48
+ .Select(it => {{ property .sub_schema | caseUcfirst | overrideIdentifier }}.From(map: it))
49
+ .ToList()
50
+ {%- else %}
51
+ {{ property .sub_schema | caseUcfirst | overrideIdentifier }}.From(
52
+ map: ((JObject)map["{{ property .name }}"])
53
+ .ToObject<Dictionary <string , object >>()!
54
+ )
55
+ {%- endif %}
56
+ {%~ else %}
57
+ {%~ if property .type == ' array' %}
58
+ ((JArray)map["{{ property .name }}"]).ToObject< {{ property | typeName }}>()
59
+ {%~ else %}
60
+ {%~ if property .type == " integer" or property .type == " number" %}
61
+ {%~ if not property .required %}map["{{ property .name }}"] == null ? null : {% endif %} Convert.To{% if property .type == " integer" %}Int64{% else %}Double{% endif %}(map["{{ property .name }}"])
62
+ {%~ else %}
63
+ {%~ if property .type == " boolean" %}
64
+ ({{ property | typeName }}{% if not property .required %}?{% endif %})map["{{ property .name }}"]
65
+ {%~ else %}
66
+ {%~ if not property .required %}map.TryGetValue("{{ property .name }}", out var {{ property .name | caseCamel | escapeKeyword | removeDollarSign }}) ? {{ property .name | caseCamel | escapeKeyword | removeDollarSign }}?.ToString() : null
67
+ {%~ else %} map["{{ property .name }}"].ToString(){% endif %}
68
+ {%- endif %}
69
+ {%~ endif %}
70
+ {%~ endif %}
71
+ {%~ endif %}
72
+ {%- if not loop .last or (loop .last and definition .additionalProperties ) %},
73
+ {%~ endif %}
45
74
{%~ endfor %}
46
- {%~ if definition .additionalProperties %}
47
- data: map
48
- {%~ endif %}
75
+ {%- if definition .additionalProperties %}
76
+ , data: map
77
+ {%- endif ~ %}
49
78
);
50
79
51
80
public Dictionary<string , object ?> ToMap() => new Dictionary<string , object ?>()
0 commit comments