forked from loafle/openapi-generator-original
parent
656d2c2263
commit
1a458d3e0b
@ -454,102 +454,103 @@ namespace {{packageName}}.Client
|
||||
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
{{#hasOAuthMethods}}
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
client = client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
{{/hasOAuthMethods}}
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{{#hasOAuthMethods}}
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof({{{packageName}}}.{{modelPackage}}.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
{{/hasOAuthMethods}}
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof({{{packageName}}}.{{modelPackage}}.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
{{#supportsAsync}}
|
||||
@ -566,95 +567,96 @@ namespace {{packageName}}.Client
|
||||
UseDefaultCredentials = configuration.UseDefaultCredentials
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
{{#hasOAuthMethods}}
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
client = client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
{{/hasOAuthMethods}}
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
{{#supportsRetry}}
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{{#hasOAuthMethods}}
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
{{/supportsRetry}}
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
{{#supportsRetry}}
|
||||
}
|
||||
{{/supportsRetry}}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof({{{packageName}}}.{{modelPackage}}.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
{{/hasOAuthMethods}}
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
{{#supportsRetry}}
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
{{/supportsRetry}}
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
{{#supportsRetry}}
|
||||
}
|
||||
{{/supportsRetry}}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof({{{packageName}}}.{{modelPackage}}.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#region IAsynchronousClient
|
||||
|
@ -455,86 +455,87 @@ namespace Org.OpenAPITools.Client
|
||||
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<ApiResponse<T>> ExecAsync<T>(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
@ -550,75 +551,76 @@ namespace Org.OpenAPITools.Client
|
||||
UseDefaultCredentials = configuration.UseDefaultCredentials
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#region IAsynchronousClient
|
||||
|
@ -453,86 +453,87 @@ namespace Org.OpenAPITools.Client
|
||||
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<ApiResponse<T>> ExecAsync<T>(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
@ -548,75 +549,76 @@ namespace Org.OpenAPITools.Client
|
||||
UseDefaultCredentials = configuration.UseDefaultCredentials
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#region IAsynchronousClient
|
||||
|
@ -454,86 +454,87 @@ namespace Org.OpenAPITools.Client
|
||||
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<ApiResponse<T>> ExecAsync<T>(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
@ -549,75 +550,76 @@ namespace Org.OpenAPITools.Client
|
||||
UseDefaultCredentials = configuration.UseDefaultCredentials
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#region IAsynchronousClient
|
||||
|
@ -454,100 +454,101 @@ namespace Org.OpenAPITools.Client
|
||||
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
client = client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<ApiResponse<T>> ExecAsync<T>(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
@ -563,89 +564,90 @@ namespace Org.OpenAPITools.Client
|
||||
UseDefaultCredentials = configuration.UseDefaultCredentials
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
client = client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#region IAsynchronousClient
|
||||
|
@ -455,100 +455,101 @@ namespace Org.OpenAPITools.Client
|
||||
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
client = client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<ApiResponse<T>> ExecAsync<T>(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
@ -564,89 +565,90 @@ namespace Org.OpenAPITools.Client
|
||||
UseDefaultCredentials = configuration.UseDefaultCredentials
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
client = client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#region IAsynchronousClient
|
||||
|
@ -455,100 +455,101 @@ namespace Org.OpenAPITools.Client
|
||||
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
client = client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<ApiResponse<T>> ExecAsync<T>(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
@ -564,89 +565,90 @@ namespace Org.OpenAPITools.Client
|
||||
UseDefaultCredentials = configuration.UseDefaultCredentials
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
client = client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#region IAsynchronousClient
|
||||
|
@ -455,100 +455,101 @@ namespace Org.OpenAPITools.Client
|
||||
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
client = client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<ApiResponse<T>> ExecAsync<T>(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
@ -564,89 +565,90 @@ namespace Org.OpenAPITools.Client
|
||||
UseDefaultCredentials = configuration.UseDefaultCredentials
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
client = client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#region IAsynchronousClient
|
||||
|
@ -454,100 +454,101 @@ namespace Org.OpenAPITools.Client
|
||||
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
client = client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<ApiResponse<T>> ExecAsync<T>(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
@ -563,89 +564,90 @@ namespace Org.OpenAPITools.Client
|
||||
UseDefaultCredentials = configuration.UseDefaultCredentials
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
client = client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#region IAsynchronousClient
|
||||
|
@ -455,100 +455,101 @@ namespace Org.OpenAPITools.Client
|
||||
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
client = client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<ApiResponse<T>> ExecAsync<T>(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
@ -564,89 +565,90 @@ namespace Org.OpenAPITools.Client
|
||||
UseDefaultCredentials = configuration.UseDefaultCredentials
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
client = client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#region IAsynchronousClient
|
||||
|
@ -454,100 +454,101 @@ namespace Org.OpenAPITools.Client
|
||||
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
client = client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(request);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
try
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||
}
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
else if (typeof(T).Name == "String") // for string response
|
||||
{
|
||||
response.Data = (T)(object)response.Content;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<ApiResponse<T>> ExecAsync<T>(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
@ -563,89 +564,90 @@ namespace Org.OpenAPITools.Client
|
||||
UseDefaultCredentials = configuration.UseDefaultCredentials
|
||||
};
|
||||
|
||||
RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)));
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
using (RestClient client = new RestClient(clientOptions,
|
||||
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||
{
|
||||
client = client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
|
||||
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
|
||||
configuration.OAuthFlow != null)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
client.UseAuthenticator(new OAuthAuthenticator(
|
||||
configuration.OAuthTokenUrl,
|
||||
configuration.OAuthClientId,
|
||||
configuration.OAuthClientSecret,
|
||||
configuration.OAuthFlow,
|
||||
SerializerSettings,
|
||||
configuration));
|
||||
}
|
||||
|
||||
InterceptRequest(request);
|
||||
|
||||
RestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||
{
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||
{
|
||||
response.Data = (T)(object)response.RawBytes;
|
||||
}
|
||||
|
||||
InterceptResponse(request, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#region IAsynchronousClient
|
||||
|
Loading…
x
Reference in New Issue
Block a user