diff --git a/modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache b/modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache index 87e572f9bd7..d7440b55b05 100644 --- a/modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache @@ -37,7 +37,6 @@ namespace {{packageName}}.Client internal class CustomJsonCodec : IRestSerializer, ISerializer, IDeserializer { private readonly IReadableConfiguration _configuration; - private static readonly string _contentType = "application/json"; private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings { // OpenAPI generated types generally hide default constructors. @@ -150,17 +149,13 @@ namespace {{packageName}}.Client public ISerializer Serializer => this; public IDeserializer Deserializer => this; - public string[] AcceptedContentTypes => RestSharp.Serializers.ContentType.JsonAccept; + public string[] AcceptedContentTypes => RestSharp.ContentType.JsonAccept; public SupportsContentType SupportsContentType => contentType => - contentType.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || - contentType.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); + contentType.Value.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || + contentType.Value.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); - public string ContentType - { - get { return _contentType; } - set { throw new InvalidOperationException("Not allowed to set content type."); } - } + public ContentType ContentType { get; set; } = RestSharp.ContentType.Json; public DataFormat DataFormat => DataFormat.Json; } @@ -434,7 +429,7 @@ namespace {{packageName}}.Client return transformed; } - private ApiResponse Exec(RestRequest req, RequestOptions options, IReadableConfiguration configuration) + private ApiResponse Exec(RestRequest request, RequestOptions options, IReadableConfiguration configuration) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -459,8 +454,8 @@ namespace {{packageName}}.Client RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); {{#hasOAuthMethods}} if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) && @@ -478,22 +473,21 @@ namespace {{packageName}}.Client } {{/hasOAuthMethods}} - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.RetryPolicy != null) { var policy = RetryConfiguration.RetryPolicy; - var policyResult = policy.ExecuteAndCapture(() => client.Execute(req)); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = policy.ExecuteAndCapture(() => client.Execute(request)); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = client.Execute(req); + response = client.Execute(request); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -521,7 +515,7 @@ namespace {{packageName}}.Client response.Data = (T)(object)response.Content; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) @@ -559,7 +553,7 @@ namespace {{packageName}}.Client } {{#supportsAsync}} - private async Task> ExecAsync(RestRequest req, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + private async Task> ExecAsync(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -572,8 +566,8 @@ namespace {{packageName}}.Client UseDefaultCredentials = configuration.UseDefaultCredentials }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); {{#hasOAuthMethods}} if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) && @@ -591,24 +585,23 @@ namespace {{packageName}}.Client } {{/hasOAuthMethods}} - InterceptRequest(req); + InterceptRequest(request); RestResponse response; {{#supportsRetry}} if (RetryConfiguration.AsyncRetryPolicy != null) { var policy = RetryConfiguration.AsyncRetryPolicy; - var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(req, ct), cancellationToken).ConfigureAwait(false); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { {{/supportsRetry}} - response = await client.ExecuteAsync(req, cancellationToken).ConfigureAwait(false); + response = await client.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); {{#supportsRetry}} } {{/supportsRetry}} @@ -627,7 +620,7 @@ namespace {{packageName}}.Client response.Data = (T)(object)response.RawBytes; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) diff --git a/modules/openapi-generator/src/main/resources/csharp/auth/OAuthAuthenticator.mustache b/modules/openapi-generator/src/main/resources/csharp/auth/OAuthAuthenticator.mustache index 1f811bf2412..dcf419c3d55 100644 --- a/modules/openapi-generator/src/main/resources/csharp/auth/OAuthAuthenticator.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/auth/OAuthAuthenticator.mustache @@ -73,8 +73,8 @@ namespace {{packageName}}.Client.Auth /// An authentication token. async Task GetToken() { - var client = new RestClient(_tokenUrl) - .UseSerializer(() => new CustomJsonCodec(_serializerSettings, _configuration)); + var client = new RestClient(_tokenUrl, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(_serializerSettings, _configuration))); var request = new RestRequest() .AddParameter("grant_type", _grantType) diff --git a/modules/openapi-generator/src/main/resources/csharp/netcore_project.mustache b/modules/openapi-generator/src/main/resources/csharp/netcore_project.mustache index e7bc3bf8f6e..f75341eaeb8 100644 --- a/modules/openapi-generator/src/main/resources/csharp/netcore_project.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/netcore_project.mustache @@ -32,7 +32,7 @@ {{/useGenericHost}} {{#useRestSharp}} - + {{/useRestSharp}} {{#useGenericHost}} diff --git a/modules/openapi-generator/src/main/resources/csharp/nuspec.mustache b/modules/openapi-generator/src/main/resources/csharp/nuspec.mustache index f86248be0e0..356b9079d07 100644 --- a/modules/openapi-generator/src/main/resources/csharp/nuspec.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/nuspec.mustache @@ -32,7 +32,7 @@ {{#useRestSharp}} - + {{/useRestSharp}} {{#useCompareNetObjects}} diff --git a/samples/client/echo_api/csharp-restsharp/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/echo_api/csharp-restsharp/src/Org.OpenAPITools/Client/ApiClient.cs index 0d3e29e4de7..00c3c48adbd 100644 --- a/samples/client/echo_api/csharp-restsharp/src/Org.OpenAPITools/Client/ApiClient.cs +++ b/samples/client/echo_api/csharp-restsharp/src/Org.OpenAPITools/Client/ApiClient.cs @@ -39,7 +39,6 @@ namespace Org.OpenAPITools.Client internal class CustomJsonCodec : IRestSerializer, ISerializer, IDeserializer { private readonly IReadableConfiguration _configuration; - private static readonly string _contentType = "application/json"; private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings { // OpenAPI generated types generally hide default constructors. @@ -152,17 +151,13 @@ namespace Org.OpenAPITools.Client public ISerializer Serializer => this; public IDeserializer Deserializer => this; - public string[] AcceptedContentTypes => RestSharp.Serializers.ContentType.JsonAccept; + public string[] AcceptedContentTypes => RestSharp.ContentType.JsonAccept; public SupportsContentType SupportsContentType => contentType => - contentType.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || - contentType.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); + contentType.Value.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || + contentType.Value.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); - public string ContentType - { - get { return _contentType; } - set { throw new InvalidOperationException("Not allowed to set content type."); } - } + public ContentType ContentType { get; set; } = RestSharp.ContentType.Json; public DataFormat DataFormat => DataFormat.Json; } @@ -435,7 +430,7 @@ namespace Org.OpenAPITools.Client return transformed; } - private ApiResponse Exec(RestRequest req, RequestOptions options, IReadableConfiguration configuration) + private ApiResponse Exec(RestRequest request, RequestOptions options, IReadableConfiguration configuration) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -460,25 +455,24 @@ namespace Org.OpenAPITools.Client RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.RetryPolicy != null) { var policy = RetryConfiguration.RetryPolicy; - var policyResult = policy.ExecuteAndCapture(() => client.Execute(req)); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = policy.ExecuteAndCapture(() => client.Execute(request)); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = client.Execute(req); + response = client.Execute(request); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -506,7 +500,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.Content; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) @@ -543,7 +537,7 @@ namespace Org.OpenAPITools.Client return result; } - private async Task> ExecAsync(RestRequest req, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + private async Task> ExecAsync(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -556,25 +550,24 @@ namespace Org.OpenAPITools.Client UseDefaultCredentials = configuration.UseDefaultCredentials }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.AsyncRetryPolicy != null) { var policy = RetryConfiguration.AsyncRetryPolicy; - var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(req, ct), cancellationToken).ConfigureAwait(false); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = await client.ExecuteAsync(req, cancellationToken).ConfigureAwait(false); + response = await client.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -591,7 +584,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.RawBytes; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) diff --git a/samples/client/echo_api/csharp-restsharp/src/Org.OpenAPITools/Org.OpenAPITools.csproj b/samples/client/echo_api/csharp-restsharp/src/Org.OpenAPITools/Org.OpenAPITools.csproj index 0be6c542d05..89948381e2e 100644 --- a/samples/client/echo_api/csharp-restsharp/src/Org.OpenAPITools/Org.OpenAPITools.csproj +++ b/samples/client/echo_api/csharp-restsharp/src/Org.OpenAPITools/Org.OpenAPITools.csproj @@ -23,7 +23,7 @@ - + diff --git a/samples/client/others/csharp-complex-files/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/others/csharp-complex-files/src/Org.OpenAPITools/Client/ApiClient.cs index 41fb8ad2630..fdf6596d44f 100644 --- a/samples/client/others/csharp-complex-files/src/Org.OpenAPITools/Client/ApiClient.cs +++ b/samples/client/others/csharp-complex-files/src/Org.OpenAPITools/Client/ApiClient.cs @@ -37,7 +37,6 @@ namespace Org.OpenAPITools.Client internal class CustomJsonCodec : IRestSerializer, ISerializer, IDeserializer { private readonly IReadableConfiguration _configuration; - private static readonly string _contentType = "application/json"; private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings { // OpenAPI generated types generally hide default constructors. @@ -150,17 +149,13 @@ namespace Org.OpenAPITools.Client public ISerializer Serializer => this; public IDeserializer Deserializer => this; - public string[] AcceptedContentTypes => RestSharp.Serializers.ContentType.JsonAccept; + public string[] AcceptedContentTypes => RestSharp.ContentType.JsonAccept; public SupportsContentType SupportsContentType => contentType => - contentType.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || - contentType.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); + contentType.Value.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || + contentType.Value.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); - public string ContentType - { - get { return _contentType; } - set { throw new InvalidOperationException("Not allowed to set content type."); } - } + public ContentType ContentType { get; set; } = RestSharp.ContentType.Json; public DataFormat DataFormat => DataFormat.Json; } @@ -433,7 +428,7 @@ namespace Org.OpenAPITools.Client return transformed; } - private ApiResponse Exec(RestRequest req, RequestOptions options, IReadableConfiguration configuration) + private ApiResponse Exec(RestRequest request, RequestOptions options, IReadableConfiguration configuration) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -458,25 +453,24 @@ namespace Org.OpenAPITools.Client RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.RetryPolicy != null) { var policy = RetryConfiguration.RetryPolicy; - var policyResult = policy.ExecuteAndCapture(() => client.Execute(req)); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = policy.ExecuteAndCapture(() => client.Execute(request)); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = client.Execute(req); + response = client.Execute(request); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -504,7 +498,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.Content; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) @@ -541,7 +535,7 @@ namespace Org.OpenAPITools.Client return result; } - private async Task> ExecAsync(RestRequest req, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + private async Task> ExecAsync(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -554,25 +548,24 @@ namespace Org.OpenAPITools.Client UseDefaultCredentials = configuration.UseDefaultCredentials }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.AsyncRetryPolicy != null) { var policy = RetryConfiguration.AsyncRetryPolicy; - var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(req, ct), cancellationToken).ConfigureAwait(false); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = await client.ExecuteAsync(req, cancellationToken).ConfigureAwait(false); + response = await client.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -589,7 +582,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.RawBytes; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) diff --git a/samples/client/others/csharp-complex-files/src/Org.OpenAPITools/Org.OpenAPITools.csproj b/samples/client/others/csharp-complex-files/src/Org.OpenAPITools/Org.OpenAPITools.csproj index 8d6a4b78ae0..c040fee7976 100644 --- a/samples/client/others/csharp-complex-files/src/Org.OpenAPITools/Org.OpenAPITools.csproj +++ b/samples/client/others/csharp-complex-files/src/Org.OpenAPITools/Org.OpenAPITools.csproj @@ -23,7 +23,7 @@ - + diff --git a/samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/ApiClient.cs index 93ace54a151..cd73ecced7c 100644 --- a/samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/ApiClient.cs +++ b/samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/ApiClient.cs @@ -38,7 +38,6 @@ namespace Org.OpenAPITools.Client internal class CustomJsonCodec : IRestSerializer, ISerializer, IDeserializer { private readonly IReadableConfiguration _configuration; - private static readonly string _contentType = "application/json"; private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings { // OpenAPI generated types generally hide default constructors. @@ -151,17 +150,13 @@ namespace Org.OpenAPITools.Client public ISerializer Serializer => this; public IDeserializer Deserializer => this; - public string[] AcceptedContentTypes => RestSharp.Serializers.ContentType.JsonAccept; + public string[] AcceptedContentTypes => RestSharp.ContentType.JsonAccept; public SupportsContentType SupportsContentType => contentType => - contentType.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || - contentType.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); + contentType.Value.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || + contentType.Value.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); - public string ContentType - { - get { return _contentType; } - set { throw new InvalidOperationException("Not allowed to set content type."); } - } + public ContentType ContentType { get; set; } = RestSharp.ContentType.Json; public DataFormat DataFormat => DataFormat.Json; } @@ -434,7 +429,7 @@ namespace Org.OpenAPITools.Client return transformed; } - private ApiResponse Exec(RestRequest req, RequestOptions options, IReadableConfiguration configuration) + private ApiResponse Exec(RestRequest request, RequestOptions options, IReadableConfiguration configuration) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -459,8 +454,8 @@ namespace Org.OpenAPITools.Client RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) && !string.IsNullOrEmpty(configuration.OAuthClientId) && @@ -476,22 +471,21 @@ namespace Org.OpenAPITools.Client configuration)); } - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.RetryPolicy != null) { var policy = RetryConfiguration.RetryPolicy; - var policyResult = policy.ExecuteAndCapture(() => client.Execute(req)); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = policy.ExecuteAndCapture(() => client.Execute(request)); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = client.Execute(req); + response = client.Execute(request); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -519,7 +513,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.Content; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) @@ -556,7 +550,7 @@ namespace Org.OpenAPITools.Client return result; } - private async Task> ExecAsync(RestRequest req, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + private async Task> ExecAsync(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -569,8 +563,8 @@ namespace Org.OpenAPITools.Client UseDefaultCredentials = configuration.UseDefaultCredentials }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) && !string.IsNullOrEmpty(configuration.OAuthClientId) && @@ -586,22 +580,21 @@ namespace Org.OpenAPITools.Client configuration)); } - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.AsyncRetryPolicy != null) { var policy = RetryConfiguration.AsyncRetryPolicy; - var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(req, ct), cancellationToken).ConfigureAwait(false); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = await client.ExecuteAsync(req, cancellationToken).ConfigureAwait(false); + response = await client.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -618,7 +611,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.RawBytes; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) diff --git a/samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs b/samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs index f64cfebe67d..d0e9c804f33 100644 --- a/samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs +++ b/samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs @@ -81,8 +81,8 @@ namespace Org.OpenAPITools.Client.Auth /// An authentication token. async Task GetToken() { - var client = new RestClient(_tokenUrl) - .UseSerializer(() => new CustomJsonCodec(_serializerSettings, _configuration)); + var client = new RestClient(_tokenUrl, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(_serializerSettings, _configuration))); var request = new RestRequest() .AddParameter("grant_type", _grantType) diff --git a/samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Org.OpenAPITools.csproj b/samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Org.OpenAPITools.csproj index 8d6a4b78ae0..c040fee7976 100644 --- a/samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Org.OpenAPITools.csproj +++ b/samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Org.OpenAPITools.csproj @@ -23,7 +23,7 @@ - + diff --git a/samples/client/petstore/csharp/OpenAPIClient-net47/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/petstore/csharp/OpenAPIClient-net47/src/Org.OpenAPITools/Client/ApiClient.cs index 0530baabc98..9e111a25f1c 100644 --- a/samples/client/petstore/csharp/OpenAPIClient-net47/src/Org.OpenAPITools/Client/ApiClient.cs +++ b/samples/client/petstore/csharp/OpenAPIClient-net47/src/Org.OpenAPITools/Client/ApiClient.cs @@ -39,7 +39,6 @@ namespace Org.OpenAPITools.Client internal class CustomJsonCodec : IRestSerializer, ISerializer, IDeserializer { private readonly IReadableConfiguration _configuration; - private static readonly string _contentType = "application/json"; private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings { // OpenAPI generated types generally hide default constructors. @@ -152,17 +151,13 @@ namespace Org.OpenAPITools.Client public ISerializer Serializer => this; public IDeserializer Deserializer => this; - public string[] AcceptedContentTypes => RestSharp.Serializers.ContentType.JsonAccept; + public string[] AcceptedContentTypes => RestSharp.ContentType.JsonAccept; public SupportsContentType SupportsContentType => contentType => - contentType.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || - contentType.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); + contentType.Value.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || + contentType.Value.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); - public string ContentType - { - get { return _contentType; } - set { throw new InvalidOperationException("Not allowed to set content type."); } - } + public ContentType ContentType { get; set; } = RestSharp.ContentType.Json; public DataFormat DataFormat => DataFormat.Json; } @@ -435,7 +430,7 @@ namespace Org.OpenAPITools.Client return transformed; } - private ApiResponse Exec(RestRequest req, RequestOptions options, IReadableConfiguration configuration) + private ApiResponse Exec(RestRequest request, RequestOptions options, IReadableConfiguration configuration) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -460,8 +455,8 @@ namespace Org.OpenAPITools.Client RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) && !string.IsNullOrEmpty(configuration.OAuthClientId) && @@ -477,22 +472,21 @@ namespace Org.OpenAPITools.Client configuration)); } - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.RetryPolicy != null) { var policy = RetryConfiguration.RetryPolicy; - var policyResult = policy.ExecuteAndCapture(() => client.Execute(req)); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = policy.ExecuteAndCapture(() => client.Execute(request)); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = client.Execute(req); + response = client.Execute(request); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -520,7 +514,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.Content; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) @@ -557,7 +551,7 @@ namespace Org.OpenAPITools.Client return result; } - private async Task> ExecAsync(RestRequest req, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + private async Task> ExecAsync(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -570,8 +564,8 @@ namespace Org.OpenAPITools.Client UseDefaultCredentials = configuration.UseDefaultCredentials }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) && !string.IsNullOrEmpty(configuration.OAuthClientId) && @@ -587,22 +581,21 @@ namespace Org.OpenAPITools.Client configuration)); } - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.AsyncRetryPolicy != null) { var policy = RetryConfiguration.AsyncRetryPolicy; - var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(req, ct), cancellationToken).ConfigureAwait(false); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = await client.ExecuteAsync(req, cancellationToken).ConfigureAwait(false); + response = await client.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -619,7 +612,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.RawBytes; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) diff --git a/samples/client/petstore/csharp/OpenAPIClient-net47/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs b/samples/client/petstore/csharp/OpenAPIClient-net47/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs index f64cfebe67d..d0e9c804f33 100644 --- a/samples/client/petstore/csharp/OpenAPIClient-net47/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs +++ b/samples/client/petstore/csharp/OpenAPIClient-net47/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs @@ -81,8 +81,8 @@ namespace Org.OpenAPITools.Client.Auth /// An authentication token. async Task GetToken() { - var client = new RestClient(_tokenUrl) - .UseSerializer(() => new CustomJsonCodec(_serializerSettings, _configuration)); + var client = new RestClient(_tokenUrl, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(_serializerSettings, _configuration))); var request = new RestRequest() .AddParameter("grant_type", _grantType) diff --git a/samples/client/petstore/csharp/OpenAPIClient-net47/src/Org.OpenAPITools/Org.OpenAPITools.csproj b/samples/client/petstore/csharp/OpenAPIClient-net47/src/Org.OpenAPITools/Org.OpenAPITools.csproj index 85b203f7dcb..b6795e5e0dd 100644 --- a/samples/client/petstore/csharp/OpenAPIClient-net47/src/Org.OpenAPITools/Org.OpenAPITools.csproj +++ b/samples/client/petstore/csharp/OpenAPIClient-net47/src/Org.OpenAPITools/Org.OpenAPITools.csproj @@ -23,7 +23,7 @@ - + diff --git a/samples/client/petstore/csharp/OpenAPIClient-net48/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/petstore/csharp/OpenAPIClient-net48/src/Org.OpenAPITools/Client/ApiClient.cs index 0530baabc98..9e111a25f1c 100644 --- a/samples/client/petstore/csharp/OpenAPIClient-net48/src/Org.OpenAPITools/Client/ApiClient.cs +++ b/samples/client/petstore/csharp/OpenAPIClient-net48/src/Org.OpenAPITools/Client/ApiClient.cs @@ -39,7 +39,6 @@ namespace Org.OpenAPITools.Client internal class CustomJsonCodec : IRestSerializer, ISerializer, IDeserializer { private readonly IReadableConfiguration _configuration; - private static readonly string _contentType = "application/json"; private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings { // OpenAPI generated types generally hide default constructors. @@ -152,17 +151,13 @@ namespace Org.OpenAPITools.Client public ISerializer Serializer => this; public IDeserializer Deserializer => this; - public string[] AcceptedContentTypes => RestSharp.Serializers.ContentType.JsonAccept; + public string[] AcceptedContentTypes => RestSharp.ContentType.JsonAccept; public SupportsContentType SupportsContentType => contentType => - contentType.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || - contentType.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); + contentType.Value.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || + contentType.Value.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); - public string ContentType - { - get { return _contentType; } - set { throw new InvalidOperationException("Not allowed to set content type."); } - } + public ContentType ContentType { get; set; } = RestSharp.ContentType.Json; public DataFormat DataFormat => DataFormat.Json; } @@ -435,7 +430,7 @@ namespace Org.OpenAPITools.Client return transformed; } - private ApiResponse Exec(RestRequest req, RequestOptions options, IReadableConfiguration configuration) + private ApiResponse Exec(RestRequest request, RequestOptions options, IReadableConfiguration configuration) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -460,8 +455,8 @@ namespace Org.OpenAPITools.Client RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) && !string.IsNullOrEmpty(configuration.OAuthClientId) && @@ -477,22 +472,21 @@ namespace Org.OpenAPITools.Client configuration)); } - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.RetryPolicy != null) { var policy = RetryConfiguration.RetryPolicy; - var policyResult = policy.ExecuteAndCapture(() => client.Execute(req)); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = policy.ExecuteAndCapture(() => client.Execute(request)); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = client.Execute(req); + response = client.Execute(request); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -520,7 +514,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.Content; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) @@ -557,7 +551,7 @@ namespace Org.OpenAPITools.Client return result; } - private async Task> ExecAsync(RestRequest req, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + private async Task> ExecAsync(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -570,8 +564,8 @@ namespace Org.OpenAPITools.Client UseDefaultCredentials = configuration.UseDefaultCredentials }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) && !string.IsNullOrEmpty(configuration.OAuthClientId) && @@ -587,22 +581,21 @@ namespace Org.OpenAPITools.Client configuration)); } - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.AsyncRetryPolicy != null) { var policy = RetryConfiguration.AsyncRetryPolicy; - var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(req, ct), cancellationToken).ConfigureAwait(false); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = await client.ExecuteAsync(req, cancellationToken).ConfigureAwait(false); + response = await client.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -619,7 +612,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.RawBytes; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) diff --git a/samples/client/petstore/csharp/OpenAPIClient-net48/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs b/samples/client/petstore/csharp/OpenAPIClient-net48/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs index f64cfebe67d..d0e9c804f33 100644 --- a/samples/client/petstore/csharp/OpenAPIClient-net48/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs +++ b/samples/client/petstore/csharp/OpenAPIClient-net48/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs @@ -81,8 +81,8 @@ namespace Org.OpenAPITools.Client.Auth /// An authentication token. async Task GetToken() { - var client = new RestClient(_tokenUrl) - .UseSerializer(() => new CustomJsonCodec(_serializerSettings, _configuration)); + var client = new RestClient(_tokenUrl, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(_serializerSettings, _configuration))); var request = new RestRequest() .AddParameter("grant_type", _grantType) diff --git a/samples/client/petstore/csharp/OpenAPIClient-net48/src/Org.OpenAPITools/Org.OpenAPITools.csproj b/samples/client/petstore/csharp/OpenAPIClient-net48/src/Org.OpenAPITools/Org.OpenAPITools.csproj index ea1b60243d8..6b3163ef9ad 100644 --- a/samples/client/petstore/csharp/OpenAPIClient-net48/src/Org.OpenAPITools/Org.OpenAPITools.csproj +++ b/samples/client/petstore/csharp/OpenAPIClient-net48/src/Org.OpenAPITools/Org.OpenAPITools.csproj @@ -23,7 +23,7 @@ - + diff --git a/samples/client/petstore/csharp/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/petstore/csharp/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/ApiClient.cs index 0530baabc98..9e111a25f1c 100644 --- a/samples/client/petstore/csharp/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/ApiClient.cs +++ b/samples/client/petstore/csharp/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/ApiClient.cs @@ -39,7 +39,6 @@ namespace Org.OpenAPITools.Client internal class CustomJsonCodec : IRestSerializer, ISerializer, IDeserializer { private readonly IReadableConfiguration _configuration; - private static readonly string _contentType = "application/json"; private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings { // OpenAPI generated types generally hide default constructors. @@ -152,17 +151,13 @@ namespace Org.OpenAPITools.Client public ISerializer Serializer => this; public IDeserializer Deserializer => this; - public string[] AcceptedContentTypes => RestSharp.Serializers.ContentType.JsonAccept; + public string[] AcceptedContentTypes => RestSharp.ContentType.JsonAccept; public SupportsContentType SupportsContentType => contentType => - contentType.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || - contentType.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); + contentType.Value.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || + contentType.Value.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); - public string ContentType - { - get { return _contentType; } - set { throw new InvalidOperationException("Not allowed to set content type."); } - } + public ContentType ContentType { get; set; } = RestSharp.ContentType.Json; public DataFormat DataFormat => DataFormat.Json; } @@ -435,7 +430,7 @@ namespace Org.OpenAPITools.Client return transformed; } - private ApiResponse Exec(RestRequest req, RequestOptions options, IReadableConfiguration configuration) + private ApiResponse Exec(RestRequest request, RequestOptions options, IReadableConfiguration configuration) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -460,8 +455,8 @@ namespace Org.OpenAPITools.Client RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) && !string.IsNullOrEmpty(configuration.OAuthClientId) && @@ -477,22 +472,21 @@ namespace Org.OpenAPITools.Client configuration)); } - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.RetryPolicy != null) { var policy = RetryConfiguration.RetryPolicy; - var policyResult = policy.ExecuteAndCapture(() => client.Execute(req)); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = policy.ExecuteAndCapture(() => client.Execute(request)); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = client.Execute(req); + response = client.Execute(request); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -520,7 +514,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.Content; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) @@ -557,7 +551,7 @@ namespace Org.OpenAPITools.Client return result; } - private async Task> ExecAsync(RestRequest req, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + private async Task> ExecAsync(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -570,8 +564,8 @@ namespace Org.OpenAPITools.Client UseDefaultCredentials = configuration.UseDefaultCredentials }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) && !string.IsNullOrEmpty(configuration.OAuthClientId) && @@ -587,22 +581,21 @@ namespace Org.OpenAPITools.Client configuration)); } - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.AsyncRetryPolicy != null) { var policy = RetryConfiguration.AsyncRetryPolicy; - var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(req, ct), cancellationToken).ConfigureAwait(false); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = await client.ExecuteAsync(req, cancellationToken).ConfigureAwait(false); + response = await client.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -619,7 +612,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.RawBytes; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) diff --git a/samples/client/petstore/csharp/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs b/samples/client/petstore/csharp/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs index f64cfebe67d..d0e9c804f33 100644 --- a/samples/client/petstore/csharp/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs +++ b/samples/client/petstore/csharp/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs @@ -81,8 +81,8 @@ namespace Org.OpenAPITools.Client.Auth /// An authentication token. async Task GetToken() { - var client = new RestClient(_tokenUrl) - .UseSerializer(() => new CustomJsonCodec(_serializerSettings, _configuration)); + var client = new RestClient(_tokenUrl, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(_serializerSettings, _configuration))); var request = new RestRequest() .AddParameter("grant_type", _grantType) diff --git a/samples/client/petstore/csharp/OpenAPIClient-net5.0/src/Org.OpenAPITools/Org.OpenAPITools.csproj b/samples/client/petstore/csharp/OpenAPIClient-net5.0/src/Org.OpenAPITools/Org.OpenAPITools.csproj index d3f3b489b0f..8c0a21ddae8 100644 --- a/samples/client/petstore/csharp/OpenAPIClient-net5.0/src/Org.OpenAPITools/Org.OpenAPITools.csproj +++ b/samples/client/petstore/csharp/OpenAPIClient-net5.0/src/Org.OpenAPITools/Org.OpenAPITools.csproj @@ -24,7 +24,7 @@ - + diff --git a/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Client/ApiClient.cs index 93ace54a151..cd73ecced7c 100644 --- a/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Client/ApiClient.cs +++ b/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Client/ApiClient.cs @@ -38,7 +38,6 @@ namespace Org.OpenAPITools.Client internal class CustomJsonCodec : IRestSerializer, ISerializer, IDeserializer { private readonly IReadableConfiguration _configuration; - private static readonly string _contentType = "application/json"; private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings { // OpenAPI generated types generally hide default constructors. @@ -151,17 +150,13 @@ namespace Org.OpenAPITools.Client public ISerializer Serializer => this; public IDeserializer Deserializer => this; - public string[] AcceptedContentTypes => RestSharp.Serializers.ContentType.JsonAccept; + public string[] AcceptedContentTypes => RestSharp.ContentType.JsonAccept; public SupportsContentType SupportsContentType => contentType => - contentType.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || - contentType.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); + contentType.Value.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || + contentType.Value.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); - public string ContentType - { - get { return _contentType; } - set { throw new InvalidOperationException("Not allowed to set content type."); } - } + public ContentType ContentType { get; set; } = RestSharp.ContentType.Json; public DataFormat DataFormat => DataFormat.Json; } @@ -434,7 +429,7 @@ namespace Org.OpenAPITools.Client return transformed; } - private ApiResponse Exec(RestRequest req, RequestOptions options, IReadableConfiguration configuration) + private ApiResponse Exec(RestRequest request, RequestOptions options, IReadableConfiguration configuration) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -459,8 +454,8 @@ namespace Org.OpenAPITools.Client RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) && !string.IsNullOrEmpty(configuration.OAuthClientId) && @@ -476,22 +471,21 @@ namespace Org.OpenAPITools.Client configuration)); } - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.RetryPolicy != null) { var policy = RetryConfiguration.RetryPolicy; - var policyResult = policy.ExecuteAndCapture(() => client.Execute(req)); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = policy.ExecuteAndCapture(() => client.Execute(request)); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = client.Execute(req); + response = client.Execute(request); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -519,7 +513,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.Content; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) @@ -556,7 +550,7 @@ namespace Org.OpenAPITools.Client return result; } - private async Task> ExecAsync(RestRequest req, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + private async Task> ExecAsync(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -569,8 +563,8 @@ namespace Org.OpenAPITools.Client UseDefaultCredentials = configuration.UseDefaultCredentials }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) && !string.IsNullOrEmpty(configuration.OAuthClientId) && @@ -586,22 +580,21 @@ namespace Org.OpenAPITools.Client configuration)); } - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.AsyncRetryPolicy != null) { var policy = RetryConfiguration.AsyncRetryPolicy; - var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(req, ct), cancellationToken).ConfigureAwait(false); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = await client.ExecuteAsync(req, cancellationToken).ConfigureAwait(false); + response = await client.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -618,7 +611,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.RawBytes; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) diff --git a/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs b/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs index f64cfebe67d..d0e9c804f33 100644 --- a/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs +++ b/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs @@ -81,8 +81,8 @@ namespace Org.OpenAPITools.Client.Auth /// An authentication token. async Task GetToken() { - var client = new RestClient(_tokenUrl) - .UseSerializer(() => new CustomJsonCodec(_serializerSettings, _configuration)); + var client = new RestClient(_tokenUrl, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(_serializerSettings, _configuration))); var request = new RestRequest() .AddParameter("grant_type", _grantType) diff --git a/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Org.OpenAPITools.csproj b/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Org.OpenAPITools.csproj index 8d6a4b78ae0..c040fee7976 100644 --- a/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Org.OpenAPITools.csproj +++ b/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Org.OpenAPITools.csproj @@ -23,7 +23,7 @@ - + diff --git a/samples/client/petstore/csharp/OpenAPIClientCore/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/petstore/csharp/OpenAPIClientCore/src/Org.OpenAPITools/Client/ApiClient.cs index 0530baabc98..9e111a25f1c 100644 --- a/samples/client/petstore/csharp/OpenAPIClientCore/src/Org.OpenAPITools/Client/ApiClient.cs +++ b/samples/client/petstore/csharp/OpenAPIClientCore/src/Org.OpenAPITools/Client/ApiClient.cs @@ -39,7 +39,6 @@ namespace Org.OpenAPITools.Client internal class CustomJsonCodec : IRestSerializer, ISerializer, IDeserializer { private readonly IReadableConfiguration _configuration; - private static readonly string _contentType = "application/json"; private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings { // OpenAPI generated types generally hide default constructors. @@ -152,17 +151,13 @@ namespace Org.OpenAPITools.Client public ISerializer Serializer => this; public IDeserializer Deserializer => this; - public string[] AcceptedContentTypes => RestSharp.Serializers.ContentType.JsonAccept; + public string[] AcceptedContentTypes => RestSharp.ContentType.JsonAccept; public SupportsContentType SupportsContentType => contentType => - contentType.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || - contentType.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); + contentType.Value.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || + contentType.Value.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); - public string ContentType - { - get { return _contentType; } - set { throw new InvalidOperationException("Not allowed to set content type."); } - } + public ContentType ContentType { get; set; } = RestSharp.ContentType.Json; public DataFormat DataFormat => DataFormat.Json; } @@ -435,7 +430,7 @@ namespace Org.OpenAPITools.Client return transformed; } - private ApiResponse Exec(RestRequest req, RequestOptions options, IReadableConfiguration configuration) + private ApiResponse Exec(RestRequest request, RequestOptions options, IReadableConfiguration configuration) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -460,8 +455,8 @@ namespace Org.OpenAPITools.Client RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) && !string.IsNullOrEmpty(configuration.OAuthClientId) && @@ -477,22 +472,21 @@ namespace Org.OpenAPITools.Client configuration)); } - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.RetryPolicy != null) { var policy = RetryConfiguration.RetryPolicy; - var policyResult = policy.ExecuteAndCapture(() => client.Execute(req)); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = policy.ExecuteAndCapture(() => client.Execute(request)); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = client.Execute(req); + response = client.Execute(request); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -520,7 +514,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.Content; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) @@ -557,7 +551,7 @@ namespace Org.OpenAPITools.Client return result; } - private async Task> ExecAsync(RestRequest req, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + private async Task> ExecAsync(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -570,8 +564,8 @@ namespace Org.OpenAPITools.Client UseDefaultCredentials = configuration.UseDefaultCredentials }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) && !string.IsNullOrEmpty(configuration.OAuthClientId) && @@ -587,22 +581,21 @@ namespace Org.OpenAPITools.Client configuration)); } - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.AsyncRetryPolicy != null) { var policy = RetryConfiguration.AsyncRetryPolicy; - var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(req, ct), cancellationToken).ConfigureAwait(false); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = await client.ExecuteAsync(req, cancellationToken).ConfigureAwait(false); + response = await client.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -619,7 +612,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.RawBytes; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) diff --git a/samples/client/petstore/csharp/OpenAPIClientCore/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs b/samples/client/petstore/csharp/OpenAPIClientCore/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs index f64cfebe67d..d0e9c804f33 100644 --- a/samples/client/petstore/csharp/OpenAPIClientCore/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs +++ b/samples/client/petstore/csharp/OpenAPIClientCore/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs @@ -81,8 +81,8 @@ namespace Org.OpenAPITools.Client.Auth /// An authentication token. async Task GetToken() { - var client = new RestClient(_tokenUrl) - .UseSerializer(() => new CustomJsonCodec(_serializerSettings, _configuration)); + var client = new RestClient(_tokenUrl, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(_serializerSettings, _configuration))); var request = new RestRequest() .AddParameter("grant_type", _grantType) diff --git a/samples/client/petstore/csharp/OpenAPIClientCore/src/Org.OpenAPITools/Org.OpenAPITools.csproj b/samples/client/petstore/csharp/OpenAPIClientCore/src/Org.OpenAPITools/Org.OpenAPITools.csproj index d3f3b489b0f..8c0a21ddae8 100644 --- a/samples/client/petstore/csharp/OpenAPIClientCore/src/Org.OpenAPITools/Org.OpenAPITools.csproj +++ b/samples/client/petstore/csharp/OpenAPIClientCore/src/Org.OpenAPITools/Org.OpenAPITools.csproj @@ -24,7 +24,7 @@ - + diff --git a/samples/client/petstore/csharp/OpenAPIClientCoreAndNet47/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/petstore/csharp/OpenAPIClientCoreAndNet47/src/Org.OpenAPITools/Client/ApiClient.cs index 9632c42a5d7..8c2eda3d66e 100644 --- a/samples/client/petstore/csharp/OpenAPIClientCoreAndNet47/src/Org.OpenAPITools/Client/ApiClient.cs +++ b/samples/client/petstore/csharp/OpenAPIClientCoreAndNet47/src/Org.OpenAPITools/Client/ApiClient.cs @@ -38,7 +38,6 @@ namespace Org.OpenAPITools.Client internal class CustomJsonCodec : IRestSerializer, ISerializer, IDeserializer { private readonly IReadableConfiguration _configuration; - private static readonly string _contentType = "application/json"; private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings { // OpenAPI generated types generally hide default constructors. @@ -151,17 +150,13 @@ namespace Org.OpenAPITools.Client public ISerializer Serializer => this; public IDeserializer Deserializer => this; - public string[] AcceptedContentTypes => RestSharp.Serializers.ContentType.JsonAccept; + public string[] AcceptedContentTypes => RestSharp.ContentType.JsonAccept; public SupportsContentType SupportsContentType => contentType => - contentType.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || - contentType.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); + contentType.Value.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || + contentType.Value.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); - public string ContentType - { - get { return _contentType; } - set { throw new InvalidOperationException("Not allowed to set content type."); } - } + public ContentType ContentType { get; set; } = RestSharp.ContentType.Json; public DataFormat DataFormat => DataFormat.Json; } @@ -434,7 +429,7 @@ namespace Org.OpenAPITools.Client return transformed; } - private ApiResponse Exec(RestRequest req, RequestOptions options, IReadableConfiguration configuration) + private ApiResponse Exec(RestRequest request, RequestOptions options, IReadableConfiguration configuration) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -459,8 +454,8 @@ namespace Org.OpenAPITools.Client RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) && !string.IsNullOrEmpty(configuration.OAuthClientId) && @@ -476,22 +471,21 @@ namespace Org.OpenAPITools.Client configuration)); } - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.RetryPolicy != null) { var policy = RetryConfiguration.RetryPolicy; - var policyResult = policy.ExecuteAndCapture(() => client.Execute(req)); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = policy.ExecuteAndCapture(() => client.Execute(request)); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = client.Execute(req); + response = client.Execute(request); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -519,7 +513,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.Content; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) @@ -556,7 +550,7 @@ namespace Org.OpenAPITools.Client return result; } - private async Task> ExecAsync(RestRequest req, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + private async Task> ExecAsync(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; @@ -569,8 +563,8 @@ namespace Org.OpenAPITools.Client UseDefaultCredentials = configuration.UseDefaultCredentials }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); + RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))); if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) && !string.IsNullOrEmpty(configuration.OAuthClientId) && @@ -586,22 +580,21 @@ namespace Org.OpenAPITools.Client configuration)); } - InterceptRequest(req); + InterceptRequest(request); RestResponse response; if (RetryConfiguration.AsyncRetryPolicy != null) { var policy = RetryConfiguration.AsyncRetryPolicy; - var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(req, ct), cancellationToken).ConfigureAwait(false); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Request = req, ErrorException = policyResult.FinalException }; } else { - response = await client.ExecuteAsync(req, cancellationToken).ConfigureAwait(false); + response = await client.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); } // if the response type is oneOf/anyOf, call FromJSON to deserialize the data @@ -618,7 +611,7 @@ namespace Org.OpenAPITools.Client response.Data = (T)(object)response.RawBytes; } - InterceptResponse(req, response); + InterceptResponse(request, response); var result = ToApiResponse(response); if (response.ErrorMessage != null) diff --git a/samples/client/petstore/csharp/OpenAPIClientCoreAndNet47/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs b/samples/client/petstore/csharp/OpenAPIClientCoreAndNet47/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs index 893e777536b..3239c4b63f4 100644 --- a/samples/client/petstore/csharp/OpenAPIClientCoreAndNet47/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs +++ b/samples/client/petstore/csharp/OpenAPIClientCoreAndNet47/src/Org.OpenAPITools/Client/Auth/OAuthAuthenticator.cs @@ -81,8 +81,8 @@ namespace Org.OpenAPITools.Client.Auth /// An authentication token. async Task GetToken() { - var client = new RestClient(_tokenUrl) - .UseSerializer(() => new CustomJsonCodec(_serializerSettings, _configuration)); + var client = new RestClient(_tokenUrl, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(_serializerSettings, _configuration))); var request = new RestRequest() .AddParameter("grant_type", _grantType) diff --git a/samples/client/petstore/csharp/OpenAPIClientCoreAndNet47/src/Org.OpenAPITools/Org.OpenAPITools.csproj b/samples/client/petstore/csharp/OpenAPIClientCoreAndNet47/src/Org.OpenAPITools/Org.OpenAPITools.csproj index a6f431cde58..50870849743 100644 --- a/samples/client/petstore/csharp/OpenAPIClientCoreAndNet47/src/Org.OpenAPITools/Org.OpenAPITools.csproj +++ b/samples/client/petstore/csharp/OpenAPIClientCoreAndNet47/src/Org.OpenAPITools/Org.OpenAPITools.csproj @@ -23,7 +23,7 @@ - +