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

* add serialization test, fix nulllable reuqired

* remove vs folder
This commit is contained in:
William Cheng 2019-01-05 18:54:29 +08:00 committed by GitHub
parent b931da2909
commit 8f561f1ef3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 27 additions and 24 deletions

2
.gitignore vendored
View File

@ -27,6 +27,7 @@ packages/
.packages .packages
.vagrant/ .vagrant/
.vscode/ .vscode/
**/.vs
.settings .settings
@ -128,7 +129,6 @@ samples/client/petstore/swift3/**/SwaggerClientTests/Podfile.lock
# C# # C#
*.csproj.user *.csproj.user
samples/client/petstore/csharp/SwaggerClient/IO.Swagger.userprefs 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/obj
samples/client/petstore/csharp/SwaggerClientTest/bin samples/client/petstore/csharp/SwaggerClientTest/bin
samples/client/petstore/csharp/SwaggerClientTest/packages samples/client/petstore/csharp/SwaggerClientTest/packages

View File

@ -31,7 +31,7 @@
{{#description}} {{#description}}
/// <value>{{description}}</value> /// <value>{{description}}</value>
{{/description}} {{/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; } public {{#complexType}}{{{complexType}}}{{/complexType}}{{^complexType}}{{{datatypeWithEnum}}}{{/complexType}}{{^isContainer}}{{^required}}?{{/required}}{{/isContainer}} {{name}} { get; set; }
{{/isEnum}} {{/isEnum}}
{{/vars}} {{/vars}}
@ -70,12 +70,16 @@
{ {
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}; this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
} }
{{/isEnum}} {{/isEnum}}
{{#isEnum}} {{#isEnum}}
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}; this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/isEnum}} {{/isEnum}}
{{/required}} {{/required}}
{{/isNullable}} {{/isNullable}}
{{#isNullable}}
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/isNullable}}
{{/isReadOnly}} {{/isReadOnly}}
{{/isInherited}} {{/isInherited}}
{{/vars}} {{/vars}}
@ -110,7 +114,7 @@
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}} /// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
/// </summary>{{#description}} /// </summary>{{#description}}
/// <value>{{description}}</value>{{/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}} [JsonConverter(typeof(OpenAPIDateConverter))]{{/isDate}}
public {{{dataType}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; } public {{{dataType}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; }

View File

@ -1,21 +0,0 @@
<Properties StartupConfiguration="{19F1DEBC-DE5E-4517-8062-F000CD499087}|Unit Tests">
<MonoDevelop.Ide.Workbench ActiveDocument="src/Org.OpenAPITools.Test/Model/PetTests.cs">
<Files>
<File FileName="src/Org.OpenAPITools.Test/Model/PetTests.cs" Line="159" Column="29" />
</Files>
<Pads>
<Pad Id="MonoDevelop.UnitTesting.TestPad">
<State name="__root__">
<Node name="Org.OpenAPITools" expanded="True" selected="True" />
</State>
</Pad>
</Pads>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>
<MonoDevelop.Ide.ItemProperties.Org.OpenAPITools.Test PreferredExecutionTarget="MonoDevelop.Default" />
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
<MultiItemStartupConfigurations />
</Properties>

View File

@ -116,6 +116,17 @@ namespace Org.OpenAPITools.Test
// TODO unit test for the property 'Status' // 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> /// <summary>
/// Test Equal /// Test Equal
/// </summary> /// </summary>

View File

@ -57,6 +57,7 @@ namespace Org.OpenAPITools.Model
{ {
this.ClassName = className; this.ClassName = className;
} }
// use default value if no "color" provided // use default value if no "color" provided
if (color == null) if (color == null)
{ {

View File

@ -53,6 +53,7 @@ namespace Org.OpenAPITools.Model
{ {
this.Name = name; this.Name = name;
} }
this.Id = id; this.Id = id;
} }

View File

@ -64,6 +64,7 @@ namespace Org.OpenAPITools.Model
{ {
this.Number = number; this.Number = number;
} }
// to ensure "_byte" is required (not null) // to ensure "_byte" is required (not null)
if (_byte == null) if (_byte == null)
{ {
@ -73,6 +74,7 @@ namespace Org.OpenAPITools.Model
{ {
this.Byte = _byte; this.Byte = _byte;
} }
// to ensure "date" is required (not null) // to ensure "date" is required (not null)
if (date == null) if (date == null)
{ {
@ -82,6 +84,7 @@ namespace Org.OpenAPITools.Model
{ {
this.Date = date; this.Date = date;
} }
// to ensure "password" is required (not null) // to ensure "password" is required (not null)
if (password == null) if (password == null)
{ {
@ -91,6 +94,7 @@ namespace Org.OpenAPITools.Model
{ {
this.Password = password; this.Password = password;
} }
this.Integer = integer; this.Integer = integer;
this.Int32 = int32; this.Int32 = int32;
this.Int64 = int64; this.Int64 = int64;

View File

@ -53,6 +53,7 @@ namespace Org.OpenAPITools.Model
{ {
this._Name = name; this._Name = name;
} }
this.Property = property; this.Property = property;
} }

View File

@ -90,6 +90,7 @@ namespace Org.OpenAPITools.Model
{ {
this.Name = name; this.Name = name;
} }
// to ensure "photoUrls" is required (not null) // to ensure "photoUrls" is required (not null)
if (photoUrls == null) if (photoUrls == null)
{ {
@ -99,6 +100,7 @@ namespace Org.OpenAPITools.Model
{ {
this.PhotoUrls = photoUrls; this.PhotoUrls = photoUrls;
} }
this.Id = id; this.Id = id;
this.Category = category; this.Category = category;
this.Tags = tags; this.Tags = tags;