Permalink
Browse files

[C#][Refactor] Fix nullable required property in the constructor (#1819)

* add serialization test, fix nulllable reuqired

* remove vs folder
  • Loading branch information...
wing328 committed Jan 5, 2019
1 parent b931da2 commit 8f561f1ef3045f4780032d673e7466ec240c56dc
@@ -27,6 +27,7 @@ packages/
.packages
.vagrant/
.vscode/
**/.vs

.settings

@@ -128,7 +129,6 @@ samples/client/petstore/swift3/**/SwaggerClientTests/Podfile.lock
# C#
*.csproj.user
samples/client/petstore/csharp/SwaggerClient/IO.Swagger.userprefs
samples/client/petstore/csharp/SwaggerClientTest/.vs
samples/client/petstore/csharp/SwaggerClientTest/obj
samples/client/petstore/csharp/SwaggerClientTest/bin
samples/client/petstore/csharp/SwaggerClientTest/packages
@@ -31,7 +31,7 @@
{{#description}}
/// <value>{{description}}</value>
{{/description}}
[DataMember(Name="{{baseName}}", EmitDefaultValue={{emitDefaultValue}})]
[DataMember(Name="{{baseName}}", EmitDefaultValue={{#isNullable}}true{{/isNullable}}{{^isNullable}}{{emitDefaultValue}}{{/isNullable}})]
public {{#complexType}}{{{complexType}}}{{/complexType}}{{^complexType}}{{{datatypeWithEnum}}}{{/complexType}}{{^isContainer}}{{^required}}?{{/required}}{{/isContainer}} {{name}} { get; set; }
{{/isEnum}}
{{/vars}}
@@ -70,12 +70,16 @@
{
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
}

{{/isEnum}}
{{#isEnum}}
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/isEnum}}
{{/required}}
{{/isNullable}}
{{#isNullable}}
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/isNullable}}
{{/isReadOnly}}
{{/isInherited}}
{{/vars}}
@@ -110,7 +114,7 @@
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
/// </summary>{{#description}}
/// <value>{{description}}</value>{{/description}}
[DataMember(Name="{{baseName}}", EmitDefaultValue={{emitDefaultValue}})]{{#isDate}}
[DataMember(Name="{{baseName}}", EmitDefaultValue={{#isNullable}}true{{/isNullable}}{{^isNullable}}{{emitDefaultValue}}{{/isNullable}})]{{#isDate}}
[JsonConverter(typeof(OpenAPIDateConverter))]{{/isDate}}
public {{{dataType}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; }

This file was deleted.

Oops, something went wrong.
@@ -116,6 +116,17 @@ public void StatusTest()
// TODO unit test for the property 'Status'
}

/// <summary>
/// Test serialization
/// </summary>
[Test()]
public void TestSerialization()
{
// create pet
Pet p1 = new Pet(name: "Csharp test", photoUrls: new List<string> { "http://petstore.com/csharp_test" });
Assert.AreEqual("{\"name\":\"Csharp test\",\"photoUrls\":[\"http://petstore.com/csharp_test\"]}", JsonConvert.SerializeObject(p1));
}

/// <summary>
/// Test Equal
/// </summary>
@@ -57,6 +57,7 @@ public Animal(string className = default(string), string color = "red")
{
this.ClassName = className;
}

// use default value if no "color" provided
if (color == null)
{
@@ -53,6 +53,7 @@ public Category(long id = default(long), string name = "default-name")
{
this.Name = name;
}

this.Id = id;
}

@@ -64,6 +64,7 @@ public FormatTest(int integer = default(int), int int32 = default(int), long int
{
this.Number = number;
}

// to ensure "_byte" is required (not null)
if (_byte == null)
{
@@ -73,6 +74,7 @@ public FormatTest(int integer = default(int), int int32 = default(int), long int
{
this.Byte = _byte;
}

// to ensure "date" is required (not null)
if (date == null)
{
@@ -82,6 +84,7 @@ public FormatTest(int integer = default(int), int int32 = default(int), long int
{
this.Date = date;
}

// to ensure "password" is required (not null)
if (password == null)
{
@@ -91,6 +94,7 @@ public FormatTest(int integer = default(int), int int32 = default(int), long int
{
this.Password = password;
}

this.Integer = integer;
this.Int32 = int32;
this.Int64 = int64;
@@ -53,6 +53,7 @@ public Name(int name = default(int), string property = default(string))
{
this._Name = name;
}

this.Property = property;
}

@@ -90,6 +90,7 @@ public Pet(long id = default(long), Category category = default(Category), strin
{
this.Name = name;
}

// to ensure "photoUrls" is required (not null)
if (photoUrls == null)
{
@@ -99,6 +100,7 @@ public Pet(long id = default(long), Category category = default(Category), strin
{
this.PhotoUrls = photoUrls;
}

this.Id = id;
this.Category = category;
this.Tags = tags;

0 comments on commit 8f561f1

Please sign in to comment.