better style for model, add <value> to all properties

This commit is contained in:
wing328 2015-07-07 16:25:33 +08:00
parent b1b0e28f59
commit e49fe7a12f
20 changed files with 149 additions and 73 deletions

View File

@ -34,11 +34,13 @@ namespace {{packageName}}.Client
/// <summary> /// <summary>
/// Gets or sets the base path. /// Gets or sets the base path.
/// </summary> /// </summary>
/// <value>The base path</value>
public string BasePath { get; set; } public string BasePath { get; set; }
/// <summary> /// <summary>
/// Gets or sets the RestClient. /// Gets or sets the RestClient.
/// </summary> /// </summary>
/// <value>An instance of the RestClient</value>
public RestClient RestClient { get; set; } public RestClient RestClient { get; set; }
/// <summary> /// <summary>
@ -205,28 +207,34 @@ namespace {{packageName}}.Client
{ {
if (type == typeof(Object)) // return an object if (type == typeof(Object)) // return an object
{ {
return (Object)content; return content;
} else if (type == typeof(Stream)) }
if (type == typeof(Stream))
{ {
String fileName, filePath; var filePath = String.IsNullOrEmpty(Configuration.TempFolderPath)
if (String.IsNullOrEmpty (Configuration.TempFolderPath)) ? Path.GetTempPath()
filePath = System.IO.Path.GetTempPath (); : Configuration.TempFolderPath;
else
filePath = Configuration.TempFolderPath;
Regex regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$"); var fileName = filePath + Guid.NewGuid();
Match match = regex.Match(headers.ToString()); if (headers != null)
if (match.Success) // replace first and last " or ', if found {
fileName = filePath + match.Value.Replace("\"", "").Replace("'",""); var regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$");
else var match = regex.Match(headers.ToString());
fileName = filePath + Guid.NewGuid().ToString(); if (match.Success)
fileName = filePath + match.Value.Replace("\"", "").Replace("'", "");
File.WriteAllText (fileName, content); }
File.WriteAllText(fileName, content);
return new FileStream(fileName, FileMode.Open); return new FileStream(fileName, FileMode.Open);
} else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) // return a datetime object
}
if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) // return a datetime object
{ {
return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind); return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind);
} else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) // return primitive type }
if (type == typeof(String) || type.Name.StartsWith("System.Nullable")) // return primitive type
{ {
return ConvertType(content, type); return ConvertType(content, type);
} }

View File

