[csharp-netcore]For conditionalSerialization do not initialize the default value. (#10551)

* added allowDefaultValue flag for conditionSerialization

* update doc

* club the allowDefaultValue flag with ConditionSerialzation.

* fixed the tabs space.

* fixed the tabs space.

* fixed the tabs space.

* update samples, docs

Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
Ghufran Zahidi
2021-10-12 13:44:14 +05:30
committed by GitHub
parent 6e14fc411f
commit b4206ad249
6 changed files with 3 additions and 7 deletions

View File

@@ -266,7 +266,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
addSwitch(CodegenConstants.OPTIONAL_EMIT_DEFAULT_VALUES,
CodegenConstants.OPTIONAL_EMIT_DEFAULT_VALUES_DESC,
this.optionalEmitDefaultValuesFlag);
addSwitch(CodegenConstants.OPTIONAL_CONDITIONAL_SERIALIZATION,
CodegenConstants.OPTIONAL_CONDITIONAL_SERIALIZATION_DESC,
this.conditionalSerialization);

View File

@@ -162,6 +162,7 @@
{{^isReadOnly}}
{{^required}}
{{#defaultValue}}
{{^conditionalSerialization}}
{{^vendorExtensions.x-csharp-value-type}}
// use default value if no "{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}" provided
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} ?? {{{defaultValue}}};
@@ -169,6 +170,7 @@
{{#vendorExtensions.x-csharp-value-type}}
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/vendorExtensions.x-csharp-value-type}}
{{/conditionalSerialization}}
{{/defaultValue}}
{{^defaultValue}}
{{^conditionalSerialization}}

View File

@@ -56,8 +56,6 @@ namespace Org.OpenAPITools.Model
throw new ArgumentNullException("className is a required property for Animal and cannot be null");
}
this._ClassName = className;
// use default value if no "color" provided
this.Color = color ?? "red";
this.AdditionalProperties = new Dictionary<string, object>();
}

View File

@@ -80,7 +80,6 @@ namespace Org.OpenAPITools.Model
public ChildCatAllOf(string name = default(string), PetTypeEnum? petType = PetTypeEnum.ChildCat)
{
this._Name = name;
this.PetType = petType;
this.AdditionalProperties = new Dictionary<string, object>();
}

View File

@@ -38,8 +38,6 @@ namespace Org.OpenAPITools.Model
/// <param name="bar">bar (default to &quot;bar&quot;).</param>
public Foo(string bar = "bar")
{
// use default value if no "bar" provided
this.Bar = bar ?? "bar";
this.AdditionalProperties = new Dictionary<string, object>();
}

View File

@@ -102,7 +102,6 @@ namespace Org.OpenAPITools.Model
this._Quantity = quantity;
this._ShipDate = shipDate;
this._Status = status;
this.Complete = complete;
this.AdditionalProperties = new Dictionary<string, object>();
}