From 890b7d17e35da6e272f15998ebebe0d11cf26df5 Mon Sep 17 00:00:00 2001 From: wing328 Date: Sun, 21 Feb 2016 22:34:13 +0800 Subject: [PATCH 1/4] add readonly property support to C# --- .../io/swagger/codegen/CodegenProperty.java | 3 ++ .../src/main/resources/csharp/model.mustache | 22 ++++++++++++-- .../src/test/resources/2_0/petstore.json | 3 +- .../src/main/csharp/IO/Swagger/Api/PetApi.cs | 30 +++++++++++++++++++ .../main/csharp/IO/Swagger/Api/StoreApi.cs | 3 -- .../main/csharp/IO/Swagger/Model/Category.cs | 3 +- .../src/main/csharp/IO/Swagger/Model/Order.cs | 5 ++-- .../src/main/csharp/IO/Swagger/Model/Pet.cs | 19 +++++++++++- .../src/main/csharp/IO/Swagger/Model/Tag.cs | 3 +- .../src/main/csharp/IO/Swagger/Model/User.cs | 3 +- 10 files changed, 81 insertions(+), 13 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java index d80bc38a4c..2808c9dcc2 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java @@ -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; } diff --git a/modules/swagger-codegen/src/main/resources/csharp/model.mustache b/modules/swagger-codegen/src/main/resources/csharp/model.mustache index 6abd76ce9d..85aecb25c2 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/model.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/model.mustache @@ -22,9 +22,25 @@ namespace {{packageName}}.Model /// /// Initializes a new instance of the class. /// - public {{classname}}() + public {{classname}}({{#vars}}{{{dataType}}}{{name}} = null{{#hasMore}}, {{/hasMore}}{{/vars}}) { - {{#vars}}{{#defaultValue}}this.{{name}} = {{{defaultValue}}}; + {{#vars}}{{#required}}if ({{name}} == null) + { + throw new InvalidDataException("{{name}} is a required property for {{classname}} and cannot be null"); + } + else + { + this.{{name}} = {{name}}; + } + {{/required}}{{/vars}} + {{#vars}}{{#defaultValue}}if ({{name}} == null) + { + this.{{name}} = {{{defaultValue}}}; + } + else + { + this.{{name}} = {{name}}; + } {{/defaultValue}}{{/vars}} } @@ -34,7 +50,7 @@ namespace {{packageName}}.Model /// {{#description}} /// {{{description}}}{{/description}} [DataMember(Name="{{baseName}}", EmitDefaultValue=false)] - public {{{datatype}}} {{name}} { get; set; } + public {{{datatype}}} {{name}} { get; {{^isReadOnly}}set;{{/isReadOnly}} } {{/vars}} diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore.json b/modules/swagger-codegen/src/test/resources/2_0/petstore.json index b49bd81631..6df7d079a1 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore.json +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore.json @@ -1069,7 +1069,8 @@ "properties": { "id": { "type": "integer", - "format": "int64" + "format": "int64", + "readOnly": true }, "petId": { "type": "integer", diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs index 5ef6e286a8..83f6558986 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs @@ -1304,6 +1304,13 @@ namespace IO.Swagger.Api } // authentication (petstore_auth) required + // oauth required + if (!String.IsNullOrEmpty(Configuration.AccessToken)) + { + headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; + } + // authentication (petstore_auth) required + // oauth required if (!String.IsNullOrEmpty(Configuration.AccessToken)) { @@ -1404,6 +1411,14 @@ namespace IO.Swagger.Api headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; } + // authentication (petstore_auth) required + + // oauth required + if (!String.IsNullOrEmpty(Configuration.AccessToken)) + { + headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; + } + // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, @@ -2033,6 +2048,13 @@ namespace IO.Swagger.Api } // authentication (petstore_auth) required + // oauth required + if (!String.IsNullOrEmpty(Configuration.AccessToken)) + { + headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; + } + // authentication (petstore_auth) required + // oauth required if (!String.IsNullOrEmpty(Configuration.AccessToken)) { @@ -2133,6 +2155,14 @@ namespace IO.Swagger.Api headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; } + // authentication (petstore_auth) required + + // oauth required + if (!String.IsNullOrEmpty(Configuration.AccessToken)) + { + headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; + } + // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/StoreApi.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/StoreApi.cs index 914e28dd6f..eac2760d98 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/StoreApi.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/StoreApi.cs @@ -676,7 +676,6 @@ namespace IO.Swagger.Api // authentication (test_api_key_header) required - if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_header"))) { headerParams["test_api_key_header"] = Configuration.GetApiKeyWithPrefix("test_api_key_header"); @@ -768,14 +767,12 @@ namespace IO.Swagger.Api // authentication (test_api_key_header) required - if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_header"))) { headerParams["test_api_key_header"] = Configuration.GetApiKeyWithPrefix("test_api_key_header"); } // authentication (test_api_key_query) required - if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_query"))) { queryParams["test_api_key_query"] = Configuration.GetApiKeyWithPrefix("test_api_key_query"); diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs index 73cb6dfecf..f25ee66070 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs @@ -20,9 +20,10 @@ namespace IO.Swagger.Model /// /// Initializes a new instance of the class. /// - public Category() + public Category(Id = null, Name = null) { + } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs index 81533a1a58..0e303bcc1c 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs @@ -20,9 +20,10 @@ namespace IO.Swagger.Model /// /// Initializes a new instance of the class. /// - public Order() + public Order(Id = null, PetId = null, Quantity = null, ShipDate = null, Status = null, Complete = null) { + } @@ -30,7 +31,7 @@ namespace IO.Swagger.Model /// Gets or Sets Id /// [DataMember(Name="id", EmitDefaultValue=false)] - public long? Id { get; set; } + public long? Id { get; } /// diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs index 2cb33cbf9e..f93573b39e 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs @@ -20,8 +20,25 @@ namespace IO.Swagger.Model /// /// Initializes a new instance of the class. /// - public Pet() + public Pet(Id = null, Category = null, Name = null, PhotoUrls = null, Tags = null, Status = null) { + if (Name == null) + { + throw new InvalidDataException("Name is a required property for Pet and cannot be null"); + } + else + { + this.Name = Name; + } + if (PhotoUrls == null) + { + throw new InvalidDataException("PhotoUrls is a required property for Pet and cannot be null"); + } + else + { + this.PhotoUrls = PhotoUrls; + } + } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs index f0fbe098cc..9753543382 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs @@ -20,9 +20,10 @@ namespace IO.Swagger.Model /// /// Initializes a new instance of the class. /// - public Tag() + public Tag(Id = null, Name = null) { + } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs index 8960576097..bda838cf6d 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs @@ -20,9 +20,10 @@ namespace IO.Swagger.Model /// /// Initializes a new instance of the class. /// - public User() + public User(Id = null, Username = null, FirstName = null, LastName = null, Email = null, Password = null, Phone = null, UserStatus = null) { + } From d42f23f82943b4aed67b55af13694c0b0ff8f046 Mon Sep 17 00:00:00 2001 From: wing328 Date: Sun, 21 Feb 2016 23:09:56 +0800 Subject: [PATCH 2/4] update test case, minor fix to required property in c# --- bin/jaxrs-resteasy-petstore-server.sh | 0 .../src/main/resources/csharp/model.mustache | 16 +++++---- .../src/main/csharp/IO/Swagger/Api/PetApi.cs | 30 ----------------- .../main/csharp/IO/Swagger/Api/StoreApi.cs | 3 ++ .../main/csharp/IO/Swagger/Model/Category.cs | 5 +-- .../src/main/csharp/IO/Swagger/Model/Order.cs | 11 +++++-- .../src/main/csharp/IO/Swagger/Model/Pet.cs | 9 +++-- .../src/main/csharp/IO/Swagger/Model/Tag.cs | 5 +-- .../src/main/csharp/IO/Swagger/Model/User.cs | 11 +++++-- .../csharp/SwaggerClientTest/TestPet.cs | 33 ++++++++++--------- 10 files changed, 59 insertions(+), 64 deletions(-) mode change 100644 => 100755 bin/jaxrs-resteasy-petstore-server.sh diff --git a/bin/jaxrs-resteasy-petstore-server.sh b/bin/jaxrs-resteasy-petstore-server.sh old mode 100644 new mode 100755 diff --git a/modules/swagger-codegen/src/main/resources/csharp/model.mustache b/modules/swagger-codegen/src/main/resources/csharp/model.mustache index 85aecb25c2..80a80c8c42 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/model.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/model.mustache @@ -22,9 +22,10 @@ namespace {{packageName}}.Model /// /// Initializes a new instance of the class. /// - public {{classname}}({{#vars}}{{{dataType}}}{{name}} = null{{#hasMore}}, {{/hasMore}}{{/vars}}) + public {{classname}}({{#vars}}{{{datatype}}} {{name}} = null{{#hasMore}}, {{/hasMore}}{{/vars}}) { - {{#vars}}{{#required}}if ({{name}} == null) + {{#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"); } @@ -32,16 +33,17 @@ namespace {{packageName}}.Model { this.{{name}} = {{name}}; } - {{/required}}{{/vars}} - {{#vars}}{{#defaultValue}}if ({{name}} == null) + {{/required}}{{/vars}}{{#vars}}{{^required}}{{#defaultValue}}// use default value if no "{{name}}" provided + if ({{name}} == null) { this.{{name}} = {{{defaultValue}}}; } - else + else { this.{{name}} = {{name}}; } - {{/defaultValue}}{{/vars}} + {{/defaultValue}}{{^defaultValue}}this.{{name}} = {{name}}; + {{/defaultValue}}{{/required}}{{/vars}} } {{#vars}} @@ -50,7 +52,7 @@ namespace {{packageName}}.Model /// {{#description}} /// {{{description}}}{{/description}} [DataMember(Name="{{baseName}}", EmitDefaultValue=false)] - public {{{datatype}}} {{name}} { get; {{^isReadOnly}}set;{{/isReadOnly}} } + public {{{datatype}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; } {{/vars}} diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs index 83f6558986..5ef6e286a8 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs @@ -1304,13 +1304,6 @@ namespace IO.Swagger.Api } // authentication (petstore_auth) required - // oauth required - if (!String.IsNullOrEmpty(Configuration.AccessToken)) - { - headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; - } - // authentication (petstore_auth) required - // oauth required if (!String.IsNullOrEmpty(Configuration.AccessToken)) { @@ -1411,14 +1404,6 @@ namespace IO.Swagger.Api headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; } - // authentication (petstore_auth) required - - // oauth required - if (!String.IsNullOrEmpty(Configuration.AccessToken)) - { - headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; - } - // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, @@ -2048,13 +2033,6 @@ namespace IO.Swagger.Api } // authentication (petstore_auth) required - // oauth required - if (!String.IsNullOrEmpty(Configuration.AccessToken)) - { - headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; - } - // authentication (petstore_auth) required - // oauth required if (!String.IsNullOrEmpty(Configuration.AccessToken)) { @@ -2155,14 +2133,6 @@ namespace IO.Swagger.Api headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; } - // authentication (petstore_auth) required - - // oauth required - if (!String.IsNullOrEmpty(Configuration.AccessToken)) - { - headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; - } - // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/StoreApi.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/StoreApi.cs index eac2760d98..914e28dd6f 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/StoreApi.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/StoreApi.cs @@ -676,6 +676,7 @@ namespace IO.Swagger.Api // authentication (test_api_key_header) required + if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_header"))) { headerParams["test_api_key_header"] = Configuration.GetApiKeyWithPrefix("test_api_key_header"); @@ -767,12 +768,14 @@ namespace IO.Swagger.Api // authentication (test_api_key_header) required + if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_header"))) { headerParams["test_api_key_header"] = Configuration.GetApiKeyWithPrefix("test_api_key_header"); } // authentication (test_api_key_query) required + if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_query"))) { queryParams["test_api_key_query"] = Configuration.GetApiKeyWithPrefix("test_api_key_query"); diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs index f25ee66070..4952a7f18c 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs @@ -20,9 +20,10 @@ namespace IO.Swagger.Model /// /// Initializes a new instance of the class. /// - public Category(Id = null, Name = null) + public Category(long? Id = null, string Name = null) { - + this.Id = Id; + this.Name = Name; } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs index 0e303bcc1c..4cc411ab9d 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs @@ -20,9 +20,14 @@ namespace IO.Swagger.Model /// /// Initializes a new instance of the class. /// - public Order(Id = null, PetId = null, Quantity = null, ShipDate = null, Status = null, Complete = null) + 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; } @@ -31,7 +36,7 @@ namespace IO.Swagger.Model /// Gets or Sets Id /// [DataMember(Name="id", EmitDefaultValue=false)] - public long? Id { get; } + public long? Id { get; private set; } /// diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs index f93573b39e..0f033d99ae 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs @@ -20,8 +20,9 @@ namespace IO.Swagger.Model /// /// Initializes a new instance of the class. /// - public Pet(Id = null, Category = null, Name = null, PhotoUrls = null, Tags = null, Status = null) + public Pet(long? Id = null, Category Category = null, string Name = null, List PhotoUrls = null, List 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"); @@ -30,6 +31,7 @@ namespace IO.Swagger.Model { 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"); @@ -38,7 +40,10 @@ namespace IO.Swagger.Model { this.PhotoUrls = PhotoUrls; } - + this.Id = Id; + this.Category = Category; + this.Tags = Tags; + this.Status = Status; } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs index 9753543382..21eb2ef66e 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs @@ -20,9 +20,10 @@ namespace IO.Swagger.Model /// /// Initializes a new instance of the class. /// - public Tag(Id = null, Name = null) + public Tag(long? Id = null, string Name = null) { - + this.Id = Id; + this.Name = Name; } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs index bda838cf6d..7de16b6608 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs @@ -20,9 +20,16 @@ namespace IO.Swagger.Model /// /// Initializes a new instance of the class. /// - public User(Id = null, Username = null, FirstName = null, LastName = null, Email = null, Password = null, Phone = null, UserStatus = null) + 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; } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs b/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs index 3ee63f1e92..84c8d408a5 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs @@ -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 { "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 tags = new List(new Tag[] {tag}); p.Tags = tags; p.Category = category; @@ -86,7 +86,7 @@ namespace SwaggerClientTest.TestPet Assert.IsInstanceOf> (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> (response.PhotoUrls, "Response.PhotoUrls is a Array"); Assert.AreEqual ("sample photoUrls", response.PhotoUrls [0]); @@ -118,7 +118,7 @@ namespace SwaggerClientTest.TestPet Assert.IsInstanceOf> (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> (response.PhotoUrls, "Response.PhotoUrls is a Array"); Assert.AreEqual ("sample photoUrls", response.PhotoUrls [0]); @@ -147,7 +147,7 @@ namespace SwaggerClientTest.TestPet Assert.IsInstanceOf> (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> (response.PhotoUrls, "Response.PhotoUrls is a Array"); Assert.AreEqual ("sample photoUrls", response.PhotoUrls [0]); @@ -235,16 +235,16 @@ namespace SwaggerClientTest.TestPet /// Test FindPetByStatus /// [Test ()] - public void TestFindPetByStatus () + public void TestFindPetByTags () { PetApi petApi = new PetApi (); - List statusList = new List(new String[] {"available"}); + List tagsList = new List(new String[] {"available"}); - List listPet = petApi.FindPetsByStatus (statusList); + List listPet = petApi.FindPetsByTags (tagsList); foreach (Pet pet in listPet) // Loop through List with foreach. { Assert.IsInstanceOf (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 { "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 tags1 = new List(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 { "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 tags2 = new List(new Tag[] {tag2}); p2.Tags = tags2; p2.Category = category2; @@ -334,8 +334,9 @@ namespace SwaggerClientTest.TestPet public void TestDefaultHeader () { PetApi petApi = new PetApi (); + // comment out the warning test below as it's confirmed the warning is working as expecteds // 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"); From b3b46700552068d374fcdfe136666daaa57467ba Mon Sep 17 00:00:00 2001 From: wing328 Date: Sun, 21 Feb 2016 23:31:19 +0800 Subject: [PATCH 3/4] add exception comment, minor enhancement to param description --- .../src/main/resources/csharp/model.mustache | 5 ++++- .../src/main/csharp/IO/Swagger/Model/Category.cs | 5 ++++- .../src/main/csharp/IO/Swagger/Model/Order.cs | 9 ++++++++- .../src/main/csharp/IO/Swagger/Model/Pet.cs | 9 ++++++++- .../src/main/csharp/IO/Swagger/Model/Tag.cs | 5 ++++- .../src/main/csharp/IO/Swagger/Model/User.cs | 11 ++++++++++- .../SwaggerClientTest.userprefs | 16 ++++++++++------ 7 files changed, 48 insertions(+), 12 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/csharp/model.mustache b/modules/swagger-codegen/src/main/resources/csharp/model.mustache index 80a80c8c42..d7f38218dc 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/model.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/model.mustache @@ -20,8 +20,11 @@ namespace {{packageName}}.Model public partial class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}} IEquatable<{{classname}}> { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// + /// Thrown when required property is null +{{#vars}} /// {{#description}}{{description}}{{/description}}{{^description}}{{name}}{{/description}}{{#required}} (required){{/required}}{{#defaultValue}} (default to {{defaultValue}}){{/defaultValue}}. +{{/vars}} public {{classname}}({{#vars}}{{{datatype}}} {{name}} = null{{#hasMore}}, {{/hasMore}}{{/vars}}) { {{#vars}}{{#required}}// to ensure "{{name}}" is required (not null) diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs index 4952a7f18c..9b534f83c1 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs @@ -18,8 +18,11 @@ namespace IO.Swagger.Model public partial class Category : IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// + /// Thrown when required property is null + /// Id. + /// Name. public Category(long? Id = null, string Name = null) { this.Id = Id; diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs index 4cc411ab9d..040b348f1f 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs @@ -18,8 +18,15 @@ namespace IO.Swagger.Model public partial class Order : IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// + /// Thrown when required property is null + /// Id. + /// PetId. + /// Quantity. + /// ShipDate. + /// Order Status. + /// Complete. public Order(long? Id = null, long? PetId = null, int? Quantity = null, DateTime? ShipDate = null, string Status = null, bool? Complete = null) { this.Id = Id; diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs index 0f033d99ae..3b96481fdf 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs @@ -18,8 +18,15 @@ namespace IO.Swagger.Model public partial class Pet : IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// + /// Thrown when required property is null + /// Id. + /// Category. + /// Name (required). + /// PhotoUrls (required). + /// Tags. + /// pet status in the store. public Pet(long? Id = null, Category Category = null, string Name = null, List PhotoUrls = null, List Tags = null, string Status = null) { // to ensure "Name" is required (not null) diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs index 21eb2ef66e..bb98f1b646 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs @@ -18,8 +18,11 @@ namespace IO.Swagger.Model public partial class Tag : IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// + /// Thrown when required property is null + /// Id. + /// Name. public Tag(long? Id = null, string Name = null) { this.Id = Id; diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs index 7de16b6608..e182b3f918 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs @@ -18,8 +18,17 @@ namespace IO.Swagger.Model public partial class User : IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// + /// Thrown when required property is null + /// Id. + /// Username. + /// FirstName. + /// LastName. + /// Email. + /// Password. + /// Phone. + /// User Status. 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; diff --git a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs index a66bf7badf..85aa051f2b 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs +++ b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs @@ -1,14 +1,18 @@  - + - + + - - - - + + + + + + + From 91da8fef52ef73caff0de3cc606236a920f383cf Mon Sep 17 00:00:00 2001 From: wing328 Date: Sun, 21 Feb 2016 23:33:53 +0800 Subject: [PATCH 4/4] fix typo --- samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs b/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs index 84c8d408a5..640d24250d 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs @@ -334,7 +334,7 @@ namespace SwaggerClientTest.TestPet public void TestDefaultHeader () { PetApi petApi = new PetApi (); - // comment out the warning test below as it's confirmed the warning is working as expecteds + // 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"); // the following should be used instead as suggested in the doc