Skip to content

Commit ce25622

Browse files
committed
Merge branch 'fix-nullable-properties-not-read' of https://github.com/janrhijn/openapi-generator into janrhijn-fix-nullable-properties-not-read
2 parents 73b6b70 + 5451e54 commit ce25622

File tree

554 files changed

+1845
-3690
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

554 files changed

+1845
-3690
lines changed

modules/openapi-generator/src/main/resources/csharp/libraries/generichost/JsonConverter.mustache

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -185,52 +185,43 @@
185185
{{/isMap}}
186186
{{/isString}}
187187
{{#isBoolean}}
188-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
189-
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}utf8JsonReader.GetBoolean());
188+
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}utf8JsonReader.TokenType == JsonTokenType.Null ? (bool?)null : utf8JsonReader.GetBoolean());
190189
{{/isBoolean}}
191190
{{#isNumeric}}
192191
{{^isEnum}}
193192
{{#isDouble}}
194-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
195-
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}utf8JsonReader.GetDouble());
193+
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}utf8JsonReader.TokenType == JsonTokenType.Null ? (double?)null : utf8JsonReader.GetDouble());
196194
{{/isDouble}}
197195
{{#isDecimal}}
198-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
199-
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}utf8JsonReader.GetDecimal());
196+
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}utf8JsonReader.TokenType == JsonTokenType.Null ? (decimal?)null : utf8JsonReader.GetDecimal());
200197
{{/isDecimal}}
201198
{{#isFloat}}
202-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
203-
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}(float)utf8JsonReader.GetDouble());
199+
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}utf8JsonReader.TokenType == JsonTokenType.Null ? (float?)null : (float)utf8JsonReader.GetDouble());
204200
{{/isFloat}}
205201
{{#isLong}}
206-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
207-
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}utf8JsonReader.Get{{#vendorExtensions.x-unsigned}}U{{/vendorExtensions.x-unsigned}}Int64());
202+
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}utf8JsonReader.TokenType == JsonTokenType.Null ? ({{#vendorExtensions.x-unsigned}}u{{/vendorExtensions.x-unsigned}}long?)null : utf8JsonReader.Get{{#vendorExtensions.x-unsigned}}U{{/vendorExtensions.x-unsigned}}Int64());
208203
{{/isLong}}
209204
{{^isLong}}
210205
{{^isFloat}}
211206
{{^isDecimal}}
212207
{{^isDouble}}
213-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
214-
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}utf8JsonReader.Get{{#vendorExtensions.x-unsigned}}U{{/vendorExtensions.x-unsigned}}Int32());
208+
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}utf8JsonReader.TokenType == JsonTokenType.Null ? ({{#vendorExtensions.x-unsigned}}u{{/vendorExtensions.x-unsigned}}int?)null : utf8JsonReader.Get{{#vendorExtensions.x-unsigned}}U{{/vendorExtensions.x-unsigned}}Int32());
215209
{{/isDouble}}
216210
{{/isDecimal}}
217211
{{/isFloat}}
218212
{{/isLong}}
219213
{{/isEnum}}
220214
{{/isNumeric}}
221215
{{#isDate}}
222-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
223-
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}JsonSerializer.Deserialize<{{#supportsDateOnly}}DateOnly{{/supportsDateOnly}}{{^supportsDateOnly}}DateTime{{/supportsDateOnly}}{{#isNullable}}?{{/isNullable}}>(ref utf8JsonReader, jsonSerializerOptions));
216+
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}JsonSerializer.Deserialize<{{#supportsDateOnly}}DateOnly{{/supportsDateOnly}}{{^supportsDateOnly}}DateTime{{/supportsDateOnly}}{{#isNullable}}?{{/isNullable}}>(ref utf8JsonReader, jsonSerializerOptions));
224217
{{/isDate}}
225218
{{#isDateTime}}
226-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
227-
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}JsonSerializer.Deserialize<DateTime{{#isNullable}}?{{/isNullable}}>(ref utf8JsonReader, jsonSerializerOptions));
219+
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}JsonSerializer.Deserialize<DateTime{{#isNullable}}?{{/isNullable}}>(ref utf8JsonReader, jsonSerializerOptions));
228220
{{/isDateTime}}
229221
{{#isEnum}}
230222
{{^isMap}}
231223
{{#isNumeric}}
232-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
233-
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}({{#isInnerEnum}}{{classname}}.{{/isInnerEnum}}{{{datatypeWithEnum}}})utf8JsonReader.Get{{#vendorExtensions.x-unsigned}}U{{/vendorExtensions.x-unsigned}}Int32());
224+
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}utf8JsonReader.TokenType == JsonTokenType.Null ? ({{#isInnerEnum}}{{classname}}.{{/isInnerEnum}}{{{datatypeWithEnum}}}?)null : ({{#isInnerEnum}}{{classname}}.{{/isInnerEnum}}{{{datatypeWithEnum}}})utf8JsonReader.Get{{#vendorExtensions.x-unsigned}}U{{/vendorExtensions.x-unsigned}}Int32());
234225
{{/isNumeric}}
235226
{{^isNumeric}}
236227
string{{nrt?}} {{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}RawValue = utf8JsonReader.GetString();
@@ -246,8 +237,7 @@
246237
{{/isMap}}
247238
{{/isEnum}}
248239
{{#isUuid}}
249-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
250-
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}utf8JsonReader.GetGuid());
240+
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}utf8JsonReader.TokenType == JsonTokenType.Null ? (Guid?)null : utf8JsonReader.GetGuid());
251241
{{/isUuid}}
252242
{{^isUuid}}
253243
{{^isEnum}}
@@ -256,8 +246,7 @@
256246
{{^isNumeric}}
257247
{{^isDate}}
258248
{{^isDateTime}}
259-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
260-
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}JsonSerializer.Deserialize<{{{datatypeWithEnum}}}>(ref utf8JsonReader, jsonSerializerOptions){{^isNullable}}{{nrt!}}{{/isNullable}});
249+
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}JsonSerializer.Deserialize<{{{datatypeWithEnum}}}>(ref utf8JsonReader, jsonSerializerOptions){{^isNullable}}{{nrt!}}{{/isNullable}});
261250
{{/isDateTime}}
262251
{{/isDate}}
263252
{{/isNumeric}}

samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Adult.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ public override Adult Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert
115115
switch (localVarJsonPropertyName)
116116
{
117117
case "children":
118-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
119-
children = new Option<List<Child>>(JsonSerializer.Deserialize<List<Child>>(ref utf8JsonReader, jsonSerializerOptions));
118+
children = new Option<List<Child>>(JsonSerializer.Deserialize<List<Child>>(ref utf8JsonReader, jsonSerializerOptions));
120119
break;
121120
case "firstName":
122121
firstName = new Option<string>(utf8JsonReader.GetString());

samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Child.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ public override Child Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert
132132
switch (localVarJsonPropertyName)
133133
{
134134
case "age":
135-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
136-
age = new Option<int?>(utf8JsonReader.GetInt32());
135+
age = new Option<int?>(utf8JsonReader.TokenType == JsonTokenType.Null ? (int?)null : utf8JsonReader.GetInt32());
137136
break;
138137
case "firstName":
139138
firstName = new Option<string>(utf8JsonReader.GetString());
@@ -145,8 +144,7 @@ public override Child Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert
145144
type = new Option<string>(utf8JsonReader.GetString());
146145
break;
147146
case "boosterSeat":
148-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
149-
boosterSeat = new Option<bool?>(utf8JsonReader.GetBoolean());
147+
boosterSeat = new Option<bool?>(utf8JsonReader.TokenType == JsonTokenType.Null ? (bool?)null : utf8JsonReader.GetBoolean());
150148
break;
151149
default:
152150
break;

samples/client/petstore/csharp/generichost/net4.7/AnyOf/src/Org.OpenAPITools/Model/Banana.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ public override Banana Read(ref Utf8JsonReader utf8JsonReader, Type typeToConver
126126
switch (localVarJsonPropertyName)
127127
{
128128
case "count":
129-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
130-
count = new Option<decimal?>(utf8JsonReader.GetDecimal());
129+
count = new Option<decimal?>(utf8JsonReader.TokenType == JsonTokenType.Null ? (decimal?)null : utf8JsonReader.GetDecimal());
131130
break;
132131
default:
133132
break;

samples/client/petstore/csharp/generichost/net4.7/AnyOfNoCompare/src/Org.OpenAPITools/Model/Banana.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ public override Banana Read(ref Utf8JsonReader utf8JsonReader, Type typeToConver
125125
switch (localVarJsonPropertyName)
126126
{
127127
case "count":
128-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
129-
count = new Option<decimal?>(utf8JsonReader.GetDecimal());
128+
count = new Option<decimal?>(utf8JsonReader.TokenType == JsonTokenType.Null ? (decimal?)null : utf8JsonReader.GetDecimal());
130129
break;
131130
default:
132131
break;

samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Activity.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ public override Activity Read(ref Utf8JsonReader utf8JsonReader, Type typeToConv
126126
switch (localVarJsonPropertyName)
127127
{
128128
case "activity_outputs":
129-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
130-
activityOutputs = new Option<Dictionary<string, List<ActivityOutputElementRepresentation>>>(JsonSerializer.Deserialize<Dictionary<string, List<ActivityOutputElementRepresentation>>>(ref utf8JsonReader, jsonSerializerOptions));
129+
activityOutputs = new Option<Dictionary<string, List<ActivityOutputElementRepresentation>>>(JsonSerializer.Deserialize<Dictionary<string, List<ActivityOutputElementRepresentation>>>(ref utf8JsonReader, jsonSerializerOptions));
131130
break;
132131
default:
133132
break;

samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/ActivityOutputElementRepresentation.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ public override ActivityOutputElementRepresentation Read(ref Utf8JsonReader utf8
146146
prop1 = new Option<string>(utf8JsonReader.GetString());
147147
break;
148148
case "prop2":
149-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
150-
prop2 = new Option<Object>(JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions));
149+
prop2 = new Option<Object>(JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions));
151150
break;
152151
default:
153152
break;

samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/AdditionalPropertiesClass.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -246,36 +246,28 @@ public override AdditionalPropertiesClass Read(ref Utf8JsonReader utf8JsonReader
246246
switch (localVarJsonPropertyName)
247247
{
248248
case "anytype_1":
249-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
250-
anytype1 = new Option<Object>(JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions));
249+
anytype1 = new Option<Object>(JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions));
251250
break;
252251
case "empty_map":
253-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
254-
emptyMap = new Option<Object>(JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions));
252+
emptyMap = new Option<Object>(JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions));
255253
break;
256254
case "map_of_map_property":
257-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
258-
mapOfMapProperty = new Option<Dictionary<string, Dictionary<string, string>>>(JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(ref utf8JsonReader, jsonSerializerOptions));
255+
mapOfMapProperty = new Option<Dictionary<string, Dictionary<string, string>>>(JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(ref utf8JsonReader, jsonSerializerOptions));
259256
break;
260257
case "map_property":
261-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
262-
mapProperty = new Option<Dictionary<string, string>>(JsonSerializer.Deserialize<Dictionary<string, string>>(ref utf8JsonReader, jsonSerializerOptions));
258+
mapProperty = new Option<Dictionary<string, string>>(JsonSerializer.Deserialize<Dictionary<string, string>>(ref utf8JsonReader, jsonSerializerOptions));
263259
break;
264260
case "map_with_undeclared_properties_anytype_1":
265-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
266-
mapWithUndeclaredPropertiesAnytype1 = new Option<Object>(JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions));
261+
mapWithUndeclaredPropertiesAnytype1 = new Option<Object>(JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions));
267262
break;
268263
case "map_with_undeclared_properties_anytype_2":
269-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
270-
mapWithUndeclaredPropertiesAnytype2 = new Option<Object>(JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions));
264+
mapWithUndeclaredPropertiesAnytype2 = new Option<Object>(JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions));
271265
break;
272266
case "map_with_undeclared_properties_anytype_3":
273-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
274-
mapWithUndeclaredPropertiesAnytype3 = new Option<Dictionary<string, Object>>(JsonSerializer.Deserialize<Dictionary<string, Object>>(ref utf8JsonReader, jsonSerializerOptions));
267+
mapWithUndeclaredPropertiesAnytype3 = new Option<Dictionary<string, Object>>(JsonSerializer.Deserialize<Dictionary<string, Object>>(ref utf8JsonReader, jsonSerializerOptions));
275268
break;
276269
case "map_with_undeclared_properties_string":
277-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
278-
mapWithUndeclaredPropertiesString = new Option<Dictionary<string, string>>(JsonSerializer.Deserialize<Dictionary<string, string>>(ref utf8JsonReader, jsonSerializerOptions));
270+
mapWithUndeclaredPropertiesString = new Option<Dictionary<string, string>>(JsonSerializer.Deserialize<Dictionary<string, string>>(ref utf8JsonReader, jsonSerializerOptions));
279271
break;
280272
default:
281273
break;

samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/ApiResponse.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ public override ApiResponse Read(ref Utf8JsonReader utf8JsonReader, Type typeToC
160160
switch (localVarJsonPropertyName)
161161
{
162162
case "code":
163-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
164-
code = new Option<int?>(utf8JsonReader.GetInt32());
163+
code = new Option<int?>(utf8JsonReader.TokenType == JsonTokenType.Null ? (int?)null : utf8JsonReader.GetInt32());
165164
break;
166165
case "message":
167166
message = new Option<string>(utf8JsonReader.GetString());

samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/AppleReq.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ public override AppleReq Read(ref Utf8JsonReader utf8JsonReader, Type typeToConv
132132
cultivar = new Option<string>(utf8JsonReader.GetString());
133133
break;
134134
case "mealy":
135-
if (utf8JsonReader.TokenType != JsonTokenType.Null)
136-
mealy = new Option<bool?>(utf8JsonReader.GetBoolean());
135+
mealy = new Option<bool?>(utf8JsonReader.TokenType == JsonTokenType.Null ? (bool?)null : utf8JsonReader.GetBoolean());
137136
break;
138137
default:
139138
break;

0 commit comments

Comments
 (0)