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 d80bc38a4c7..2808c9dcc2a 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 6abd76ce9df..85aecb25c2c 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 b49bd81631e..6df7d079a10 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 5ef6e286a8d..83f6558986d 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 914e28dd6fb..eac2760d98b 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 73cb6dfecfa..f25ee660703 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 81533a1a586..0e303bcc1cd 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 2cb33cbf9e7..f93573b39e5 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 f0fbe098cce..97535433826 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 89605760978..bda838cf6d6 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) { + }