diff --git a/modules/swagger-codegen/src/main/resources/csharp/api.mustache b/modules/swagger-codegen/src/main/resources/csharp/api.mustache index 0853c9f95ea..bb72037bad9 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/api.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/api.mustache @@ -1,6 +1,7 @@ using System; using System.IO; using System.Collections.Generic; +using System.Linq; using RestSharp; using {{packageName}}.Client; {{#hasImport}}using {{packageName}}.Model; @@ -90,6 +91,16 @@ namespace {{packageName}}.Api /// /// An instance of the Configuration public Configuration Configuration {get; set;} + + /// + /// Gets the status code of the previous request + /// + public int StatusCode { get; private set; } + + /// + /// Gets the response headers of the previous request + /// + public Dictionary ResponseHeaders { get; private set; } {{#operation}} /// @@ -162,11 +173,14 @@ namespace {{packageName}}.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling {{operationId}}: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling {{operationId}}: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling {{operationId}}: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling {{operationId}}: " + response.ErrorMessage, response.ErrorMessage); {{#returnType}}return ({{{returnType}}}) Configuration.ApiClient.Deserialize(response, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}return;{{/returnType}} } @@ -240,8 +254,12 @@ namespace {{packageName}}.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling {{operationId}}: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling {{operationId}}: " + response.Content, response.Content); {{#returnType}}return ({{{returnType}}}) Configuration.ApiClient.Deserialize(response, typeof({{{returnType}}}));{{/returnType}}{{^returnType}} return;{{/returnType}} 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 02a5cbd53ec..2b4f77bf4de 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 @@ -1,6 +1,7 @@ using System; using System.IO; using System.Collections.Generic; +using System.Linq; using RestSharp; using IO.Swagger.Client; using IO.Swagger.Model; @@ -203,7 +204,7 @@ namespace IO.Swagger.Api /// /// Initializes a new instance of the class - /// using Configuration object + /// using Configuration object. /// /// An instance of Configuration /// @@ -235,11 +236,20 @@ namespace IO.Swagger.Api } /// - /// Gets or sets the configuration object + /// Gets or sets the configuration object. /// /// An instance of the Configuration public Configuration Configuration {get; set;} - + + /// + /// Gets the status code of the previous request. + /// + public int StatusCode { get; private set; } + + /// + /// Gets the response headers of the previous request. + /// + public Dictionary ResponseHeaders { get; private set; } /// /// Update an existing pet @@ -289,11 +299,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling UpdatePet: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling UpdatePet: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling UpdatePet: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling UpdatePet: " + response.ErrorMessage, response.ErrorMessage); return; } @@ -346,8 +359,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling UpdatePet: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling UpdatePet: " + response.Content, response.Content); return; @@ -401,11 +418,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling AddPet: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling AddPet: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling AddPet: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling AddPet: " + response.ErrorMessage, response.ErrorMessage); return; } @@ -458,8 +478,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling AddPet: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling AddPet: " + response.Content, response.Content); return; @@ -513,11 +537,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling FindPetsByStatus: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling FindPetsByStatus: " + response.ErrorMessage, response.ErrorMessage); return (List) Configuration.ApiClient.Deserialize(response, typeof(List)); } @@ -570,8 +597,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling FindPetsByStatus: " + response.Content, response.Content); return (List) Configuration.ApiClient.Deserialize(response, typeof(List)); } @@ -624,11 +655,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling FindPetsByTags: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling FindPetsByTags: " + response.ErrorMessage, response.ErrorMessage); return (List) Configuration.ApiClient.Deserialize(response, typeof(List)); } @@ -681,8 +715,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling FindPetsByTags: " + response.Content, response.Content); return (List) Configuration.ApiClient.Deserialize(response, typeof(List)); } @@ -738,11 +776,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling GetPetById: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling GetPetById: " + response.ErrorMessage, response.ErrorMessage); return (Pet) Configuration.ApiClient.Deserialize(response, typeof(Pet)); } @@ -797,8 +838,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling GetPetById: " + response.Content, response.Content); return (Pet) Configuration.ApiClient.Deserialize(response, typeof(Pet)); } @@ -858,11 +903,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling UpdatePetWithForm: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling UpdatePetWithForm: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling UpdatePetWithForm: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling UpdatePetWithForm: " + response.ErrorMessage, response.ErrorMessage); return; } @@ -921,8 +969,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling UpdatePetWithForm: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling UpdatePetWithForm: " + response.Content, response.Content); return; @@ -981,11 +1033,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling DeletePet: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling DeletePet: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling DeletePet: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling DeletePet: " + response.ErrorMessage, response.ErrorMessage); return; } @@ -1042,8 +1097,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling DeletePet: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling DeletePet: " + response.Content, response.Content); return; @@ -1104,11 +1163,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling UploadFile: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling UploadFile: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling UploadFile: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling UploadFile: " + response.ErrorMessage, response.ErrorMessage); return; } @@ -1167,8 +1229,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling UploadFile: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling UploadFile: " + response.Content, response.Content); return; 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 90f59746fca..dafb93d9458 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 @@ -1,6 +1,7 @@ using System; using System.IO; using System.Collections.Generic; +using System.Linq; using RestSharp; using IO.Swagger.Client; using IO.Swagger.Model; @@ -147,6 +148,16 @@ namespace IO.Swagger.Api /// /// An instance of the Configuration public Configuration Configuration {get; set;} + + /// + /// Gets the status code of the previous request + /// + public int StatusCode { get; private set; } + + /// + /// Gets the response headers of the previous request + /// + public Dictionary ResponseHeaders { get; private set; } /// @@ -195,11 +206,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling GetInventory: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling GetInventory: " + response.ErrorMessage, response.ErrorMessage); return (Dictionary) Configuration.ApiClient.Deserialize(response, typeof(Dictionary)); } @@ -250,8 +264,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling GetInventory: " + response.Content, response.Content); return (Dictionary) Configuration.ApiClient.Deserialize(response, typeof(Dictionary)); } @@ -296,11 +314,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling PlaceOrder: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling PlaceOrder: " + response.ErrorMessage, response.ErrorMessage); return (Order) Configuration.ApiClient.Deserialize(response, typeof(Order)); } @@ -345,8 +366,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling PlaceOrder: " + response.Content, response.Content); return (Order) Configuration.ApiClient.Deserialize(response, typeof(Order)); } @@ -394,11 +419,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling GetOrderById: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling GetOrderById: " + response.ErrorMessage, response.ErrorMessage); return (Order) Configuration.ApiClient.Deserialize(response, typeof(Order)); } @@ -445,8 +473,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling GetOrderById: " + response.Content, response.Content); return (Order) Configuration.ApiClient.Deserialize(response, typeof(Order)); } @@ -494,11 +526,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling DeleteOrder: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling DeleteOrder: " + response.ErrorMessage, response.ErrorMessage); return; } @@ -545,8 +580,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling DeleteOrder: " + response.Content, response.Content); return; diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/UserApi.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/UserApi.cs index 01127fb340f..c2c23cddfc2 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/UserApi.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/UserApi.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Collections.Generic; +using System.Linq; using RestSharp; using IO.Swagger.Client; using IO.Swagger.Model; @@ -231,6 +232,16 @@ namespace IO.Swagger.Api /// /// An instance of the Configuration public Configuration Configuration {get; set;} + + /// + /// Gets the status code of the previous request + /// + public int StatusCode { get; private set; } + + /// + /// Gets the response headers of the previous request + /// + public Dictionary ResponseHeaders { get; private set; } /// @@ -273,11 +284,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling CreateUser: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling CreateUser: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling CreateUser: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling CreateUser: " + response.ErrorMessage, response.ErrorMessage); return; } @@ -322,8 +336,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling CreateUser: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling CreateUser: " + response.Content, response.Content); return; @@ -369,11 +387,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithArrayInput: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling CreateUsersWithArrayInput: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithArrayInput: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling CreateUsersWithArrayInput: " + response.ErrorMessage, response.ErrorMessage); return; } @@ -418,8 +439,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithArrayInput: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling CreateUsersWithArrayInput: " + response.Content, response.Content); return; @@ -465,11 +490,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithListInput: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling CreateUsersWithListInput: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithListInput: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling CreateUsersWithListInput: " + response.ErrorMessage, response.ErrorMessage); return; } @@ -514,8 +542,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithListInput: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling CreateUsersWithListInput: " + response.Content, response.Content); return; @@ -563,11 +595,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling LoginUser: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling LoginUser: " + response.ErrorMessage, response.ErrorMessage); return (string) Configuration.ApiClient.Deserialize(response, typeof(string)); } @@ -614,8 +649,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling LoginUser: " + response.Content, response.Content); return (string) Configuration.ApiClient.Deserialize(response, typeof(string)); } @@ -658,11 +697,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling LogoutUser: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling LogoutUser: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling LogoutUser: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling LogoutUser: " + response.ErrorMessage, response.ErrorMessage); return; } @@ -705,8 +747,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling LogoutUser: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling LogoutUser: " + response.Content, response.Content); return; @@ -755,11 +801,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling GetUserByName: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling GetUserByName: " + response.ErrorMessage, response.ErrorMessage); return (User) Configuration.ApiClient.Deserialize(response, typeof(User)); } @@ -806,8 +855,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling GetUserByName: " + response.Content, response.Content); return (User) Configuration.ApiClient.Deserialize(response, typeof(User)); } @@ -857,11 +910,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling UpdateUser: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling UpdateUser: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling UpdateUser: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling UpdateUser: " + response.ErrorMessage, response.ErrorMessage); return; } @@ -910,8 +966,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling UpdateUser: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling UpdateUser: " + response.Content, response.Content); return; @@ -960,11 +1020,14 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, pathParams); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling DeleteUser: " + response.Content, response.Content); + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling DeleteUser: " + response.Content, response.Content); else if (((int)response.StatusCode) == 0) - throw new ApiException ((int)response.StatusCode, "Error calling DeleteUser: " + response.ErrorMessage, response.ErrorMessage); + throw new ApiException (StatusCode, "Error calling DeleteUser: " + response.ErrorMessage, response.ErrorMessage); return; } @@ -1011,8 +1074,12 @@ namespace IO.Swagger.Api // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, pathParams); - if (((int)response.StatusCode) >= 400) - throw new ApiException ((int)response.StatusCode, "Error calling DeleteUser: " + response.Content, response.Content); + + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + + if (StatusCode >= 400) + throw new ApiException (StatusCode, "Error calling DeleteUser: " + response.Content, response.Content); return; diff --git a/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs b/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs index e9169da9832..2bd9b8ac733 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs @@ -229,6 +229,19 @@ namespace SwaggerClient.TestPet } + /// + /// Test status code + /// + [Test ()] + public void TestStatusCodeAndHeader () + { + PetApi petApi = new PetApi (); + petApi.GetPetById (petId); + Assert.AreEqual (petApi.StatusCode, 200); + Assert.IsTrue (petApi.ResponseHeaders.ContainsKey("Content-Type")); + Assert.AreEqual (petApi.ResponseHeaders["Content-Type"], "application/json"); + } + } } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll index 955673ab9a4..e26e6d019c2 100755 Binary files a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll and b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll differ diff --git a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb index bf97cbbd6cb..c798dc28827 100644 Binary files a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb and b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb differ diff --git a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll index 955673ab9a4..e26e6d019c2 100755 Binary files a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll and b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll differ diff --git a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb index bf97cbbd6cb..c798dc28827 100644 Binary files a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb and b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb differ