diff --git a/samples/client/petstore/csharp/SwaggerClient/IO.Swagger.sln b/samples/client/petstore/csharp/SwaggerClient/IO.Swagger.sln index c0a42faae52..740ca6561ac 100644 --- a/samples/client/petstore/csharp/SwaggerClient/IO.Swagger.sln +++ b/samples/client/petstore/csharp/SwaggerClient/IO.Swagger.sln @@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 VisualStudioVersion = 12.0.0.0 MinimumVisualStudioVersion = 10.0.0.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{C81D6286-7BA5-4920-8591-F59169CCE4A4}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{EE727567-9CAF-4258-AA0E-FDF89487D7D6}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger.Test", "src\IO.Swagger.Test\IO.Swagger.Test.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}" EndProject @@ -12,10 +12,10 @@ Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution -{C81D6286-7BA5-4920-8591-F59169CCE4A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU -{C81D6286-7BA5-4920-8591-F59169CCE4A4}.Debug|Any CPU.Build.0 = Debug|Any CPU -{C81D6286-7BA5-4920-8591-F59169CCE4A4}.Release|Any CPU.ActiveCfg = Release|Any CPU -{C81D6286-7BA5-4920-8591-F59169CCE4A4}.Release|Any CPU.Build.0 = Release|Any CPU +{EE727567-9CAF-4258-AA0E-FDF89487D7D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{EE727567-9CAF-4258-AA0E-FDF89487D7D6}.Debug|Any CPU.Build.0 = Debug|Any CPU +{EE727567-9CAF-4258-AA0E-FDF89487D7D6}.Release|Any CPU.ActiveCfg = Release|Any CPU +{EE727567-9CAF-4258-AA0E-FDF89487D7D6}.Release|Any CPU.Build.0 = Release|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/samples/client/petstore/csharp/SwaggerClient/README.md b/samples/client/petstore/csharp/SwaggerClient/README.md index d9dcb59b2da..c94e740d7b3 100644 --- a/samples/client/petstore/csharp/SwaggerClient/README.md +++ b/samples/client/petstore/csharp/SwaggerClient/README.md @@ -6,7 +6,7 @@ This C# SDK is automatically generated by the [Swagger Codegen](https://github.c - API version: 1.0.0 - SDK version: 1.0.0 -- Build date: 2016-05-29T17:27:36.037+08:00 +- Build date: 2016-06-10T08:07:39.769-04:00 - Build package: class io.swagger.codegen.languages.CSharpClientCodegen ## Frameworks supported @@ -54,7 +54,7 @@ namespace Example { var apiInstance = new FakeApi(); - var number = 3.4; // double? | None + var number = 3.4; // decimal? | None var _double = 1.2; // double? | None var _string = _string_example; // string | None var _byte = B; // byte[] | None @@ -138,12 +138,6 @@ Class | Method | HTTP request | Description ## Documentation for Authorization -### api_key - -- **Type**: API key -- **API key parameter name**: api_key -- **Location**: HTTP header - ### petstore_auth - **Type**: OAuth @@ -153,3 +147,9 @@ Class | Method | HTTP request | Description - write:pets: modify pets in your account - read:pets: read your pets +### api_key + +- **Type**: API key +- **API key parameter name**: api_key +- **Location**: HTTP header + diff --git a/samples/client/petstore/csharp/SwaggerClient/docs/FakeApi.md b/samples/client/petstore/csharp/SwaggerClient/docs/FakeApi.md index e4325274999..cc24d4dfa07 100644 --- a/samples/client/petstore/csharp/SwaggerClient/docs/FakeApi.md +++ b/samples/client/petstore/csharp/SwaggerClient/docs/FakeApi.md @@ -8,7 +8,7 @@ Method | HTTP request | Description # **TestEndpointParameters** -> void TestEndpointParameters (double? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null) +> void TestEndpointParameters (decimal? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null) Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -30,7 +30,7 @@ namespace Example { var apiInstance = new FakeApi(); - var number = 3.4; // double? | None + var number = 3.4; // decimal? | None var _double = 1.2; // double? | None var _string = _string_example; // string | None var _byte = B; // byte[] | None @@ -61,7 +61,7 @@ namespace Example Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **number** | **double?**| None | + **number** | **decimal?**| None | **_double** | **double?**| None | **_string** | **string**| None | **_byte** | **byte[]**| None | diff --git a/samples/client/petstore/csharp/SwaggerClient/docs/FormatTest.md b/samples/client/petstore/csharp/SwaggerClient/docs/FormatTest.md index 7ddfad04d05..1d366bd7cab 100644 --- a/samples/client/petstore/csharp/SwaggerClient/docs/FormatTest.md +++ b/samples/client/petstore/csharp/SwaggerClient/docs/FormatTest.md @@ -6,7 +6,7 @@ Name | Type | Description | Notes **Integer** | **int?** | | [optional] **Int32** | **int?** | | [optional] **Int64** | **long?** | | [optional] -**Number** | **double?** | | +**Number** | **decimal?** | | **_Float** | **float?** | | [optional] **_Double** | **double?** | | [optional] **_String** | **string** | | [optional] diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger.Test/IO.Swagger.Test.csproj b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger.Test/IO.Swagger.Test.csproj index 4e4b161e255..2cc0dd9525c 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger.Test/IO.Swagger.Test.csproj +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger.Test/IO.Swagger.Test.csproj @@ -86,7 +86,7 @@ limitations under the License. - {C81D6286-7BA5-4920-8591-F59169CCE4A4} + {EE727567-9CAF-4258-AA0E-FDF89487D7D6} IO.Swagger diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/FakeApi.cs b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/FakeApi.cs index 00ce83ef910..973771809a2 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/FakeApi.cs @@ -55,7 +55,7 @@ namespace IO.Swagger.Api /// None (optional) /// None (optional) /// - void TestEndpointParameters (double? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null); + void TestEndpointParameters (decimal? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -77,7 +77,7 @@ namespace IO.Swagger.Api /// None (optional) /// None (optional) /// ApiResponse of Object(void) - ApiResponse TestEndpointParametersWithHttpInfo (double? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null); + ApiResponse TestEndpointParametersWithHttpInfo (decimal? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null); #endregion Synchronous Operations #region Asynchronous Operations /// @@ -100,7 +100,7 @@ namespace IO.Swagger.Api /// None (optional) /// None (optional) /// Task of void - System.Threading.Tasks.Task TestEndpointParametersAsync (double? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null); + System.Threading.Tasks.Task TestEndpointParametersAsync (decimal? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -122,7 +122,7 @@ namespace IO.Swagger.Api /// None (optional) /// None (optional) /// Task of ApiResponse - System.Threading.Tasks.Task> TestEndpointParametersAsyncWithHttpInfo (double? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null); + System.Threading.Tasks.Task> TestEndpointParametersAsyncWithHttpInfo (decimal? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null); #endregion Asynchronous Operations } @@ -131,6 +131,8 @@ namespace IO.Swagger.Api /// public partial class FakeApi : IFakeApi { + private IO.Swagger.Client.ExceptionFactory _exceptionFactory = (name, response) => null; + /// /// Initializes a new instance of the class. /// @@ -139,6 +141,8 @@ namespace IO.Swagger.Api { this.Configuration = new Configuration(new ApiClient(basePath)); + ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory; + // ensure API client has configuration ready if (Configuration.ApiClient.Configuration == null) { @@ -159,6 +163,8 @@ namespace IO.Swagger.Api else this.Configuration = configuration; + ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory; + // ensure API client has configuration ready if (Configuration.ApiClient.Configuration == null) { @@ -191,6 +197,22 @@ namespace IO.Swagger.Api /// An instance of the Configuration public Configuration Configuration {get; set;} + /// + /// Provides a factory method hook for the creation of exceptions. + /// + public IO.Swagger.Client.ExceptionFactory ExceptionFactory + { + get + { + if (_exceptionFactory != null && _exceptionFactory.GetInvocationList().Length > 1) + { + throw new InvalidOperationException("Multicast delegate for ExceptionFactory is unsupported."); + } + return _exceptionFactory; + } + set { _exceptionFactory = value; } + } + /// /// Gets the default header. /// @@ -230,7 +252,7 @@ namespace IO.Swagger.Api /// None (optional) /// None (optional) /// - public void TestEndpointParameters (double? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null) + public void TestEndpointParameters (decimal? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null) { TestEndpointParametersWithHttpInfo(number, _double, _string, _byte, integer, int32, int64, _float, binary, date, dateTime, password); } @@ -252,7 +274,7 @@ namespace IO.Swagger.Api /// None (optional) /// None (optional) /// ApiResponse of Object(void) - public ApiResponse TestEndpointParametersWithHttpInfo (double? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null) + public ApiResponse TestEndpointParametersWithHttpInfo (decimal? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null) { // verify the required parameter 'number' is set if (number == null) @@ -315,10 +337,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling TestEndpointParameters: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling TestEndpointParameters: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("TestEndpointParameters", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -343,7 +366,7 @@ namespace IO.Swagger.Api /// None (optional) /// None (optional) /// Task of void - public async System.Threading.Tasks.Task TestEndpointParametersAsync (double? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null) + public async System.Threading.Tasks.Task TestEndpointParametersAsync (decimal? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null) { await TestEndpointParametersAsyncWithHttpInfo(number, _double, _string, _byte, integer, int32, int64, _float, binary, date, dateTime, password); @@ -366,7 +389,7 @@ namespace IO.Swagger.Api /// None (optional) /// None (optional) /// Task of ApiResponse - public async System.Threading.Tasks.Task> TestEndpointParametersAsyncWithHttpInfo (double? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null) + public async System.Threading.Tasks.Task> TestEndpointParametersAsyncWithHttpInfo (decimal? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null) { // verify the required parameter 'number' is set if (number == null) @@ -429,10 +452,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling TestEndpointParameters: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling TestEndpointParameters: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("TestEndpointParameters", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/PetApi.cs b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/PetApi.cs index e147d33cceb..abf5a0595b2 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/PetApi.cs +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/PetApi.cs @@ -402,6 +402,8 @@ namespace IO.Swagger.Api /// public partial class PetApi : IPetApi { + private IO.Swagger.Client.ExceptionFactory _exceptionFactory = (name, response) => null; + /// /// Initializes a new instance of the class. /// @@ -410,6 +412,8 @@ namespace IO.Swagger.Api { this.Configuration = new Configuration(new ApiClient(basePath)); + ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory; + // ensure API client has configuration ready if (Configuration.ApiClient.Configuration == null) { @@ -430,6 +434,8 @@ namespace IO.Swagger.Api else this.Configuration = configuration; + ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory; + // ensure API client has configuration ready if (Configuration.ApiClient.Configuration == null) { @@ -462,6 +468,22 @@ namespace IO.Swagger.Api /// An instance of the Configuration public Configuration Configuration {get; set;} + /// + /// Provides a factory method hook for the creation of exceptions. + /// + public IO.Swagger.Client.ExceptionFactory ExceptionFactory + { + get + { + if (_exceptionFactory != null && _exceptionFactory.GetInvocationList().Length > 1) + { + throw new InvalidOperationException("Multicast delegate for ExceptionFactory is unsupported."); + } + return _exceptionFactory; + } + set { _exceptionFactory = value; } + } + /// /// Gets the default header. /// @@ -557,10 +579,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling AddPet: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling AddPet: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("AddPet", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -642,10 +665,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling AddPet: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling AddPet: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("AddPet", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -720,10 +744,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling DeletePet: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling DeletePet: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("DeletePet", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -799,10 +824,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling DeletePet: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling DeletePet: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("DeletePet", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -875,10 +901,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling FindPetsByStatus: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling FindPetsByStatus: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("FindPetsByStatus", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), @@ -952,10 +979,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling FindPetsByStatus: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling FindPetsByStatus: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("FindPetsByStatus", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), @@ -1028,10 +1056,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling FindPetsByTags: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling FindPetsByTags: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("FindPetsByTags", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), @@ -1105,10 +1134,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling FindPetsByTags: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling FindPetsByTags: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("FindPetsByTags", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), @@ -1181,10 +1211,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling GetPetById: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling GetPetById: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("GetPetById", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), @@ -1257,10 +1288,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling GetPetById: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling GetPetById: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("GetPetById", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), @@ -1341,10 +1373,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling UpdatePet: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling UpdatePet: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("UpdatePet", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -1426,10 +1459,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling UpdatePet: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling UpdatePet: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("UpdatePet", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -1508,10 +1542,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling UpdatePetWithForm: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling UpdatePetWithForm: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("UpdatePetWithForm", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -1591,10 +1626,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling UpdatePetWithForm: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling UpdatePetWithForm: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("UpdatePetWithForm", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -1673,10 +1709,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling UploadFile: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling UploadFile: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("UploadFile", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), @@ -1756,10 +1793,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling UploadFile: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling UploadFile: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("UploadFile", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/StoreApi.cs b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/StoreApi.cs index ed5dd54ec40..3fbbe71b8ca 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/StoreApi.cs +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/StoreApi.cs @@ -210,6 +210,8 @@ namespace IO.Swagger.Api /// public partial class StoreApi : IStoreApi { + private IO.Swagger.Client.ExceptionFactory _exceptionFactory = (name, response) => null; + /// /// Initializes a new instance of the class. /// @@ -218,6 +220,8 @@ namespace IO.Swagger.Api { this.Configuration = new Configuration(new ApiClient(basePath)); + ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory; + // ensure API client has configuration ready if (Configuration.ApiClient.Configuration == null) { @@ -238,6 +242,8 @@ namespace IO.Swagger.Api else this.Configuration = configuration; + ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory; + // ensure API client has configuration ready if (Configuration.ApiClient.Configuration == null) { @@ -270,6 +276,22 @@ namespace IO.Swagger.Api /// An instance of the Configuration public Configuration Configuration {get; set;} + /// + /// Provides a factory method hook for the creation of exceptions. + /// + public IO.Swagger.Client.ExceptionFactory ExceptionFactory + { + get + { + if (_exceptionFactory != null && _exceptionFactory.GetInvocationList().Length > 1) + { + throw new InvalidOperationException("Multicast delegate for ExceptionFactory is unsupported."); + } + return _exceptionFactory; + } + set { _exceptionFactory = value; } + } + /// /// Gets the default header. /// @@ -350,10 +372,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling DeleteOrder: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling DeleteOrder: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("DeleteOrder", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -420,10 +443,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling DeleteOrder: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling DeleteOrder: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("DeleteOrder", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -489,10 +513,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling GetInventory: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling GetInventory: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("GetInventory", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), @@ -558,10 +583,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling GetInventory: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling GetInventory: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("GetInventory", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), @@ -628,10 +654,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling GetOrderById: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling GetOrderById: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("GetOrderById", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), @@ -699,10 +726,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling GetOrderById: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling GetOrderById: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("GetOrderById", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), @@ -776,10 +804,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling PlaceOrder: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling PlaceOrder: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("PlaceOrder", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), @@ -854,10 +883,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling PlaceOrder: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling PlaceOrder: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("PlaceOrder", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/UserApi.cs b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/UserApi.cs index 6cb5bee041c..6fb6244264e 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/UserApi.cs +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/UserApi.cs @@ -386,6 +386,8 @@ namespace IO.Swagger.Api /// public partial class UserApi : IUserApi { + private IO.Swagger.Client.ExceptionFactory _exceptionFactory = (name, response) => null; + /// /// Initializes a new instance of the class. /// @@ -394,6 +396,8 @@ namespace IO.Swagger.Api { this.Configuration = new Configuration(new ApiClient(basePath)); + ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory; + // ensure API client has configuration ready if (Configuration.ApiClient.Configuration == null) { @@ -414,6 +418,8 @@ namespace IO.Swagger.Api else this.Configuration = configuration; + ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory; + // ensure API client has configuration ready if (Configuration.ApiClient.Configuration == null) { @@ -446,6 +452,22 @@ namespace IO.Swagger.Api /// An instance of the Configuration public Configuration Configuration {get; set;} + /// + /// Provides a factory method hook for the creation of exceptions. + /// + public IO.Swagger.Client.ExceptionFactory ExceptionFactory + { + get + { + if (_exceptionFactory != null && _exceptionFactory.GetInvocationList().Length > 1) + { + throw new InvalidOperationException("Multicast delegate for ExceptionFactory is unsupported."); + } + return _exceptionFactory; + } + set { _exceptionFactory = value; } + } + /// /// Gets the default header. /// @@ -533,10 +555,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling CreateUser: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling CreateUser: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("CreateUser", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -610,10 +633,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling CreateUser: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling CreateUser: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("CreateUser", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -686,10 +710,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling CreateUsersWithArrayInput: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling CreateUsersWithArrayInput: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("CreateUsersWithArrayInput", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -763,10 +788,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling CreateUsersWithArrayInput: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling CreateUsersWithArrayInput: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("CreateUsersWithArrayInput", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -839,10 +865,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling CreateUsersWithListInput: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling CreateUsersWithListInput: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("CreateUsersWithListInput", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -916,10 +943,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling CreateUsersWithListInput: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling CreateUsersWithListInput: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("CreateUsersWithListInput", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -985,10 +1013,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling DeleteUser: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling DeleteUser: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("DeleteUser", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -1055,10 +1084,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling DeleteUser: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling DeleteUser: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("DeleteUser", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -1125,10 +1155,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling GetUserByName: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling GetUserByName: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("GetUserByName", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), @@ -1196,10 +1227,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling GetUserByName: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling GetUserByName: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("GetUserByName", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), @@ -1272,10 +1304,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling LoginUser: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling LoginUser: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("LoginUser", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), @@ -1349,10 +1382,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling LoginUser: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling LoginUser: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("LoginUser", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), @@ -1412,10 +1446,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling LogoutUser: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling LogoutUser: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("LogoutUser", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -1476,10 +1511,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling LogoutUser: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling LogoutUser: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("LogoutUser", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -1558,10 +1594,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling UpdateUser: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling UpdateUser: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("UpdateUser", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, @@ -1641,10 +1678,11 @@ namespace IO.Swagger.Api int localVarStatusCode = (int) localVarResponse.StatusCode; - if (localVarStatusCode >= 400) - throw new ApiException (localVarStatusCode, "Error calling UpdateUser: " + localVarResponse.Content, localVarResponse.Content); - else if (localVarStatusCode == 0) - throw new ApiException (localVarStatusCode, "Error calling UpdateUser: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("UpdateUser", localVarResponse); + if (exception != null) throw exception; + } return new ApiResponse(localVarStatusCode, diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/ApiClient.cs b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/ApiClient.cs index 4331456ceaa..c5a2de83da1 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/ApiClient.cs +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/ApiClient.cs @@ -36,15 +36,28 @@ using RestSharp; namespace IO.Swagger.Client { /// - /// API client is mainly responible for making the HTTP call to the API backend. + /// API client is mainly responsible for making the HTTP call to the API backend. /// - public class ApiClient + public partial class ApiClient { private JsonSerializerSettings serializerSettings = new JsonSerializerSettings { ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor }; + /// + /// Allows for extending request processing for generated code. + /// + /// The RestSharp request object + partial void InterceptRequest(IRestRequest request); + + /// + /// Allows for extending response processing for generated code. + /// + /// The RestSharp request object + /// The RestSharp response object + partial void InterceptResponse(IRestRequest request, IRestResponse response); + /// /// Initializes a new instance of the class /// with default configuration and base path (http://petstore.swagger.io/v2). @@ -177,7 +190,10 @@ namespace IO.Swagger.Client // set user agent RestClient.UserAgent = Configuration.UserAgent; + InterceptRequest(request); var response = RestClient.Execute(request); + InterceptResponse(request, response); + return (Object) response; } /// @@ -202,7 +218,9 @@ namespace IO.Swagger.Client var request = PrepareRequest( path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, contentType); + InterceptRequest(request); var response = await RestClient.ExecuteTaskAsync(request); + InterceptResponse(request, response); return (Object)response; } diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/Configuration.cs b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/Configuration.cs index 451f6d61354..533b994dab2 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/Configuration.cs +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/Configuration.cs @@ -101,6 +101,17 @@ namespace IO.Swagger.Client /// Configuration. public static Configuration Default = new Configuration(); + /// + /// Default creation of exceptions for a given method name and response object + /// + public static readonly ExceptionFactory DefaultExceptionFactory = (methodName, response) => + { + int status = (int) response.StatusCode; + if (status >= 400) return new ApiException(status, String.Format("Error calling {0}: {1}", methodName, response.Content), response.Content); + if (status == 0) return new ApiException(status, String.Format("Error calling {0}: {1}", methodName, response.ErrorMessage), response.ErrorMessage); + return null; + }; + /// /// Gets or sets the HTTP timeout (milliseconds) of ApiClient. Default to 100000 milliseconds. /// diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/ExceptionFactory.cs b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/ExceptionFactory.cs new file mode 100644 index 00000000000..24e5fad478f --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/ExceptionFactory.cs @@ -0,0 +1,7 @@ +using System; +using RestSharp; + +namespace IO.Swagger.Client +{ + public delegate Exception ExceptionFactory(string methodName, IRestResponse response); +} diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/IApiAccessor.cs b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/IApiAccessor.cs index 1c91ef50003..65ff8bef73b 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/IApiAccessor.cs +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/IApiAccessor.cs @@ -45,5 +45,10 @@ namespace IO.Swagger.Client /// /// The base path String GetBasePath(); + + /// + /// Provides a factory method hook for the creation of exceptions. + /// + ExceptionFactory ExceptionFactory { get; set; } } } diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj index 20fdb3385e1..a484b5b5026 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj @@ -24,7 +24,7 @@ limitations under the License. Debug AnyCPU - {C81D6286-7BA5-4920-8591-F59169CCE4A4} + {EE727567-9CAF-4258-AA0E-FDF89487D7D6} Library Properties Swagger Library diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Model/FormatTest.cs b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Model/FormatTest.cs index eb1a6a8924b..5e50732ee0b 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Model/FormatTest.cs +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Model/FormatTest.cs @@ -60,7 +60,7 @@ namespace IO.Swagger.Model /// DateTime. /// Uuid. /// Password (required). - public FormatTest(int? Integer = null, int? Int32 = null, long? Int64 = null, double? Number = null, float? _Float = null, double? _Double = null, string _String = null, byte[] _Byte = null, byte[] Binary = null, DateTime? Date = null, DateTime? DateTime = null, Guid? Uuid = null, string Password = null) + public FormatTest(int? Integer = null, int? Int32 = null, long? Int64 = null, decimal? Number = null, float? _Float = null, double? _Double = null, string _String = null, byte[] _Byte = null, byte[] Binary = null, DateTime? Date = null, DateTime? DateTime = null, Guid? Uuid = null, string Password = null) { // to ensure "Number" is required (not null) if (Number == null) @@ -128,7 +128,7 @@ namespace IO.Swagger.Model /// Gets or Sets Number /// [DataMember(Name="number", EmitDefaultValue=false)] - public double? Number { get; set; } + public decimal? Number { get; set; } /// /// Gets or Sets _Float ///