|
1 | 1 | {% macro sub_schema(property) %}{% if property.sub_schema %}{% if property.type == 'array' %}List<{{property.sub_schema | caseUcfirst | overrideIdentifier}}>{% else %}{{property.sub_schema | caseUcfirst | overrideIdentifier}}{% endif %}{% else %}{{property | typeName}}{% endif %}{% if not property.required %}?{% endif %}{% endmacro %} |
2 | 2 | {% macro property_name(definition, property) %}{{ property.name | caseUcfirst | removeDollarSign | escapeKeyword }}{% endmacro %} |
3 | | - |
4 | 3 | using System; |
5 | 4 | using System.Linq; |
6 | 5 | using System.Collections.Generic; |
@@ -42,25 +41,21 @@ namespace {{ spec.title | caseUcfirst }}.Models |
42 | 41 | {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}:{{' '}} |
43 | 42 | {%- if property.sub_schema %} |
44 | 43 | {%- if property.type == 'array' -%} |
45 | | - map["{{ property.name }}"] is JsonElement jsonArray{{ loop.index }} ? jsonArray{{ loop.index }}.Deserialize<List<Dictionary<string, object>>>()!.Select(it => {{ property.sub_schema | caseUcfirst | overrideIdentifier }}.From(map: it)).ToList() : ((IEnumerable<Dictionary<string, object>>)map["{{ property.name }}"]).Select(it => {{ property.sub_schema | caseUcfirst | overrideIdentifier }}.From(map: it)).ToList() |
| 44 | + ((IEnumerable<object>)map["{{ property.name }}"]).Select(it => {{ property.sub_schema | caseUcfirst | overrideIdentifier }}.From(map: (Dictionary<string, object>)it)).ToList() |
46 | 45 | {%- else -%} |
47 | | - {{ property.sub_schema | caseUcfirst | overrideIdentifier }}.From(map: map["{{ property.name }}"] is JsonElement jsonObj{{ loop.index }} ? jsonObj{{ loop.index }}.Deserialize<Dictionary<string, object>>()! : (Dictionary<string, object>)map["{{ property.name }}"]) |
| 46 | + {{ property.sub_schema | caseUcfirst | overrideIdentifier }}.From(map: (Dictionary<string, object>)map["{{ property.name }}"]) |
48 | 47 | {%- endif %} |
49 | 48 | {%- else %} |
50 | 49 | {%- if property.type == 'array' -%} |
51 | | - map["{{ property.name }}"] is JsonElement jsonArrayProp{{ loop.index }} ? jsonArrayProp{{ loop.index }}.Deserialize<{{ property | typeName }}>()! : ({{ property | typeName }})map["{{ property.name }}"] |
| 50 | + ((IEnumerable<object>)map["{{ property.name }}"]).Select(x => {% if property.items.type == "string" %}x?.ToString(){% elseif property.items.type == "integer" %}{% if not property.required %}x == null ? (long?)null : {% endif %}Convert.ToInt64(x){% elseif property.items.type == "number" %}{% if not property.required %}x == null ? (double?)null : {% endif %}Convert.ToDouble(x){% elseif property.items.type == "boolean" %}{% if not property.required %}x == null ? (bool?)null : {% endif %}(bool)x{% else %}x{% endif %}).{% if property.items.type == "string" and property.required %}Where(x => x != null).{% endif %}ToList()! |
52 | 51 | {%- else %} |
53 | 52 | {%- if property.type == "integer" or property.type == "number" %} |
54 | | - {%- if not property.required -%}map["{{ property.name }}"] == null ? null :{% endif %}Convert.To{% if property.type == "integer" %}Int64{% else %}Double{% endif %}(map["{{ property.name }}"]) |
| 53 | + {%- if not property.required -%}map["{{ property.name }}"] == null ? null : {% endif %}Convert.To{% if property.type == "integer" %}Int64{% else %}Double{% endif %}(map["{{ property.name }}"]) |
55 | 54 | {%- else %} |
56 | 55 | {%- if property.type == "boolean" -%} |
57 | 56 | ({{ property | typeName }}{% if not property.required %}?{% endif %})map["{{ property.name }}"] |
58 | | - {%- else %} |
59 | | - {%- if not property.required -%} |
60 | | - map.TryGetValue("{{ property.name }}", out var {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}) ? {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}?.ToString() : null |
61 | | - {%- else -%} |
62 | | - map["{{ property.name }}"].ToString() |
63 | | - {%- endif %} |
| 57 | + {%- else -%} |
| 58 | + map["{{ property.name }}"]{% if not property.required %}?{% endif %}.ToString() |
64 | 59 | {%- endif %} |
65 | 60 | {%~ endif %} |
66 | 61 | {%~ endif %} |
|
0 commit comments