@ -82,10 +82,9 @@ namespace {{packageName}}.Client
/// <summary> /// <summary>
/// Returns a string with essential information for debugging. /// Returns a string with essential information for debugging.
/// </summary> /// </summary>
/// <value>Debugging Report</value>
public static String ToDebugReport() public static String ToDebugReport()
{ {
String report = "C# SDK ({{invokerPackage}}) Debug Report:\n"; String report = "C# SDK ({{packageName}}) Debug Report:\n";
report += " OS: " + Environment.OSVersion + "\n"; report += " OS: " + Environment.OSVersion + "\n";
report += " .NET Framework Version: " + Assembly report += " .NET Framework Version: " + Assembly
.GetExecutingAssembly() .GetExecutingAssembly()

View File

@ -59,6 +59,7 @@ namespace {{packageName}}.Api
/// <summary> /// <summary>
/// Sets the base path of the API client. /// Sets the base path of the API client.
/// </summary> /// </summary>
/// <param name="basePath">The base path</param>
/// <value>The base path</value> /// <value>The base path</value>
public void SetBasePath(String basePath) public void SetBasePath(String basePath)
{ {
@ -68,6 +69,7 @@ namespace {{packageName}}.Api
/// <summary> /// <summary>
/// Gets the base path of the API client. /// Gets the base path of the API client.
/// </summary> /// </summary>
/// <param name="basePath">The base path</param>
/// <value>The base path</value> /// <value>The base path</value>
public String GetBasePath(String basePath) public String GetBasePath(String basePath)
{ {
@ -77,7 +79,7 @@ namespace {{packageName}}.Api
/// <summary> /// <summary>
/// Gets or sets the API client. /// Gets or sets the API client.
/// </summary> /// </summary>
/// <value>The API client.</value> /// <value>An instance of the ApiClient</param>
public ApiClient ApiClient {get; set;} public ApiClient ApiClient {get; set;}
{{#operation}} {{#operation}}

View File

@ -15,7 +15,10 @@ namespace {{packageName}}.Model {
[DataContract] [DataContract]
public class {{classname}}{{#parent}} : {{{parent}}}{{/parent}} { public class {{classname}}{{#parent}} : {{{parent}}}{{/parent}} {
{{#vars}} {{#vars}}
{{#description}}/* {{{description}}} */{{/description}} /// <summary>
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
/// </summary>{{#description}}
/// <value>{{{description}}}</value>{{/description}}
[DataMember(Name="{{baseName}}", EmitDefaultValue=false)] [DataMember(Name="{{baseName}}", EmitDefaultValue=false)]
public {{{datatype}}} {{name}} { get; set; } public {{{datatype}}} {{name}} { get; set; }

View File

@ -166,6 +166,7 @@ namespace IO.Swagger.Api
/// <summary> /// <summary>
/// Sets the base path of the API client. /// Sets the base path of the API client.
/// </summary> /// </summary>
/// <param name="basePath">The base path</param>
/// <value>The base path</value> /// <value>The base path</value>
public void SetBasePath(String basePath) public void SetBasePath(String basePath)
{ {
@ -175,6 +176,7 @@ namespace IO.Swagger.Api
/// <summary> /// <summary>
/// Gets the base path of the API client. /// Gets the base path of the API client.
/// </summary> /// </summary>
/// <param name="basePath">The base path</param>
/// <value>The base path</value> /// <value>The base path</value>
public String GetBasePath(String basePath) public String GetBasePath(String basePath)
{ {
@ -184,7 +186,7 @@ namespace IO.Swagger.Api
/// <summary> /// <summary>
/// Gets or sets the API client. /// Gets or sets the API client.
/// </summary> /// </summary>
/// <value>The API client.</value> /// <value>An instance of the ApiClient</param>
public ApiClient ApiClient {get; set;} public ApiClient ApiClient {get; set;}

View File

@ -98,6 +98,7 @@ namespace IO.Swagger.Api
/// <summary> /// <summary>
/// Sets the base path of the API client. /// Sets the base path of the API client.
/// </summary> /// </summary>
/// <param name="basePath">The base path</param>
/// <value>The base path</value> /// <value>The base path</value>
public void SetBasePath(String basePath) public void SetBasePath(String basePath)
{ {
@ -107,6 +108,7 @@ namespace IO.Swagger.Api
/// <summary> /// <summary>
/// Gets the base path of the API client. /// Gets the base path of the API client.
/// </summary> /// </summary>
/// <param name="basePath">The base path</param>
/// <value>The base path</value> /// <value>The base path</value>
public String GetBasePath(String basePath) public String GetBasePath(String basePath)
{ {
@ -116,7 +118,7 @@ namespace IO.Swagger.Api
/// <summary> /// <summary>
/// Gets or sets the API client. /// Gets or sets the API client.
/// </summary> /// </summary>
/// <value>The API client.</value> /// <value>An instance of the ApiClient</param>
public ApiClient ApiClient {get; set;} public ApiClient ApiClient {get; set;}

View File

@ -158,6 +158,7 @@ namespace IO.Swagger.Api
/// <summary> /// <summary>
/// Sets the base path of the API client. /// Sets the base path of the API client.
/// </summary> /// </summary>
/// <param name="basePath">The base path</param>
/// <value>The base path</value> /// <value>The base path</value>
public void SetBasePath(String basePath) public void SetBasePath(String basePath)
{ {
@ -167,6 +168,7 @@ namespace IO.Swagger.Api
/// <summary> /// <summary>
/// Gets the base path of the API client. /// Gets the base path of the API client.
/// </summary> /// </summary>
/// <param name="basePath">The base path</param>
/// <value>The base path</value> /// <value>The base path</value>
public String GetBasePath(String basePath) public String GetBasePath(String basePath)
{ {
@ -176,7 +178,7 @@ namespace IO.Swagger.Api
/// <summary> /// <summary>
/// Gets or sets the API client. /// Gets or sets the API client.
/// </summary> /// </summary>
/// <value>The API client.</value> /// <value>An instance of the ApiClient</param>
public ApiClient ApiClient {get; set;} public ApiClient ApiClient {get; set;}

View File

@ -34,11 +34,13 @@ namespace IO.Swagger.Client
/// <summary> /// <summary>
/// Gets or sets the base path. /// Gets or sets the base path.
/// </summary> /// </summary>
/// <value>The base path</value>
public string BasePath { get; set; } public string BasePath { get; set; }
/// <summary> /// <summary>
/// Gets or sets the RestClient. /// Gets or sets the RestClient.
/// </summary> /// </summary>
/// <value>An instance of the RestClient</value>
public RestClient RestClient { get; set; } public RestClient RestClient { get; set; }
/// <summary> /// <summary>
@ -205,28 +207,34 @@ namespace IO.Swagger.Client
{ {
if (type == typeof(Object)) // return an object if (type == typeof(Object)) // return an object
{ {
return (Object)content; return content;
} else if (type == typeof(Stream)) }
if (type == typeof(Stream))
{ {
String fileName, filePath; var filePath = String.IsNullOrEmpty(Configuration.TempFolderPath)
if (String.IsNullOrEmpty (Configuration.TempFolderPath)) ? Path.GetTempPath()
filePath = System.IO.Path.GetTempPath (); : Configuration.TempFolderPath;
else
filePath = Configuration.TempFolderPath;
Regex regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$"); var fileName = filePath + Guid.NewGuid();
Match match = regex.Match(headers.ToString()); if (headers != null)
if (match.Success) // replace first and last " or ', if found {
fileName = filePath + match.Value.Replace("\"", "").Replace("'",""); var regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$");
else var match = regex.Match(headers.ToString());
fileName = filePath + Guid.NewGuid().ToString(); if (match.Success)
fileName = filePath + match.Value.Replace("\"", "").Replace("'", "");
File.WriteAllText (fileName, content); }
File.WriteAllText(fileName, content);
return new FileStream(fileName, FileMode.Open); return new FileStream(fileName, FileMode.Open);
} else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) // return a datetime object
}
if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) // return a datetime object
{ {
return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind); return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind);
} else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) // return primitive type }
if (type == typeof(String) || type.Name.StartsWith("System.Nullable")) // return primitive type
{ {
return ConvertType(content, type); return ConvertType(content, type);
} }

View File

@ -82,10 +82,9 @@ namespace IO.Swagger.Client
/// <summary> /// <summary>
/// Returns a string with essential information for debugging. /// Returns a string with essential information for debugging.
/// </summary> /// </summary>
/// <value>Debugging Report</value>
public static String ToDebugReport() public static String ToDebugReport()
{ {
String report = "C# SDK () Debug Report:\n"; String report = "C# SDK (IO.Swagger) Debug Report:\n";
report += " OS: " + Environment.OSVersion + "\n"; report += " OS: " + Environment.OSVersion + "\n";
report += " .NET Framework Version: " + Assembly report += " .NET Framework Version: " + Assembly
.GetExecutingAssembly() .GetExecutingAssembly()

View File

@ -13,12 +13,16 @@ namespace IO.Swagger.Model {
[DataContract] [DataContract]
public class Category { public class Category {
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)] [DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; } public long? Id { get; set; }
/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name="name", EmitDefaultValue=false)] [DataMember(Name="name", EmitDefaultValue=false)]
public string Name { get; set; } public string Name { get; set; }

View File

@ -13,32 +13,45 @@ namespace IO.Swagger.Model {
[DataContract] [DataContract]
public class Order { public class Order {
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)] [DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; } public long? Id { get; set; }
/// <summary>
/// Gets or Sets PetId
/// </summary>
[DataMember(Name="petId", EmitDefaultValue=false)] [DataMember(Name="petId", EmitDefaultValue=false)]
public long? PetId { get; set; } public long? PetId { get; set; }
/// <summary>
/// Gets or Sets Quantity
/// </summary>
[DataMember(Name="quantity", EmitDefaultValue=false)] [DataMember(Name="quantity", EmitDefaultValue=false)]
public int? Quantity { get; set; } public int? Quantity { get; set; }
/// <summary>
/// Gets or Sets ShipDate
/// </summary>
[DataMember(Name="shipDate", EmitDefaultValue=false)] [DataMember(Name="shipDate", EmitDefaultValue=false)]
public DateTime? ShipDate { get; set; } public DateTime? ShipDate { get; set; }
/* Order Status */ /// <summary>
/// Order Status
/// </summary>
/// <value>Order Status</value>
[DataMember(Name="status", EmitDefaultValue=false)] [DataMember(Name="status", EmitDefaultValue=false)]
public string Status { get; set; } public string Status { get; set; }
/// <summary>
/// Gets or Sets Complete
/// </summary>
[DataMember(Name="complete", EmitDefaultValue=false)] [DataMember(Name="complete", EmitDefaultValue=false)]
public bool? Complete { get; set; } public bool? Complete { get; set; }

View File

@ -13,32 +13,45 @@ namespace IO.Swagger.Model {
[DataContract] [DataContract]
public class Pet { public class Pet {
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)] [DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; } public long? Id { get; set; }
/// <summary>
/// Gets or Sets Category
/// </summary>
[DataMember(Name="category", EmitDefaultValue=false)] [DataMember(Name="category", EmitDefaultValue=false)]
public Category Category { get; set; } public Category Category { get; set; }
/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name="name", EmitDefaultValue=false)] [DataMember(Name="name", EmitDefaultValue=false)]
public string Name { get; set; } public string Name { get; set; }
/// <summary>
/// Gets or Sets PhotoUrls
/// </summary>
[DataMember(Name="photoUrls", EmitDefaultValue=false)] [DataMember(Name="photoUrls", EmitDefaultValue=false)]
public List<string> PhotoUrls { get; set; } public List<string> PhotoUrls { get; set; }
/// <summary>
/// Gets or Sets Tags
/// </summary>
[DataMember(Name="tags", EmitDefaultValue=false)] [DataMember(Name="tags", EmitDefaultValue=false)]
public List<Tag> Tags { get; set; } public List<Tag> Tags { get; set; }
/* pet status in the store */ /// <summary>
/// pet status in the store
/// </summary>
/// <value>pet status in the store</value>
[DataMember(Name="status", EmitDefaultValue=false)] [DataMember(Name="status", EmitDefaultValue=false)]
public string Status { get; set; } public string Status { get; set; }

View File

@ -13,12 +13,16 @@ namespace IO.Swagger.Model {
[DataContract] [DataContract]
public class Tag { public class Tag {
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)] [DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; } public long? Id { get; set; }
/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name="name", EmitDefaultValue=false)] [DataMember(Name="name", EmitDefaultValue=false)]
public string Name { get; set; } public string Name { get; set; }

View File

@ -13,42 +13,59 @@ namespace IO.Swagger.Model {
[DataContract] [DataContract]
public class User { public class User {
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)] [DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; } public long? Id { get; set; }
/// <summary>
/// Gets or Sets Username
/// </summary>
[DataMember(Name="username", EmitDefaultValue=false)] [DataMember(Name="username", EmitDefaultValue=false)]
public string Username { get; set; } public string Username { get; set; }
/// <summary>
/// Gets or Sets FirstName
/// </summary>
[DataMember(Name="firstName", EmitDefaultValue=false)] [DataMember(Name="firstName", EmitDefaultValue=false)]
public string FirstName { get; set; } public string FirstName { get; set; }
/// <summary>
/// Gets or Sets LastName
/// </summary>
[DataMember(Name="lastName", EmitDefaultValue=false)] [DataMember(Name="lastName", EmitDefaultValue=false)]
public string LastName { get; set; } public string LastName { get; set; }
/// <summary>
/// Gets or Sets Email
/// </summary>
[DataMember(Name="email", EmitDefaultValue=false)] [DataMember(Name="email", EmitDefaultValue=false)]
public string Email { get; set; } public string Email { get; set; }
/// <summary>
/// Gets or Sets Password
/// </summary>
[DataMember(Name="password", EmitDefaultValue=false)] [DataMember(Name="password", EmitDefaultValue=false)]
public string Password { get; set; } public string Password { get; set; }
/// <summary>
/// Gets or Sets Phone
/// </summary>
[DataMember(Name="phone", EmitDefaultValue=false)] [DataMember(Name="phone", EmitDefaultValue=false)]
public string Phone { get; set; } public string Phone { get; set; }
/* User Status */ /// <summary>
/// User Status
/// </summary>
/// <value>User Status</value>
[DataMember(Name="userStatus", EmitDefaultValue=false)] [DataMember(Name="userStatus", EmitDefaultValue=false)]
public int? UserStatus { get; set; } public int? UserStatus { get; set; }

View File

@ -2,7 +2,7 @@
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" /> <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.Workbench ActiveDocument="TestPet.cs"> <MonoDevelop.Ide.Workbench ActiveDocument="TestPet.cs">
<Files> <Files>
<File FileName="TestPet.cs" Line="31" Column="19" /> <File FileName="TestPet.cs" Line="28" Column="64" />
</Files> </Files>
</MonoDevelop.Ide.Workbench> </MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints> <MonoDevelop.Ide.DebuggingService.Breakpoints>

View File

@ -1,8 +1,8 @@
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs /Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb /Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll /Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll /Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb /Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll