add readonly property support to C#

This commit is contained in:
wing328 2016-02-21 22:34:13 +08:00
parent e9bb912fca
commit 890b7d17e3
10 changed files with 81 additions and 13 deletions

View 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;
}

View File

@ -22,9 +22,25 @@ namespace {{packageName}}.Model
/// <summary>
/// Initializes a new instance of the <see cref="{{classname}}" /> class.
/// </summary>
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
/// </summary>{{#description}}
/// <value>{{{description}}}</value>{{/description}}
[DataMember(Name="{{baseName}}", EmitDefaultValue=false)]
public {{{datatype}}} {{name}} { get; set; }
public {{{datatype}}} {{name}} { get; {{^isReadOnly}}set;{{/isReadOnly}} }
{{/vars}}

View File

@ -1069,7 +1069,8 @@
"properties": {
"id": {
"type": "integer",
"format": "int64"
"format": "int64",
"readOnly": true
},
"petId": {
"type": "integer",

View File

@ -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_,

View File

@ -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");

View File

@ -20,9 +20,10 @@ namespace IO.Swagger.Model
/// <summary>
/// Initializes a new instance of the <see cref="Category" /> class.
/// </summary>
public Category()
public Category(Id = null, Name = null)
{
}

View File

@ -20,9 +20,10 @@ namespace IO.Swagger.Model
/// <summary>
/// Initializes a new instance of the <see cref="Order" /> class.
/// </summary>
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
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }
public long? Id { get; }
/// <summary>

View File

@ -20,8 +20,25 @@ namespace IO.Swagger.Model
/// <summary>
/// Initializes a new instance of the <see cref="Pet" /> class.
/// </summary>
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;
}
}

View File

@ -20,9 +20,10 @@ namespace IO.Swagger.Model
/// <summary>
/// Initializes a new instance of the <see cref="Tag" /> class.
/// </summary>
public Tag()
public Tag(Id = null, Name = null)
{
}

View File

@ -20,9 +20,10 @@ namespace IO.Swagger.Model
/// <summary>
/// Initializes a new instance of the <see cref="User" /> class.
/// </summary>
public User()
public User(Id = null, Username = null, FirstName = null, LastName = null, Email = null, Password = null, Phone = null, UserStatus = null)
{
}