mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-06 10:35:25 +00:00
[C#][Refactor] Fix nullable required property in the constructor (#1819)
* add serialization test, fix nulllable reuqired * remove vs folder
This commit is contained in:
parent
b931da2909
commit
8f561f1ef3
2
.gitignore
vendored
2
.gitignore
vendored
@ -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; }
|
||||
|
||||
|
@ -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>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -116,6 +116,17 @@ namespace Org.OpenAPITools.Test
|
||||
// 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 @@ namespace Org.OpenAPITools.Model
|
||||
{
|
||||
this.ClassName = className;
|
||||
}
|
||||
|
||||
// use default value if no "color" provided
|
||||
if (color == null)
|
||||
{
|
||||
|
@ -53,6 +53,7 @@ namespace Org.OpenAPITools.Model
|
||||
{
|
||||
this.Name = name;
|
||||
}
|
||||
|
||||
this.Id = id;
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,7 @@ namespace Org.OpenAPITools.Model
|
||||
{
|
||||
this.Number = number;
|
||||
}
|
||||
|
||||
// to ensure "_byte" is required (not null)
|
||||
if (_byte == null)
|
||||
{
|
||||
@ -73,6 +74,7 @@ namespace Org.OpenAPITools.Model
|
||||
{
|
||||
this.Byte = _byte;
|
||||
}
|
||||
|
||||
// to ensure "date" is required (not null)
|
||||
if (date == null)
|
||||
{
|
||||
@ -82,6 +84,7 @@ namespace Org.OpenAPITools.Model
|
||||
{
|
||||
this.Date = date;
|
||||
}
|
||||
|
||||
// to ensure "password" is required (not null)
|
||||
if (password == null)
|
||||
{
|
||||
@ -91,6 +94,7 @@ namespace Org.OpenAPITools.Model
|
||||
{
|
||||
this.Password = password;
|
||||
}
|
||||
|
||||
this.Integer = integer;
|
||||
this.Int32 = int32;
|
||||
this.Int64 = int64;
|
||||
|
@ -53,6 +53,7 @@ namespace Org.OpenAPITools.Model
|
||||
{
|
||||
this._Name = name;
|
||||
}
|
||||
|
||||
this.Property = property;
|
||||
}
|
||||
|
||||
|
@ -90,6 +90,7 @@ namespace Org.OpenAPITools.Model
|
||||
{
|
||||
this.Name = name;
|
||||
}
|
||||
|
||||
// to ensure "photoUrls" is required (not null)
|
||||
if (photoUrls == null)
|
||||
{
|
||||
@ -99,6 +100,7 @@ namespace Org.OpenAPITools.Model
|
||||
{
|
||||
this.PhotoUrls = photoUrls;
|
||||
}
|
||||
|
||||
this.Id = id;
|
||||
this.Category = category;
|
||||
this.Tags = tags;
|
||||
|
Loading…
Reference in New Issue
Block a user