better comment on csharp api, add ParameterToString to handle date

This commit is contained in:
wing328 2015-04-29 16:27:08 +08:00
parent 96d837274e
commit e7b170bf3c
4 changed files with 93 additions and 122 deletions

View File

@ -41,15 +41,16 @@ namespace {{package}} {
/// {{summary}} {{notes}}
/// </summary>
{{#allParams}} /// <param name="{{paramName}}">{{description}}</param>
{{/allParams}} /// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
{{/allParams}}
/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
public {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
var _request = new RestRequest("{{path}}", Method.{{httpMethod}});
{{#requiredParams}}
// verify required param {{paramName}} is set
if ({{paramName}} == null) throw new ApiException(400, "missing required params {{paramName}}");
{{/requiredParams}}
{{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set
if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}");
{{/required}}{{/allParams}}
_request.AddUrlSegment("format", "json"); // set format to json by default
{{#pathParams}}_request.AddUrlSegment("{{baseName}}", ApiInvoker.ParameterToString({{{paramName}}})); // path (url segment) parameter
@ -58,17 +59,15 @@ namespace {{package}} {
{{/queryParams}}
{{#headerParams}} if ({{paramName}} != null) _request.AddHeader("{{baseName}}", ApiInvoker.ParameterToString({{paramName}})); // header parameter
{{/headerParams}}
{{#formParams}}if ({{paramName}} != null) {{#isFile}}_request.AddFile("{{baseName}}", {{paramName}});{{/isFile}}{{^isFile}}_request.AddParameter("{{baseName}}", ApiInvoker.ParameterToString({{paramName}}));{{/isFile}} // form parameter
{{#formParams}}if ({{paramName}} != null) {{#isFile}}_request.AddFile("{{baseName}}", {{paramName}});{{/isFile}}{{^isFile}}_request.AddParameter("{{baseName}}", ApiInvoker.ParameterToString({{paramName}})); // form parameter{{/isFile}}
{{/formParams}}
{{#bodyParam}}
_request.AddParameter("application/json", ApiInvoker.Serialize({{paramName}}), ParameterType.RequestBody); // HTTP request body (model)
{{#bodyParam}}_request.AddParameter("application/json", ApiInvoker.Serialize({{paramName}}), ParameterType.RequestBody); // http body (model) parameter
{{/bodyParam}}
try {
// make the HTTP request
{{#returnType}}IRestResponse response = restClient.Execute(_request);
return ({{{returnType}}}) ApiInvoker.Deserialize(response.Content, typeof({{{returnType}}}));
//return ((object)response) as {{{returnType}}};{{/returnType}}
{{^returnType}}restClient.Execute(_request);
return ({{{returnType}}}) ApiInvoker.Deserialize(response.Content, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}restClient.Execute(_request);
return;{{/returnType}}
} catch (Exception ex) {
if(ex != null) {

View File

@ -40,9 +40,7 @@ namespace io.swagger.Api {
/// </summary>
/// <param name="Body">Pet object that needs to be added to the store</param>
/// <returns></returns>
public void UpdatePet (Pet Body) {
// create path and map variables
var path = "/pet".Replace("{format}","json");
public void UpdatePet (Pet Body) {
var _request = new RestRequest("/pet", Method.PUT);
@ -53,12 +51,11 @@ namespace io.swagger.Api {
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // HTTP request body (model)
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // http body (model) parameter
try {
// make the HTTP request
restClient.Execute(_request);
return;
} catch (Exception ex) {
@ -77,9 +74,7 @@ namespace io.swagger.Api {
/// </summary>
/// <param name="Body">Pet object that needs to be added to the store</param>
/// <returns></returns>
public void AddPet (Pet Body) {
// create path and map variables
var path = "/pet".Replace("{format}","json");
public void AddPet (Pet Body) {
var _request = new RestRequest("/pet", Method.POST);
@ -90,12 +85,11 @@ namespace io.swagger.Api {
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // HTTP request body (model)
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // http body (model) parameter
try {
// make the HTTP request
restClient.Execute(_request);
return;
} catch (Exception ex) {
@ -113,10 +107,8 @@ namespace io.swagger.Api {
/// Finds Pets by status Multiple status values can be provided with comma seperated strings
/// </summary>
/// <param name="Status">Status values that need to be considered for filter</param>
/// <returns></returns>
public List<Pet> FindPetsByStatus (List<string> Status) {
// create path and map variables
var path = "/pet/findByStatus".Replace("{format}","json");
/// <returns>List<Pet></returns>
public List<Pet> FindPetsByStatus (List<string> Status) {
var _request = new RestRequest("/pet/findByStatus", Method.GET);
@ -131,10 +123,9 @@ namespace io.swagger.Api {
try {
// make the HTTP request
IRestResponse response = restClient.Execute(_request);
return (List<Pet>) ApiInvoker.Deserialize(response.Content, typeof(List<Pet>));
//return ((object)response) as List<Pet>;
} catch (Exception ex) {
if(ex != null) {
return null;
@ -150,10 +141,8 @@ namespace io.swagger.Api {
/// Finds Pets by tags Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
/// </summary>
/// <param name="Tags">Tags to filter by</param>
/// <returns></returns>
public List<Pet> FindPetsByTags (List<string> Tags) {
// create path and map variables
var path = "/pet/findByTags".Replace("{format}","json");
/// <returns>List<Pet></returns>
public List<Pet> FindPetsByTags (List<string> Tags) {
var _request = new RestRequest("/pet/findByTags", Method.GET);
@ -168,10 +157,9 @@ namespace io.swagger.Api {
try {
// make the HTTP request
IRestResponse response = restClient.Execute(_request);
return (List<Pet>) ApiInvoker.Deserialize(response.Content, typeof(List<Pet>));
//return ((object)response) as List<Pet>;
} catch (Exception ex) {
if(ex != null) {
return null;
@ -187,14 +175,15 @@ namespace io.swagger.Api {
/// Find pet by ID Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
/// </summary>
/// <param name="PetId">ID of pet that needs to be fetched</param>
/// <returns></returns>
public Pet GetPetById (long? PetId) {
// create path and map variables
var path = "/pet/{petId}".Replace("{format}","json").Replace("{" + "petId" + "}", apiInvoker.ParameterToString(PetId));
/// <returns>Pet</returns>
public Pet GetPetById (long? PetId) {
var _request = new RestRequest("/pet/{petId}", Method.GET);
// verify the required parameter 'PetId' is set
if (PetId == null) throw new ApiException(400, "Missing required parameter 'PetId' when calling GetPetById");
_request.AddUrlSegment("format", "json"); // set format to json by default
_request.AddUrlSegment("petId", ApiInvoker.ParameterToString(PetId)); // path (url segment) parameter
@ -205,10 +194,9 @@ namespace io.swagger.Api {
try {
// make the HTTP request
IRestResponse response = restClient.Execute(_request);
return (Pet) ApiInvoker.Deserialize(response.Content, typeof(Pet));
//return ((object)response) as Pet;
} catch (Exception ex) {
if(ex != null) {
return null;
@ -227,13 +215,14 @@ namespace io.swagger.Api {
/// <param name="Name">Updated name of the pet</param>
/// <param name="Status">Updated status of the pet</param>
/// <returns></returns>
public void UpdatePetWithForm (string PetId, string Name, string Status) {
// create path and map variables
var path = "/pet/{petId}".Replace("{format}","json").Replace("{" + "petId" + "}", apiInvoker.ParameterToString(PetId));
public void UpdatePetWithForm (string PetId, string Name, string Status) {
var _request = new RestRequest("/pet/{petId}", Method.POST);
// verify the required parameter 'PetId' is set
if (PetId == null) throw new ApiException(400, "Missing required parameter 'PetId' when calling UpdatePetWithForm");
_request.AddUrlSegment("format", "json"); // set format to json by default
_request.AddUrlSegment("petId", ApiInvoker.ParameterToString(PetId)); // path (url segment) parameter
@ -246,7 +235,7 @@ namespace io.swagger.Api {
try {
// make the HTTP request
restClient.Execute(_request);
return;
} catch (Exception ex) {
@ -266,13 +255,14 @@ namespace io.swagger.Api {
/// <param name="ApiKey"></param>
/// <param name="PetId">Pet id to delete</param>
/// <returns></returns>
public void DeletePet (string ApiKey, long? PetId) {
// create path and map variables
var path = "/pet/{petId}".Replace("{format}","json").Replace("{" + "petId" + "}", apiInvoker.ParameterToString(PetId));
public void DeletePet (string ApiKey, long? PetId) {
var _request = new RestRequest("/pet/{petId}", Method.DELETE);
// verify the required parameter 'PetId' is set
if (PetId == null) throw new ApiException(400, "Missing required parameter 'PetId' when calling DeletePet");
_request.AddUrlSegment("format", "json"); // set format to json by default
_request.AddUrlSegment("petId", ApiInvoker.ParameterToString(PetId)); // path (url segment) parameter
@ -284,7 +274,7 @@ namespace io.swagger.Api {
try {
// make the HTTP request
restClient.Execute(_request);
return;
} catch (Exception ex) {
@ -305,13 +295,14 @@ namespace io.swagger.Api {
/// <param name="AdditionalMetadata">Additional data to pass to server</param>
/// <param name="File">file to upload</param>
/// <returns></returns>
public void UploadFile (long? PetId, string AdditionalMetadata, byte[] File) {
// create path and map variables
var path = "/pet/{petId}/uploadImage".Replace("{format}","json").Replace("{" + "petId" + "}", apiInvoker.ParameterToString(PetId));
public void UploadFile (long? PetId, string AdditionalMetadata, string File) {
var _request = new RestRequest("/pet/{petId}/uploadImage", Method.POST);
// verify the required parameter 'PetId' is set
if (PetId == null) throw new ApiException(400, "Missing required parameter 'PetId' when calling UploadFile");
_request.AddUrlSegment("format", "json"); // set format to json by default
_request.AddUrlSegment("petId", ApiInvoker.ParameterToString(PetId)); // path (url segment) parameter
@ -319,12 +310,12 @@ namespace io.swagger.Api {
if (AdditionalMetadata != null) _request.AddParameter("additionalMetadata", ApiInvoker.ParameterToString(AdditionalMetadata)); // form parameter
if (File != null) _request.AddFile("file", File); // form parameter
if (File != null) _request.AddFile("file", File);
try {
// make the HTTP request
restClient.Execute(_request);
return;
} catch (Exception ex) {

View File

@ -38,10 +38,8 @@ namespace io.swagger.Api {
/// <summary>
/// Returns pet inventories by status Returns a map of status codes to quantities
/// </summary>
/// <returns></returns>
public Dictionary<String, int?> GetInventory () {
// create path and map variables
var path = "/store/inventory".Replace("{format}","json");
/// <returns>Dictionary<String, int?></returns>
public Dictionary<String, int?> GetInventory () {
var _request = new RestRequest("/store/inventory", Method.GET);
@ -55,10 +53,9 @@ namespace io.swagger.Api {
try {
// make the HTTP request
IRestResponse response = restClient.Execute(_request);
return (Dictionary<String, int?>) ApiInvoker.Deserialize(response.Content, typeof(Dictionary<String, int?>));
//return ((object)response) as Dictionary<String, int?>;
} catch (Exception ex) {
if(ex != null) {
return null;
@ -74,10 +71,8 @@ namespace io.swagger.Api {
/// Place an order for a pet
/// </summary>
/// <param name="Body">order placed for purchasing the pet</param>
/// <returns></returns>
public Order PlaceOrder (Order Body) {
// create path and map variables
var path = "/store/order".Replace("{format}","json");
/// <returns>Order</returns>
public Order PlaceOrder (Order Body) {
var _request = new RestRequest("/store/order", Method.POST);
@ -88,15 +83,13 @@ namespace io.swagger.Api {
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // HTTP request body (model)
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // http body (model) parameter
try {
// make the HTTP request
IRestResponse response = restClient.Execute(_request);
return (Order) ApiInvoker.Deserialize(response.Content, typeof(Order));
//return ((object)response) as Order;
} catch (Exception ex) {
if(ex != null) {
return null;
@ -112,14 +105,15 @@ namespace io.swagger.Api {
/// Find purchase order by ID For valid response try integer IDs with value &lt;= 5 or &gt; 10. Other values will generated exceptions
/// </summary>
/// <param name="OrderId">ID of pet that needs to be fetched</param>
/// <returns></returns>
public Order GetOrderById (string OrderId) {
// create path and map variables
var path = "/store/order/{orderId}".Replace("{format}","json").Replace("{" + "orderId" + "}", apiInvoker.ParameterToString(OrderId));
/// <returns>Order</returns>
public Order GetOrderById (string OrderId) {
var _request = new RestRequest("/store/order/{orderId}", Method.GET);
// verify the required parameter 'OrderId' is set
if (OrderId == null) throw new ApiException(400, "Missing required parameter 'OrderId' when calling GetOrderById");
_request.AddUrlSegment("format", "json"); // set format to json by default
_request.AddUrlSegment("orderId", ApiInvoker.ParameterToString(OrderId)); // path (url segment) parameter
@ -130,10 +124,9 @@ namespace io.swagger.Api {
try {
// make the HTTP request
IRestResponse response = restClient.Execute(_request);
return (Order) ApiInvoker.Deserialize(response.Content, typeof(Order));
//return ((object)response) as Order;
} catch (Exception ex) {
if(ex != null) {
return null;
@ -150,13 +143,14 @@ namespace io.swagger.Api {
/// </summary>
/// <param name="OrderId">ID of the order that needs to be deleted</param>
/// <returns></returns>
public void DeleteOrder (string OrderId) {
// create path and map variables
var path = "/store/order/{orderId}".Replace("{format}","json").Replace("{" + "orderId" + "}", apiInvoker.ParameterToString(OrderId));
public void DeleteOrder (string OrderId) {
var _request = new RestRequest("/store/order/{orderId}", Method.DELETE);
// verify the required parameter 'OrderId' is set
if (OrderId == null) throw new ApiException(400, "Missing required parameter 'OrderId' when calling DeleteOrder");
_request.AddUrlSegment("format", "json"); // set format to json by default
_request.AddUrlSegment("orderId", ApiInvoker.ParameterToString(OrderId)); // path (url segment) parameter
@ -167,7 +161,7 @@ namespace io.swagger.Api {
try {
// make the HTTP request
restClient.Execute(_request);
return;
} catch (Exception ex) {

View File

@ -40,9 +40,7 @@ namespace io.swagger.Api {
/// </summary>
/// <param name="Body">Created user object</param>
/// <returns></returns>
public void CreateUser (User Body) {
// create path and map variables
var path = "/user".Replace("{format}","json");
public void CreateUser (User Body) {
var _request = new RestRequest("/user", Method.POST);
@ -53,12 +51,11 @@ namespace io.swagger.Api {
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // HTTP request body (model)
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // http body (model) parameter
try {
// make the HTTP request
restClient.Execute(_request);
return;
} catch (Exception ex) {
@ -77,9 +74,7 @@ namespace io.swagger.Api {
/// </summary>
/// <param name="Body">List of user object</param>
/// <returns></returns>
public void CreateUsersWithArrayInput (List<User> Body) {
// create path and map variables
var path = "/user/createWithArray".Replace("{format}","json");
public void CreateUsersWithArrayInput (List<User> Body) {
var _request = new RestRequest("/user/createWithArray", Method.POST);
@ -90,12 +85,11 @@ namespace io.swagger.Api {
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // HTTP request body (model)
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // http body (model) parameter
try {
// make the HTTP request
restClient.Execute(_request);
return;
} catch (Exception ex) {
@ -114,9 +108,7 @@ namespace io.swagger.Api {
/// </summary>
/// <param name="Body">List of user object</param>
/// <returns></returns>
public void CreateUsersWithListInput (List<User> Body) {
// create path and map variables
var path = "/user/createWithList".Replace("{format}","json");
public void CreateUsersWithListInput (List<User> Body) {
var _request = new RestRequest("/user/createWithList", Method.POST);
@ -127,12 +119,11 @@ namespace io.swagger.Api {
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // HTTP request body (model)
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // http body (model) parameter
try {
// make the HTTP request
restClient.Execute(_request);
return;
} catch (Exception ex) {
@ -151,11 +142,8 @@ namespace io.swagger.Api {
/// </summary>
/// <param name="Username">The user name for login</param>
/// <param name="Password">The password for login in clear text</param>
/// <returns></returns>
public string LoginUser (string Username, string Password) {
// create path and map variables
var path = "/user/login".Replace("{format}","json");
/// <returns>string</returns>
public string LoginUser (string Username, string Password) {
var _request = new RestRequest("/user/login", Method.GET);
@ -171,10 +159,9 @@ namespace io.swagger.Api {
try {
// make the HTTP request
IRestResponse response = restClient.Execute(_request);
return (string) ApiInvoker.Deserialize(response.Content, typeof(string));
//return ((object)response) as string;
} catch (Exception ex) {
if(ex != null) {
return null;
@ -190,9 +177,7 @@ namespace io.swagger.Api {
/// Logs out current logged in user session
/// </summary>
/// <returns></returns>
public void LogoutUser () {
// create path and map variables
var path = "/user/logout".Replace("{format}","json");
public void LogoutUser () {
var _request = new RestRequest("/user/logout", Method.GET);
@ -206,7 +191,7 @@ namespace io.swagger.Api {
try {
// make the HTTP request
restClient.Execute(_request);
return;
} catch (Exception ex) {
@ -224,13 +209,15 @@ namespace io.swagger.Api {
/// Get user by user name
/// </summary>
/// <param name="Username">The name that needs to be fetched. Use user1 for testing. </param>
public User GetUserByName (string Username) {
// create path and map variables
var path = "/user/{username}".Replace("{format}","json").Replace("{" + "username" + "}", apiInvoker.ParameterToString(Username));
/// <returns>User</returns>
public User GetUserByName (string Username) {
var _request = new RestRequest("/user/{username}", Method.GET);
// verify the required parameter 'Username' is set
if (Username == null) throw new ApiException(400, "Missing required parameter 'Username' when calling GetUserByName");
_request.AddUrlSegment("format", "json"); // set format to json by default
_request.AddUrlSegment("username", ApiInvoker.ParameterToString(Username)); // path (url segment) parameter
@ -241,10 +228,9 @@ namespace io.swagger.Api {
try {
// make the HTTP request
IRestResponse response = restClient.Execute(_request);
return (User) ApiInvoker.Deserialize(response.Content, typeof(User));
//return ((object)response) as User;
} catch (Exception ex) {
if(ex != null) {
return null;
@ -262,13 +248,14 @@ namespace io.swagger.Api {
/// <param name="Username">name that need to be deleted</param>
/// <param name="Body">Updated user object</param>
/// <returns></returns>
public void UpdateUser (string Username, User Body) {
// create path and map variables
var path = "/user/{username}".Replace("{format}","json").Replace("{" + "username" + "}", apiInvoker.ParameterToString(Username));
public void UpdateUser (string Username, User Body) {
var _request = new RestRequest("/user/{username}", Method.PUT);
// verify the required parameter 'Username' is set
if (Username == null) throw new ApiException(400, "Missing required parameter 'Username' when calling UpdateUser");
_request.AddUrlSegment("format", "json"); // set format to json by default
_request.AddUrlSegment("username", ApiInvoker.ParameterToString(Username)); // path (url segment) parameter
@ -276,12 +263,11 @@ namespace io.swagger.Api {
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // HTTP request body (model)
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // http body (model) parameter
try {
// make the HTTP request
restClient.Execute(_request);
return;
} catch (Exception ex) {
@ -300,13 +286,14 @@ namespace io.swagger.Api {
/// </summary>
/// <param name="Username">The name that needs to be deleted</param>
/// <returns></returns>
public void DeleteUser (string Username) {
// create path and map variables
var path = "/user/{username}".Replace("{format}","json").Replace("{" + "username" + "}", apiInvoker.ParameterToString(Username));
public void DeleteUser (string Username) {
var _request = new RestRequest("/user/{username}", Method.DELETE);
// verify the required parameter 'Username' is set
if (Username == null) throw new ApiException(400, "Missing required parameter 'Username' when calling DeleteUser");
_request.AddUrlSegment("format", "json"); // set format to json by default
_request.AddUrlSegment("username", ApiInvoker.ParameterToString(Username)); // path (url segment) parameter
@ -317,7 +304,7 @@ namespace io.swagger.Api {
try {
// make the HTTP request
restClient.Execute(_request);
return;
} catch (Exception ex) {