1+ {% set DefinitionClass = definition .name | caseUcfirst | overrideIdentifier %}
12using System;
23using System.Linq;
34using System.Collections.Generic;
@@ -11,7 +12,7 @@ namespace {{ spec.title | caseUcfirst }}.Models
1112 {
1213 {%~ for property in definition .properties %}
1314 [JsonPropertyName("{{ property .name }}")]
14- public {{ sub_schema(property ) | raw }} {{ property_name(definition , property ) | overrideProperty(definition .name ) }} { get; private set; }
15+ public {{ sub_schema(property ) }} {{ property_name(definition , property ) | overrideProperty(definition .name ) }} { get; private set; }
1516
1617 {%~ endfor %}
1718 {%~ if definition .additionalProperties %}
@@ -20,7 +21,7 @@ namespace {{ spec.title | caseUcfirst }}.Models
2021 {%~ endif %}
2122 public {{ DefinitionClass }}(
2223 {%~ for property in definition .properties %}
23- {{ sub_schema(property ) | raw }} {{ property .name | caseCamel | escapeKeyword }}{% if not loop .last or (loop .last and definition .additionalProperties ) %},{% endif %}
24+ {{ sub_schema(property ) }} {{ property .name | caseCamel | escapeKeyword }}{% if not loop .last or (loop .last and definition .additionalProperties ) %},{% endif %}
2425
2526 {%~ endfor %}
2627 {%~ if definition .additionalProperties %}
@@ -40,62 +41,9 @@ namespace {{ spec.title | caseUcfirst }}.Models
4041 {%~ set v = ' v' ~ loop .index0 %}
4142 {%~ set mapAccess = ' map["' ~ property .name ~ ' "]' %}
4243 {{ property .name | caseCamel | escapeKeyword | removeDollarSign }}:{{' ' }}
43- {%- if not property .required -%}map.TryGetValue("{{ property .name }}", out var {{ v }}) ? {% endif %}
44- {%- if property .sub_schema %}
45- {%- if property .type == ' array' -%}
46- {%- if property .required -%}
47- {{ _self.parse_subschema_array (property .sub_schema , mapAccess , true ) }}
48- {%- else -%}
49- {{ _self.parse_subschema_array (property .sub_schema , v , false ) }}
50- {%- endif %}
51- {%- else -%}
52- {%- if property .required -%}
53- {{ property .sub_schema | caseUcfirst | overrideIdentifier }}.From(map: (Dictionary<string , object >){{ mapAccess | raw }})
54- {%- else -%}
55- ({{ v }} as Dictionary<string , object >) is { } obj
56- ? {{ property .sub_schema | caseUcfirst | overrideIdentifier }}.From(map: obj)
57- : null
58- {%- endif %}
59- {%- endif %}
60- {%- elseif property .enum %}
61- {%- set enumName = property ['enumName' ] ?? property .name -%}
62- {%- if not property .required -%}
63- map.TryGetValue("{{ property .name }}", out var enumRaw{{ loop .index }})
64- ? enumRaw{{ loop .index }} == null
65- ? null
66- : new {{ enumName | caseUcfirst }}(enumRaw{{ loop .index }}.ToString()!)
67- : null
68- {%- else -%}
69- new {{ enumName | caseUcfirst }}(map["{{ property .name }}"].ToString()!)
70- {%- endif %}
71- {%- else %}
72- {%- if property .type == ' array' -%}
73- {%- if property .required -%}
74- {{ _self.parse_primitive_array (property .items .type , mapAccess , true ) }}
75- {%- else -%}
76- {{ _self.parse_primitive_array (property .items .type , v , false ) }}
77- {%- endif -%}
78- {%- else %}
79- {%- if property .type == " integer" or property .type == " number" %}
80- {%- if not property .required -%}Convert.To{% if property .type == " integer" %}Int64{% else %}Double{% endif %}({{ v }}){% else %}Convert.To{% if property .type == " integer" %}Int64{% else %}Double{% endif %}({{ mapAccess | raw }}){%- endif %}
81- {%- else %}
82- {%- if property .type == " boolean" -%}
83- {%- if not property .required -%}
84- ({{ property | typeName }}?){{ v }}
85- {%- else -%}
86- ({{ property | typeName }}){{ mapAccess | raw }}
87- {%- endif %}
88- {%- else -%}
89- {%- if not property .required -%}
90- {{ v }}?.ToString()
91- {%- else -%}
92- {{ mapAccess | raw }}.ToString()
93- {%- endif %}
94- {%- endif %}
95- {%~ endif %}
96- {%~ endif %}
97- {%~ endif %}
98- {%- if not property .required %} : null{% endif %}
44+ {%- if not property .required -%}map.TryGetValue("{{ property .name }}", out var {{ v }}) ? {% endif -%}
45+ {{ parse_value(property , mapAccess , v ) }}
46+ {%- if not property .required %} : null{% endif -%}
9947 {%- if not loop .last or (loop .last and definition .additionalProperties ) %},
10048 {%~ endif %}
10149 {%~ endfor %}
0 commit comments