forked from loafle/openapi-generator-original
add required property check to aspnet5 model constructor
This commit is contained in:
parent
eed91d335d
commit
a1e15adb8f
@ -20,10 +20,30 @@ namespace {{packageName}}.Models
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="{{classname}}" /> class.
|
||||
/// </summary>
|
||||
public {{classname}}()
|
||||
{{#vars}} /// <param name="{{name}}">{{#description}}{{description}}{{/description}}{{^description}}{{name}}{{/description}}{{#required}} (required){{/required}}{{#defaultValue}} (default to {{defaultValue}}){{/defaultValue}}.</param>
|
||||
{{/vars}}
|
||||
public {{classname}}({{#vars}}{{{datatype}}} {{name}} = null{{#hasMore}}, {{/hasMore}}{{/vars}})
|
||||
{
|
||||
{{#vars}}{{#defaultValue}}this.{{name}} = {{{defaultValue}}};
|
||||
{{/defaultValue}}{{/vars}}
|
||||
{{#vars}}{{#required}}// to ensure "{{name}}" is required (not null)
|
||||
if ({{name}} == null)
|
||||
{
|
||||
throw new InvalidDataException("{{name}} is a required property for {{classname}} and cannot be null");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
{{/required}}{{/vars}}{{#vars}}{{^required}}{{#defaultValue}}// use default value if no "{{name}}" provided
|
||||
if ({{name}} == null)
|
||||
{
|
||||
this.{{name}} = {{{defaultValue}}};
|
||||
}
|
||||
else
|
||||
{
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
{{/defaultValue}}{{^defaultValue}}this.{{name}} = {{name}};
|
||||
{{/defaultValue}}{{/required}}{{/vars}}
|
||||
}
|
||||
|
||||
{{#vars}}
|
||||
|
@ -18,8 +18,12 @@ namespace IO.Swagger.Models
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Category" /> class.
|
||||
/// </summary>
|
||||
public Category()
|
||||
/// <param name="Id">Id.</param>
|
||||
/// <param name="Name">Name.</param>
|
||||
public Category(long? Id = null, string Name = null)
|
||||
{
|
||||
this.Id = Id;
|
||||
this.Name = Name;
|
||||
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,20 @@ namespace IO.Swagger.Models
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Order" /> class.
|
||||
/// </summary>
|
||||
public Order()
|
||||
/// <param name="Id">Id.</param>
|
||||
/// <param name="PetId">PetId.</param>
|
||||
/// <param name="Quantity">Quantity.</param>
|
||||
/// <param name="ShipDate">ShipDate.</param>
|
||||
/// <param name="Status">Order Status.</param>
|
||||
/// <param name="Complete">Complete.</param>
|
||||
public Order(long? Id = null, long? PetId = null, int? Quantity = null, DateTime? ShipDate = null, string Status = null, bool? Complete = null)
|
||||
{
|
||||
this.Id = Id;
|
||||
this.PetId = PetId;
|
||||
this.Quantity = Quantity;
|
||||
this.ShipDate = ShipDate;
|
||||
this.Status = Status;
|
||||
this.Complete = Complete;
|
||||
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,36 @@ namespace IO.Swagger.Models
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Pet" /> class.
|
||||
/// </summary>
|
||||
public Pet()
|
||||
/// <param name="Id">Id.</param>
|
||||
/// <param name="Category">Category.</param>
|
||||
/// <param name="Name">Name (required).</param>
|
||||
/// <param name="PhotoUrls">PhotoUrls (required).</param>
|
||||
/// <param name="Tags">Tags.</param>
|
||||
/// <param name="Status">pet status in the store.</param>
|
||||
public Pet(long? Id = null, Category Category = null, string Name = null, List<string> PhotoUrls = null, List<Tag> Tags = null, string Status = null)
|
||||
{
|
||||
// to ensure "Name" is required (not null)
|
||||
if (Name == null)
|
||||
{
|
||||
throw new InvalidDataException("Name is a required property for Pet and cannot be null");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Name = Name;
|
||||
}
|
||||
// to ensure "PhotoUrls" is required (not null)
|
||||
if (PhotoUrls == null)
|
||||
{
|
||||
throw new InvalidDataException("PhotoUrls is a required property for Pet and cannot be null");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.PhotoUrls = PhotoUrls;
|
||||
}
|
||||
this.Id = Id;
|
||||
this.Category = Category;
|
||||
this.Tags = Tags;
|
||||
this.Status = Status;
|
||||
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,12 @@ namespace IO.Swagger.Models
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Tag" /> class.
|
||||
/// </summary>
|
||||
public Tag()
|
||||
/// <param name="Id">Id.</param>
|
||||
/// <param name="Name">Name.</param>
|
||||
public Tag(long? Id = null, string Name = null)
|
||||
{
|
||||
this.Id = Id;
|
||||
this.Name = Name;
|
||||
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,24 @@ namespace IO.Swagger.Models
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="User" /> class.
|
||||
/// </summary>
|
||||
public User()
|
||||
/// <param name="Id">Id.</param>
|
||||
/// <param name="Username">Username.</param>
|
||||
/// <param name="FirstName">FirstName.</param>
|
||||
/// <param name="LastName">LastName.</param>
|
||||
/// <param name="Email">Email.</param>
|
||||
/// <param name="Password">Password.</param>
|
||||
/// <param name="Phone">Phone.</param>
|
||||
/// <param name="UserStatus">User Status.</param>
|
||||
public User(long? Id = null, string Username = null, string FirstName = null, string LastName = null, string Email = null, string Password = null, string Phone = null, int? UserStatus = null)
|
||||
{
|
||||
this.Id = Id;
|
||||
this.Username = Username;
|
||||
this.FirstName = FirstName;
|
||||
this.LastName = LastName;
|
||||
this.Email = Email;
|
||||
this.Password = Password;
|
||||
this.Phone = Phone;
|
||||
this.UserStatus = UserStatus;
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user