openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[REQ] [AspNetCore] Set EmitDefaultValue to true

Open taylor-burns opened this issue 5 years ago • 3 comments

Same Issue as described here: #3274 (comment)

But for the AspNetCore generator

taylor-burns avatar Mar 24 '21 21:03 taylor-burns

Can you please file a PR for the aspnetcore generator or sponsor this change?

wing328 avatar Mar 25 '21 02:03 wing328

Opened a PR which may address this, if your concern is for non-nullable value types (long/int/bool/etc): #11280

hauntingEcho avatar Jan 11 '22 18:01 hauntingEcho

Is there any specific reason why EmitDefaultValue should not be solely based on whether the field is marked as required? I think this is the simplest and most straightforward solution. The logic currently tries to cover all kinds of edge-cases with nullability but if you want to have a value emitted in all cases you should mark it as required imo. Otherwise it is fine to omit.

I can imagine that there are some cases where for example a string is not declared as being nullable so even if it is not required it would need to be interpreted as an empty string by the recipient instead of null. However, this cannot be covered by the EmitDefaultValue property.

Possibly related: I believe the default value emiittance is also not correctly set when using System.Text.Json, because afaik this doesn't care about the DataMember attribute at all.

X-Celcius avatar Nov 04 '25 14:11 X-Celcius