mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
Merge pull request #2199 from wing328/readonly_property
[C#] Add support for Readonly property
This commit is contained in:
commit
ad6380cb88
0
bin/jaxrs-resteasy-petstore-server.sh
Normal file → Executable file
0
bin/jaxrs-resteasy-petstore-server.sh
Normal file → Executable file
@ -177,6 +177,9 @@ public class CodegenProperty {
|
||||
if (this.isEnum != other.isEnum) {
|
||||
return false;
|
||||
}
|
||||
if (this.isReadOnly != other.isReadOnly && (this.isReadOnly == null || !this.isReadOnly.equals(other.isReadOnly))) {
|
||||
return false;
|
||||
}
|
||||
if (this._enum != other._enum && (this._enum == null || !this._enum.equals(other._enum))) {
|
||||
return false;
|
||||
}
|
||||
|
@ -20,12 +20,33 @@ namespace {{packageName}}.Model
|
||||
public partial class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}} IEquatable<{{classname}}>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="{{classname}}" /> class.
|
||||
/// Initializes a new instance of the <see cref="{{classname}}" />class.
|
||||
/// </summary>
|
||||
public {{classname}}()
|
||||
/// <exception cref="System.InvalidDataException">Thrown when required property is null</exception>
|
||||
{{#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}}
|
||||
@ -34,7 +55,7 @@ namespace {{packageName}}.Model
|
||||
/// </summary>{{#description}}
|
||||
/// <value>{{{description}}}</value>{{/description}}
|
||||
[DataMember(Name="{{baseName}}", EmitDefaultValue=false)]
|
||||
public {{{datatype}}} {{name}} { get; set; }
|
||||
public {{{datatype}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; }
|
||||
|
||||
{{/vars}}
|
||||
|
||||
|
@ -1069,7 +1069,8 @@
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
"format": "int64",
|
||||
"readOnly": true
|
||||
},
|
||||
"petId": {
|
||||
"type": "integer",
|
||||
|
@ -18,10 +18,15 @@ namespace IO.Swagger.Model
|
||||
public partial class Category : IEquatable<Category>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Category" /> class.
|
||||
/// Initializes a new instance of the <see cref="Category" />class.
|
||||
/// </summary>
|
||||
public Category()
|
||||
/// <exception cref="System.InvalidDataException">Thrown when required property is null</exception>
|
||||
/// <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,10 +18,23 @@ namespace IO.Swagger.Model
|
||||
public partial class Order : IEquatable<Order>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Order" /> class.
|
||||
/// Initializes a new instance of the <see cref="Order" />class.
|
||||
/// </summary>
|
||||
public Order()
|
||||
/// <exception cref="System.InvalidDataException">Thrown when required property is null</exception>
|
||||
/// <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;
|
||||
|
||||
}
|
||||
|
||||
@ -30,7 +43,7 @@ namespace IO.Swagger.Model
|
||||
/// Gets or Sets Id
|
||||
/// </summary>
|
||||
[DataMember(Name="id", EmitDefaultValue=false)]
|
||||
public long? Id { get; set; }
|
||||
public long? Id { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
@ -18,10 +18,39 @@ namespace IO.Swagger.Model
|
||||
public partial class Pet : IEquatable<Pet>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Pet" /> class.
|
||||
/// Initializes a new instance of the <see cref="Pet" />class.
|
||||
/// </summary>
|
||||
public Pet()
|
||||
/// <exception cref="System.InvalidDataException">Thrown when required property is null</exception>
|
||||
/// <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,10 +18,15 @@ namespace IO.Swagger.Model
|
||||
public partial class Tag : IEquatable<Tag>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Tag" /> class.
|
||||
/// Initializes a new instance of the <see cref="Tag" />class.
|
||||
/// </summary>
|
||||
public Tag()
|
||||
/// <exception cref="System.InvalidDataException">Thrown when required property is null</exception>
|
||||
/// <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,10 +18,27 @@ namespace IO.Swagger.Model
|
||||
public partial class User : IEquatable<User>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="User" /> class.
|
||||
/// Initializes a new instance of the <see cref="User" />class.
|
||||
/// </summary>
|
||||
public User()
|
||||
/// <exception cref="System.InvalidDataException">Thrown when required property is null</exception>
|
||||
/// <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;
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,18 @@
|
||||
<Properties StartupItem="SwaggerClientTest.csproj">
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="TestApiClient.cs">
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="TestPet.cs">
|
||||
<Files>
|
||||
<File FileName="TestPet.cs" Line="1" Column="1" />
|
||||
<File FileName="TestPet.cs" Line="250" Column="4" />
|
||||
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs" Line="21" Column="64" />
|
||||
<File FileName="TestConfiguration.cs" Line="1" Column="1" />
|
||||
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs" Line="1" Column="1" />
|
||||
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs" Line="1" Column="1" />
|
||||
<File FileName="TestApiClient.cs" Line="8" Column="2" />
|
||||
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs" Line="1" Column="1" />
|
||||
</Files>
|
||||
<Pads>
|
||||
<Pad Id="MonoDevelop.NUnit.TestPad">
|
||||
<State name="__root__">
|
||||
<Node name="SwaggerClientTest" expanded="True" />
|
||||
</State>
|
||||
</Pad>
|
||||
</Pads>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<BreakpointStore />
|
||||
|
@ -21,9 +21,9 @@ namespace SwaggerClientTest.TestPet
|
||||
private Pet createPet()
|
||||
{
|
||||
// create pet
|
||||
Pet p = new Pet();
|
||||
Pet p = new Pet(Name: "Csharp test", PhotoUrls: new List<string> { "http://petstore.com/csharp_test" });
|
||||
p.Id = petId;
|
||||
p.Name = "Csharp test";
|
||||
//p.Name = "Csharp test";
|
||||
p.Status = "available";
|
||||
// create Category object
|
||||
Category category = new Category();
|
||||
@ -33,7 +33,7 @@ namespace SwaggerClientTest.TestPet
|
||||
// create Tag object
|
||||
Tag tag = new Tag();
|
||||
tag.Id = petId;
|
||||
tag.Name = "sample tag name1";
|
||||
tag.Name = "csharp sample tag name1";
|
||||
List<Tag> tags = new List<Tag>(new Tag[] {tag});
|
||||
p.Tags = tags;
|
||||
p.Category = category;
|
||||
@ -86,7 +86,7 @@ namespace SwaggerClientTest.TestPet
|
||||
|
||||
Assert.IsInstanceOf<List<Tag>> (response.Tags, "Response.Tags is a Array");
|
||||
Assert.AreEqual (petId, response.Tags [0].Id);
|
||||
Assert.AreEqual ("sample tag name1", response.Tags [0].Name);
|
||||
Assert.AreEqual ("csharp sample tag name1", response.Tags [0].Name);
|
||||
|
||||
Assert.IsInstanceOf<List<String>> (response.PhotoUrls, "Response.PhotoUrls is a Array");
|
||||
Assert.AreEqual ("sample photoUrls", response.PhotoUrls [0]);
|
||||
@ -118,7 +118,7 @@ namespace SwaggerClientTest.TestPet
|
||||
|
||||
Assert.IsInstanceOf<List<Tag>> (response.Tags, "Response.Tags is a Array");
|
||||
Assert.AreEqual (petId, response.Tags [0].Id);
|
||||
Assert.AreEqual ("sample tag name1", response.Tags [0].Name);
|
||||
Assert.AreEqual ("csharp sample tag name1", response.Tags [0].Name);
|
||||
|
||||
Assert.IsInstanceOf<List<String>> (response.PhotoUrls, "Response.PhotoUrls is a Array");
|
||||
Assert.AreEqual ("sample photoUrls", response.PhotoUrls [0]);
|
||||
@ -147,7 +147,7 @@ namespace SwaggerClientTest.TestPet
|
||||
|
||||
Assert.IsInstanceOf<List<Tag>> (response.Tags, "Response.Tags is a Array");
|
||||
Assert.AreEqual (petId, response.Tags [0].Id);
|
||||
Assert.AreEqual ("sample tag name1", response.Tags [0].Name);
|
||||
Assert.AreEqual ("csharp sample tag name1", response.Tags [0].Name);
|
||||
|
||||
Assert.IsInstanceOf<List<String>> (response.PhotoUrls, "Response.PhotoUrls is a Array");
|
||||
Assert.AreEqual ("sample photoUrls", response.PhotoUrls [0]);
|
||||
@ -235,16 +235,16 @@ namespace SwaggerClientTest.TestPet
|
||||
/// Test FindPetByStatus
|
||||
/// </summary>
|
||||
[Test ()]
|
||||
public void TestFindPetByStatus ()
|
||||
public void TestFindPetByTags ()
|
||||
{
|
||||
PetApi petApi = new PetApi ();
|
||||
List<String> statusList = new List<String>(new String[] {"available"});
|
||||
List<String> tagsList = new List<String>(new String[] {"available"});
|
||||
|
||||
List<Pet> listPet = petApi.FindPetsByStatus (statusList);
|
||||
List<Pet> listPet = petApi.FindPetsByTags (tagsList);
|
||||
foreach (Pet pet in listPet) // Loop through List with foreach.
|
||||
{
|
||||
Assert.IsInstanceOf<Pet> (pet, "Response is a Pet");
|
||||
Assert.AreEqual ("available", pet.Status);
|
||||
Assert.AreEqual ("csharp sample tag name1", pet.Tags[0]);
|
||||
}
|
||||
|
||||
}
|
||||
@ -256,9 +256,9 @@ namespace SwaggerClientTest.TestPet
|
||||
public void TestEqual()
|
||||
{
|
||||
// create pet
|
||||
Pet p1 = new Pet();
|
||||
Pet p1 = new Pet(Name: "Csharp test", PhotoUrls: new List<string> { "http://petstore.com/csharp_test"} );
|
||||
p1.Id = petId;
|
||||
p1.Name = "Csharp test";
|
||||
//p1.Name = "Csharp test";
|
||||
p1.Status = "available";
|
||||
// create Category object
|
||||
Category category1 = new Category();
|
||||
@ -268,14 +268,14 @@ namespace SwaggerClientTest.TestPet
|
||||
// create Tag object
|
||||
Tag tag1 = new Tag();
|
||||
tag1.Id = petId;
|
||||
tag1.Name = "sample tag name1";
|
||||
tag1.Name = "csharp sample tag name1";
|
||||
List<Tag> tags1 = new List<Tag>(new Tag[] {tag1});
|
||||
p1.Tags = tags1;
|
||||
p1.Category = category1;
|
||||
p1.PhotoUrls = photoUrls1;
|
||||
|
||||
// create pet 2
|
||||
Pet p2 = new Pet();
|
||||
Pet p2 = new Pet(Name: "Csharp test", PhotoUrls: new List<string> { "http://petstore.com/csharp_test"} );
|
||||
p2.Id = petId;
|
||||
p2.Name = "Csharp test";
|
||||
p2.Status = "available";
|
||||
@ -287,7 +287,7 @@ namespace SwaggerClientTest.TestPet
|
||||
// create Tag object
|
||||
Tag tag2 = new Tag();
|
||||
tag2.Id = petId;
|
||||
tag2.Name = "sample tag name1";
|
||||
tag2.Name = "csharp sample tag name1";
|
||||
List<Tag> tags2 = new List<Tag>(new Tag[] {tag2});
|
||||
p2.Tags = tags2;
|
||||
p2.Category = category2;
|
||||
@ -334,8 +334,9 @@ namespace SwaggerClientTest.TestPet
|
||||
public void TestDefaultHeader ()
|
||||
{
|
||||
PetApi petApi = new PetApi ();
|
||||
// commented out the warning test below as it's confirmed the warning is working as expected
|
||||
// there should be a warning for using AddDefaultHeader (deprecated) below
|
||||
petApi.AddDefaultHeader ("header_key", "header_value");
|
||||
//petApi.AddDefaultHeader ("header_key", "header_value");
|
||||
// the following should be used instead as suggested in the doc
|
||||
petApi.Configuration.AddDefaultHeader ("header_key2", "header_value2");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user