Skip to content

Commit

Permalink
Emit default values for aspnetcore 3 value types (OpenAPITools#11280)
Browse files Browse the repository at this point in the history
Fixes OpenAPITools#10772 for aspnetcore 3+

This allows numbers to be set to zero, and booleans to be set to false.
It may make sense to port this fix to the other C# generators,
though it was partially fixed (for booleans only) in the netcore client in PR9042.
  • Loading branch information
hauntingEcho authored and rk0n committed Apr 24, 2022
1 parent bfc9f2e commit 10d0dbf
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace {{modelPackage}}
[MinLength({{minLength}})]{{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}}
[MaxLength({{.}})]{{/maxLength}}{{/minLength}}{{#minimum}}{{#maximum}}
[Range({{minimum}}, {{maximum}})]{{/maximum}}{{/minimum}}
[DataMember(Name="{{baseName}}", EmitDefaultValue={{#isNullable}}true{{/isNullable}}{{^isNullable}}false{{/isNullable}})]
[DataMember(Name="{{baseName}}", EmitDefaultValue={{#isNullable}}true{{/isNullable}}{{^isNullable}}{{#vendorExtensions.x-is-value-type}}true{{/vendorExtensions.x-is-value-type}}{{^vendorExtensions.x-is-value-type}}false{{/vendorExtensions.x-is-value-type}}{{/isNullable}})]
{{#isEnum}}
public {{{datatypeWithEnum}}}{{#isNullable}}?{{/isNullable}} {{name}} { get; set; }{{#defaultValue}} = {{{.}}};{{/defaultValue}}
{{/isEnum}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class ApiResponse : IEquatable<ApiResponse>
/// <summary>
/// Gets or Sets Code
/// </summary>
[DataMember(Name="code", EmitDefaultValue=false)]
[DataMember(Name="code", EmitDefaultValue=true)]
public int Code { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class Category : IEquatable<Category>
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
[DataMember(Name="id", EmitDefaultValue=true)]
public long Id { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ public partial class Order : IEquatable<Order>
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
[DataMember(Name="id", EmitDefaultValue=true)]
public long Id { get; set; }

/// <summary>
/// Gets or Sets PetId
/// </summary>
[DataMember(Name="petId", EmitDefaultValue=false)]
[DataMember(Name="petId", EmitDefaultValue=true)]
public long PetId { get; set; }

/// <summary>
/// Gets or Sets Quantity
/// </summary>
[DataMember(Name="quantity", EmitDefaultValue=false)]
[DataMember(Name="quantity", EmitDefaultValue=true)]
public int Quantity { get; set; }

/// <summary>
Expand Down Expand Up @@ -83,13 +83,13 @@ public enum StatusEnum
/// Order Status
/// </summary>
/// <value>Order Status</value>
[DataMember(Name="status", EmitDefaultValue=false)]
[DataMember(Name="status", EmitDefaultValue=true)]
public StatusEnum Status { get; set; }

/// <summary>
/// Gets or Sets Complete
/// </summary>
[DataMember(Name="complete", EmitDefaultValue=false)]
[DataMember(Name="complete", EmitDefaultValue=true)]
public bool Complete { get; set; } = false;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class Pet : IEquatable<Pet>
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
[DataMember(Name="id", EmitDefaultValue=true)]
public long Id { get; set; }

/// <summary>
Expand Down Expand Up @@ -91,7 +91,7 @@ public enum StatusEnum
/// pet status in the store
/// </summary>
/// <value>pet status in the store</value>
[DataMember(Name="status", EmitDefaultValue=false)]
[DataMember(Name="status", EmitDefaultValue=true)]
public StatusEnum Status { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class Tag : IEquatable<Tag>
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
[DataMember(Name="id", EmitDefaultValue=true)]
public long Id { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class User : IEquatable<User>
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
[DataMember(Name="id", EmitDefaultValue=true)]
public long Id { get; set; }

/// <summary>
Expand Down Expand Up @@ -72,7 +72,7 @@ public partial class User : IEquatable<User>
/// User Status
/// </summary>
/// <value>User Status</value>
[DataMember(Name="userStatus", EmitDefaultValue=false)]
[DataMember(Name="userStatus", EmitDefaultValue=true)]
public int UserStatus { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class ApiResponse : IEquatable<ApiResponse>
/// <summary>
/// Gets or Sets Code
/// </summary>
[DataMember(Name="code", EmitDefaultValue=false)]
[DataMember(Name="code", EmitDefaultValue=true)]
public int Code { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class Category : IEquatable<Category>
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
[DataMember(Name="id", EmitDefaultValue=true)]
public long Id { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ public partial class Order : IEquatable<Order>
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
[DataMember(Name="id", EmitDefaultValue=true)]
public long Id { get; set; }

/// <summary>
/// Gets or Sets PetId
/// </summary>
[DataMember(Name="petId", EmitDefaultValue=false)]
[DataMember(Name="petId", EmitDefaultValue=true)]
public long PetId { get; set; }

/// <summary>
/// Gets or Sets Quantity
/// </summary>
[DataMember(Name="quantity", EmitDefaultValue=false)]
[DataMember(Name="quantity", EmitDefaultValue=true)]
public int Quantity { get; set; }

/// <summary>
Expand Down Expand Up @@ -83,13 +83,13 @@ public enum StatusEnum
/// Order Status
/// </summary>
/// <value>Order Status</value>
[DataMember(Name="status", EmitDefaultValue=false)]
[DataMember(Name="status", EmitDefaultValue=true)]
public StatusEnum Status { get; set; }

/// <summary>
/// Gets or Sets Complete
/// </summary>
[DataMember(Name="complete", EmitDefaultValue=false)]
[DataMember(Name="complete", EmitDefaultValue=true)]
public bool Complete { get; set; } = false;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class Pet : IEquatable<Pet>
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
[DataMember(Name="id", EmitDefaultValue=true)]
public long Id { get; set; }

/// <summary>
Expand Down Expand Up @@ -91,7 +91,7 @@ public enum StatusEnum
/// pet status in the store
/// </summary>
/// <value>pet status in the store</value>
[DataMember(Name="status", EmitDefaultValue=false)]
[DataMember(Name="status", EmitDefaultValue=true)]
public StatusEnum Status { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class Tag : IEquatable<Tag>
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
[DataMember(Name="id", EmitDefaultValue=true)]
public long Id { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class User : IEquatable<User>
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
[DataMember(Name="id", EmitDefaultValue=true)]
public long Id { get; set; }

/// <summary>
Expand Down Expand Up @@ -72,7 +72,7 @@ public partial class User : IEquatable<User>
/// User Status
/// </summary>
/// <value>User Status</value>
[DataMember(Name="userStatus", EmitDefaultValue=false)]
[DataMember(Name="userStatus", EmitDefaultValue=true)]
public int UserStatus { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class ApiResponse : IEquatable<ApiResponse>
/// <summary>
/// Gets or Sets Code
/// </summary>
[DataMember(Name="code", EmitDefaultValue=false)]
[DataMember(Name="code", EmitDefaultValue=true)]
public int Code { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class Category : IEquatable<Category>
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
[DataMember(Name="id", EmitDefaultValue=true)]
public long Id { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ public partial class Order : IEquatable<Order>
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
[DataMember(Name="id", EmitDefaultValue=true)]
public long Id { get; set; }

/// <summary>
/// Gets or Sets PetId
/// </summary>
[DataMember(Name="petId", EmitDefaultValue=false)]
[DataMember(Name="petId", EmitDefaultValue=true)]
public long PetId { get; set; }

/// <summary>
/// Gets or Sets Quantity
/// </summary>
[DataMember(Name="quantity", EmitDefaultValue=false)]
[DataMember(Name="quantity", EmitDefaultValue=true)]
public int Quantity { get; set; }

/// <summary>
Expand Down Expand Up @@ -83,13 +83,13 @@ public enum StatusEnum
/// Order Status
/// </summary>
/// <value>Order Status</value>
[DataMember(Name="status", EmitDefaultValue=false)]
[DataMember(Name="status", EmitDefaultValue=true)]
public StatusEnum Status { get; set; }

/// <summary>
/// Gets or Sets Complete
/// </summary>
[DataMember(Name="complete", EmitDefaultValue=false)]
[DataMember(Name="complete", EmitDefaultValue=true)]
public bool Complete { get; set; } = false;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class Pet : IEquatable<Pet>
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
[DataMember(Name="id", EmitDefaultValue=true)]
public long Id { get; set; }

/// <summary>
Expand Down Expand Up @@ -91,7 +91,7 @@ public enum StatusEnum
/// pet status in the store
/// </summary>
/// <value>pet status in the store</value>
[DataMember(Name="status", EmitDefaultValue=false)]
[DataMember(Name="status", EmitDefaultValue=true)]
public StatusEnum Status { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class Tag : IEquatable<Tag>
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
[DataMember(Name="id", EmitDefaultValue=true)]
public long Id { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class User : IEquatable<User>
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
[DataMember(Name="id", EmitDefaultValue=true)]
public long Id { get; set; }

/// <summary>
Expand Down Expand Up @@ -72,7 +72,7 @@ public partial class User : IEquatable<User>
/// User Status
/// </summary>
/// <value>User Status</value>
[DataMember(Name="userStatus", EmitDefaultValue=false)]
[DataMember(Name="userStatus", EmitDefaultValue=true)]
public int UserStatus { get; set; }

/// <summary>
Expand Down

0 comments on commit 10d0dbf

Please sign in to comment.