From 64b981a69d59606aa9d631644bcf269f6e86d266 Mon Sep 17 00:00:00 2001 From: maksimlysenko Date: Thu, 5 Jul 2018 06:14:15 +0000 Subject: [PATCH] 9.0.000.00.1162 --- .../Api/AuthenticationApi.cs | 82 ++-- .../Client/ApiClient.cs | 126 ++--- .../Client/Configuration.cs | 437 +++++++----------- .../Client/GlobalConfiguration.cs | 34 -- .../Client/IReadableConfiguration.cs | 94 ---- .../Genesys.Internal.Authentication.csproj | 8 +- .../Genesys.Internal.Authentication.nuspec | 1 - .../Model/ApiResponse.cs | 52 ++- .../Model/AuthSchemeLookupData.cs | 36 +- .../Model/ChangePasswordOperation.cs | 44 +- .../Model/CloudUserDetails.cs | 76 +-- .../Model/DefaultOAuth2AccessToken.cs | 60 +-- .../Model/ErrorResponse.cs | 36 +- .../Model/JwtConvertResult.cs | 28 +- .../Model/ResponseStatus.cs | 44 +- .../Model/UserRole.cs | 28 +- .../packages.config | 1 - 17 files changed, 466 insertions(+), 721 deletions(-) delete mode 100644 src/Genesys.Internal.Authentication/Client/GlobalConfiguration.cs delete mode 100644 src/Genesys.Internal.Authentication/Client/IReadableConfiguration.cs diff --git a/src/Genesys.Internal.Authentication/Api/AuthenticationApi.cs b/src/Genesys.Internal.Authentication/Api/AuthenticationApi.cs index 489f5c1..c706cba 100644 --- a/src/Genesys.Internal.Authentication/Api/AuthenticationApi.cs +++ b/src/Genesys.Internal.Authentication/Api/AuthenticationApi.cs @@ -488,9 +488,15 @@ public partial class AuthenticationApi : IAuthenticationApi /// public AuthenticationApi(String basePath) { - this.Configuration = new Configuration { BasePath = basePath }; + this.Configuration = new Configuration(new ApiClient(basePath)); ExceptionFactory = Genesys.Internal.Authentication.Client.Configuration.DefaultExceptionFactory; + + // ensure API client has configuration ready + if (Configuration.ApiClient.Configuration == null) + { + this.Configuration.ApiClient.Configuration = this.Configuration; + } } /// @@ -507,6 +513,12 @@ public AuthenticationApi(Configuration configuration = null) this.Configuration = configuration; ExceptionFactory = Genesys.Internal.Authentication.Client.Configuration.DefaultExceptionFactory; + + // ensure API client has configuration ready + if (Configuration.ApiClient.Configuration == null) + { + this.Configuration.ApiClient.Configuration = this.Configuration; + } } /// @@ -555,9 +567,9 @@ public Genesys.Internal.Authentication.Client.ExceptionFactory ExceptionFactory /// /// Dictionary of HTTP header [Obsolete("DefaultHeader is deprecated, please use Configuration.DefaultHeader instead.")] - public IDictionary DefaultHeader() + public Dictionary DefaultHeader() { - return new ReadOnlyDictionary(this.Configuration.DefaultHeader); + return this.Configuration.DefaultHeader; } /// @@ -611,7 +623,7 @@ public ApiResponse AuthorizeWithHttpInfo (string responseType, string re var localVarPath = "/oauth/authorize"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -631,10 +643,10 @@ public ApiResponse AuthorizeWithHttpInfo (string responseType, string re if (localVarHttpHeaderAccept != null) localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); - if (responseType != null) localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "response_type", responseType)); // query parameter - if (scope != null) localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "scope", scope)); // query parameter - if (redirectUri != null) localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "redirect_uri", redirectUri)); // query parameter - if (clientId != null) localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "client_id", clientId)); // query parameter + if (responseType != null) localVarQueryParams.Add("response_type", Configuration.ApiClient.ParameterToString(responseType)); // query parameter + if (scope != null) localVarQueryParams.Add("scope", Configuration.ApiClient.ParameterToString(scope)); // query parameter + if (redirectUri != null) localVarQueryParams.Add("redirect_uri", Configuration.ApiClient.ParameterToString(redirectUri)); // query parameter + if (clientId != null) localVarQueryParams.Add("client_id", Configuration.ApiClient.ParameterToString(clientId)); // query parameter if (authorization != null) localVarHeaderParams.Add("Authorization", Configuration.ApiClient.ParameterToString(authorization)); // header parameter @@ -696,7 +708,7 @@ public async System.Threading.Tasks.Task> AuthorizeAsyncWith var localVarPath = "/oauth/authorize"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -716,10 +728,10 @@ public async System.Threading.Tasks.Task> AuthorizeAsyncWith if (localVarHttpHeaderAccept != null) localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); - if (responseType != null) localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "response_type", responseType)); // query parameter - if (scope != null) localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "scope", scope)); // query parameter - if (redirectUri != null) localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "redirect_uri", redirectUri)); // query parameter - if (clientId != null) localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "client_id", clientId)); // query parameter + if (responseType != null) localVarQueryParams.Add("response_type", Configuration.ApiClient.ParameterToString(responseType)); // query parameter + if (scope != null) localVarQueryParams.Add("scope", Configuration.ApiClient.ParameterToString(scope)); // query parameter + if (redirectUri != null) localVarQueryParams.Add("redirect_uri", Configuration.ApiClient.ParameterToString(redirectUri)); // query parameter + if (clientId != null) localVarQueryParams.Add("client_id", Configuration.ApiClient.ParameterToString(clientId)); // query parameter if (authorization != null) localVarHeaderParams.Add("Authorization", Configuration.ApiClient.ParameterToString(authorization)); // header parameter @@ -769,7 +781,7 @@ public ApiResponse< ApiResponse > ChangePasswordWithHttpInfo (ChangePasswordOper var localVarPath = "/change-password"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -847,7 +859,7 @@ public async System.Threading.Tasks.Task> ChangePasswor var localVarPath = "/change-password"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -922,7 +934,7 @@ public ApiResponse< CloudUserDetails > ConvertTokenWithHttpInfo (string authoriz var localVarPath = "/oauth/convert-token"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -990,7 +1002,7 @@ public async System.Threading.Tasks.Task> ConvertT var localVarPath = "/oauth/convert-token"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -1057,7 +1069,7 @@ public ApiResponse< CloudUserDetails > GetInfoWithHttpInfo (string authorization var localVarPath = "/userinfo"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -1125,7 +1137,7 @@ public async System.Threading.Tasks.Task> GetInfoA var localVarPath = "/userinfo"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -1206,7 +1218,7 @@ public ApiResponse< DefaultOAuth2AccessToken > RetrieveTokenWithHttpInfo (string var localVarPath = "/oauth/token"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -1295,7 +1307,7 @@ public async System.Threading.Tasks.Task> var localVarPath = "/oauth/token"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -1375,7 +1387,7 @@ public ApiResponse SignInWithHttpInfo (string username, string password, var localVarPath = "/sign-in"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -1451,7 +1463,7 @@ public async System.Threading.Tasks.Task> SignInAsyncWithHtt var localVarPath = "/sign-in"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -1522,7 +1534,7 @@ public ApiResponse< ApiResponse > SignOutWithHttpInfo (string authorization, boo var localVarPath = "/sign-out"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -1542,7 +1554,7 @@ public ApiResponse< ApiResponse > SignOutWithHttpInfo (string authorization, boo if (localVarHttpHeaderAccept != null) localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); - if (global != null) localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "global", global)); // query parameter + if (global != null) localVarQueryParams.Add("global", Configuration.ApiClient.ParameterToString(global)); // query parameter if (authorization != null) localVarHeaderParams.Add("Authorization", Configuration.ApiClient.ParameterToString(authorization)); // header parameter @@ -1593,7 +1605,7 @@ public async System.Threading.Tasks.Task> SignOutAsyncW var localVarPath = "/sign-out"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -1613,7 +1625,7 @@ public async System.Threading.Tasks.Task> SignOutAsyncW if (localVarHttpHeaderAccept != null) localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); - if (global != null) localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "global", global)); // query parameter + if (global != null) localVarQueryParams.Add("global", Configuration.ApiClient.ParameterToString(global)); // query parameter if (authorization != null) localVarHeaderParams.Add("Authorization", Configuration.ApiClient.ParameterToString(authorization)); // header parameter @@ -1665,7 +1677,7 @@ public ApiResponse< ApiResponse > SignOut1WithHttpInfo (string authorization, bo var localVarPath = "/sign-out"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -1685,8 +1697,8 @@ public ApiResponse< ApiResponse > SignOut1WithHttpInfo (string authorization, bo if (localVarHttpHeaderAccept != null) localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); - if (global != null) localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "global", global)); // query parameter - if (redirectUri != null) localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "redirectUri", redirectUri)); // query parameter + if (global != null) localVarQueryParams.Add("global", Configuration.ApiClient.ParameterToString(global)); // query parameter + if (redirectUri != null) localVarQueryParams.Add("redirectUri", Configuration.ApiClient.ParameterToString(redirectUri)); // query parameter if (authorization != null) localVarHeaderParams.Add("Authorization", Configuration.ApiClient.ParameterToString(authorization)); // header parameter @@ -1739,7 +1751,7 @@ public async System.Threading.Tasks.Task> SignOut1Async var localVarPath = "/sign-out"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -1759,8 +1771,8 @@ public async System.Threading.Tasks.Task> SignOut1Async if (localVarHttpHeaderAccept != null) localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); - if (global != null) localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "global", global)); // query parameter - if (redirectUri != null) localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "redirectUri", redirectUri)); // query parameter + if (global != null) localVarQueryParams.Add("global", Configuration.ApiClient.ParameterToString(global)); // query parameter + if (redirectUri != null) localVarQueryParams.Add("redirectUri", Configuration.ApiClient.ParameterToString(redirectUri)); // query parameter if (authorization != null) localVarHeaderParams.Add("Authorization", Configuration.ApiClient.ParameterToString(authorization)); // header parameter @@ -1805,7 +1817,7 @@ public ApiResponse< ApiResponse > TenantInfoWithHttpInfo (AuthSchemeLookupData l var localVarPath = "/auth-scheme"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); @@ -1877,7 +1889,7 @@ public async System.Threading.Tasks.Task> TenantInfoAsy var localVarPath = "/auth-scheme"; var localVarPathParams = new Dictionary(); - var localVarQueryParams = new List>(); + var localVarQueryParams = new Dictionary(); var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); var localVarFormParams = new Dictionary(); var localVarFileParams = new Dictionary(); diff --git a/src/Genesys.Internal.Authentication/Client/ApiClient.cs b/src/Genesys.Internal.Authentication/Client/ApiClient.cs index aab1e20..5b91846 100644 --- a/src/Genesys.Internal.Authentication/Client/ApiClient.cs +++ b/src/Genesys.Internal.Authentication/Client/ApiClient.cs @@ -48,11 +48,11 @@ public partial class ApiClient /// /// Initializes a new instance of the class - /// with default configuration. + /// with default configuration and base path (https://your-server.com/auth/v3). /// public ApiClient() { - Configuration = Genesys.Internal.Authentication.Client.Configuration.Default; + Configuration = Configuration.Default; RestClient = new RestClient("https://your-server.com/auth/v3"); } @@ -61,11 +61,14 @@ public ApiClient() /// with default base path (https://your-server.com/auth/v3). /// /// An instance of Configuration. - public ApiClient(Configuration config) + public ApiClient(Configuration config = null) { - Configuration = config ?? Genesys.Internal.Authentication.Client.Configuration.Default; + if (config == null) + Configuration = Configuration.Default; + else + Configuration = config; - RestClient = new RestClient(Configuration.BasePath); + RestClient = new RestClient("https://your-server.com/auth/v3"); } /// @@ -79,7 +82,7 @@ public ApiClient(String basePath = "https://your-server.com/auth/v3") throw new ArgumentException("basePath cannot be empty"); RestClient = new RestClient(basePath); - Configuration = Client.Configuration.Default; + Configuration = Configuration.Default; } /// @@ -90,15 +93,10 @@ public ApiClient(String basePath = "https://your-server.com/auth/v3") public static ApiClient Default; /// - /// Gets or sets an instance of the IReadableConfiguration. + /// Gets or sets the Configuration. /// - /// An instance of the IReadableConfiguration. - /// - /// helps us to avoid modifying possibly global - /// configuration values from within a given client. It does not guarantee thread-safety - /// of the instance in any way. - /// - public IReadableConfiguration Configuration { get; set; } + /// An instance of the Configuration. + public Configuration Configuration { get; set; } /// /// Gets or sets the RestClient. @@ -108,7 +106,7 @@ public ApiClient(String basePath = "https://your-server.com/auth/v3") // Creates and sets up a RestRequest prior to a call. private RestRequest PrepareRequest( - String path, RestSharp.Method method, List> queryParams, Object postBody, + String path, RestSharp.Method method, Dictionary queryParams, Object postBody, Dictionary headerParams, Dictionary formParams, Dictionary fileParams, Dictionary pathParams, String contentType) @@ -139,7 +137,14 @@ private RestRequest PrepareRequest( if (postBody != null) // http body (model or byte[]) parameter { - request.AddParameter(contentType, postBody, ParameterType.RequestBody); + if (postBody.GetType() == typeof(String)) + { + request.AddParameter("application/json", postBody, ParameterType.RequestBody); + } + else if (postBody.GetType() == typeof(byte[])) + { + request.AddParameter(contentType, postBody, ParameterType.RequestBody); + } } return request; @@ -159,7 +164,7 @@ private RestRequest PrepareRequest( /// Content Type of the request /// Object public Object CallApi( - String path, RestSharp.Method method, List> queryParams, Object postBody, + String path, RestSharp.Method method, Dictionary queryParams, Object postBody, Dictionary headerParams, Dictionary formParams, Dictionary fileParams, Dictionary pathParams, String contentType) @@ -169,7 +174,6 @@ public Object CallApi( pathParams, contentType); // set timeout - RestClient.Timeout = Configuration.Timeout; // set user agent RestClient.UserAgent = Configuration.UserAgent; @@ -194,7 +198,7 @@ public Object CallApi( /// Content type. /// The Task instance. public async System.Threading.Tasks.Task CallApiAsync( - String path, RestSharp.Method method, List> queryParams, Object postBody, + String path, RestSharp.Method method, Dictionary queryParams, Object postBody, Dictionary headerParams, Dictionary formParams, Dictionary fileParams, Dictionary pathParams, String contentType) @@ -282,7 +286,6 @@ public object Deserialize(IRestResponse response, Type type) return response.RawBytes; } - // TODO: ? if (type.IsAssignableFrom(typeof(Stream))) if (type == typeof(Stream)) { if (headers != null) @@ -344,25 +347,9 @@ public String Serialize(object obj) } } - /// - ///Check if the given MIME is a JSON MIME. - ///JSON MIME examples: - /// application/json - /// application/json; charset=UTF8 - /// APPLICATION/JSON - /// application/vnd.company+json - /// - /// MIME - /// Returns True if MIME type is json. - public bool IsJsonMime(String mime) - { - var jsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"); - return mime != null && (jsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json")); - } - /// /// Select the Content-Type header's value from the given content-type array: - /// if JSON type exists in the given array, use it; + /// if JSON exists in the given array, use it; /// otherwise use the first one defined in 'consumes' /// /// The Content-Type array to select from. @@ -370,13 +357,10 @@ public bool IsJsonMime(String mime) public String SelectHeaderContentType(String[] contentTypes) { if (contentTypes.Length == 0) - return "application/json"; + return null; - foreach (var contentType in contentTypes) - { - if (IsJsonMime(contentType.ToLower())) - return contentType; - } + if (contentTypes.Contains("application/json", StringComparer.OrdinalIgnoreCase)) + return "application/json"; return contentTypes[0]; // use the first content type specified in 'consumes' } @@ -411,29 +395,31 @@ public static string Base64Encode(string text) /// /// Dynamically cast the object into target type. + /// Ref: http://stackoverflow.com/questions/4925718/c-dynamic-runtime-cast /// - /// Object to be casted - /// Target type + /// Object to be casted + /// Target type /// Casted object - public static dynamic ConvertType(dynamic fromObject, Type toObject) + public static dynamic ConvertType(dynamic source, Type dest) { - return Convert.ChangeType(fromObject, toObject); + return Convert.ChangeType(source, dest); } /// /// Convert stream to byte array + /// Credit/Ref: http://stackoverflow.com/a/221941/677735 /// - /// Input stream to be converted + /// Input stream to be converted /// Byte array - public static byte[] ReadAsBytes(Stream inputStream) + public static byte[] ReadAsBytes(Stream input) { - byte[] buf = new byte[16*1024]; + byte[] buffer = new byte[16*1024]; using (MemoryStream ms = new MemoryStream()) { - int count; - while ((count = inputStream.Read(buf, 0, buf.Length)) > 0) + int read; + while ((read = input.Read(buffer, 0, buffer.Length)) > 0) { - ms.Write(buf, 0, count); + ms.Write(buffer, 0, read); } return ms.ToArray(); } @@ -492,39 +478,5 @@ public static string SanitizeFilename(string filename) return filename; } } - - /// - /// Convert params to key/value pairs. - /// Use collectionFormat to properly format lists and collections. - /// - /// Key name. - /// Value object. - /// A list of KeyValuePairs - public IEnumerable> ParameterToKeyValuePairs(string collectionFormat, string name, object value) - { - var parameters = new List>(); - - if (IsCollection(value) && collectionFormat == "multi") - { - var valueCollection = value as IEnumerable; - parameters.AddRange(from object item in valueCollection select new KeyValuePair(name, ParameterToString(item))); - } - else - { - parameters.Add(new KeyValuePair(name, ParameterToString(value))); - } - - return parameters; - } - - /// - /// Check if generic object is a collection. - /// - /// - /// True if object is a collection type - private static bool IsCollection(object value) - { - return value is IList || value is ICollection; - } } } diff --git a/src/Genesys.Internal.Authentication/Client/Configuration.cs b/src/Genesys.Internal.Authentication/Client/Configuration.cs index 9fe25ce..9eef528 100644 --- a/src/Genesys.Internal.Authentication/Client/Configuration.cs +++ b/src/Genesys.Internal.Authentication/Client/Configuration.cs @@ -10,7 +10,6 @@ using System; using System.Reflection; -using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; @@ -21,9 +20,62 @@ namespace Genesys.Internal.Authentication.Client /// /// Represents a set of configuration settings /// - public class Configuration : IReadableConfiguration + public class Configuration { - #region Constants + /// + /// Initializes a new instance of the Configuration class with different settings + /// + /// Api client + /// Dictionary of default HTTP header + /// Username + /// Password + /// accessToken + /// Dictionary of API key + /// Dictionary of API key prefix + /// Temp folder path + /// DateTime format string + /// HTTP connection timeout (in milliseconds) + /// HTTP user agent + public Configuration(ApiClient apiClient = null, + Dictionary defaultHeader = null, + string username = null, + string password = null, + string accessToken = null, + Dictionary apiKey = null, + Dictionary apiKeyPrefix = null, + string tempFolderPath = null, + string dateTimeFormat = null, + int timeout = 100000, + string userAgent = "Swagger-Codegen/1.0.0/csharp" + ) + { + setApiClientUsingDefault(apiClient); + + Username = username; + Password = password; + AccessToken = accessToken; + UserAgent = userAgent; + + if (defaultHeader != null) + DefaultHeader = defaultHeader; + if (apiKey != null) + ApiKey = apiKey; + if (apiKeyPrefix != null) + ApiKeyPrefix = apiKeyPrefix; + + TempFolderPath = tempFolderPath; + DateTimeFormat = dateTimeFormat; + Timeout = timeout; + } + + /// + /// Initializes a new instance of the Configuration class. + /// + /// Api client. + public Configuration(ApiClient apiClient) + { + setApiClientUsingDefault(apiClient); + } /// /// Version of the package. @@ -32,251 +84,155 @@ public class Configuration : IReadableConfiguration public const string Version = "1.0.0"; /// - /// Identifier for ISO 8601 DateTime Format + /// Gets or sets the default Configuration. /// - /// See https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8 for more information. - // ReSharper disable once InconsistentNaming - public const string ISO8601_DATETIME_FORMAT = "o"; - - #endregion Constants - - #region Static Members - - private static readonly object GlobalConfigSync = new { }; - private static Configuration _globalConfiguration; + /// Configuration. + public static Configuration Default = new Configuration(); /// /// Default creation of exceptions for a given method name and response object /// public static readonly ExceptionFactory DefaultExceptionFactory = (methodName, response) => { - var status = (int)response.StatusCode; - if (status >= 400) - { - return new ApiException(status, - string.Format("Error calling {0}: {1}", methodName, response.Content), - response.Content); - } - if (status == 0) - { - return new ApiException(status, - string.Format("Error calling {0}: {1}", methodName, response.ErrorMessage), response.ErrorMessage); - } + int status = (int) response.StatusCode; + if (status >= 400) return new ApiException(status, String.Format("Error calling {0}: {1}", methodName, response.Content), response.Content); + if (status == 0) return new ApiException(status, String.Format("Error calling {0}: {1}", methodName, response.ErrorMessage), response.ErrorMessage); return null; }; /// - /// Gets or sets the default Configuration. + /// Gets or sets the HTTP timeout (milliseconds) of ApiClient. Default to 100000 milliseconds. /// - /// Configuration. - public static Configuration Default + /// Timeout. + public int Timeout { - get { return _globalConfiguration; } + get { return ApiClient.RestClient.Timeout; } + set { - lock (GlobalConfigSync) - { - _globalConfiguration = value; - } + if (ApiClient != null) + ApiClient.RestClient.Timeout = value; } } - #endregion Static Members - - #region Private Members - /// - /// Gets or sets the API key based on the authentication name. + /// Gets or sets the default API client for making HTTP calls. /// - /// The API key. - private IDictionary _apiKey = null; + /// The API client. + public ApiClient ApiClient; /// - /// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name. + /// Set the ApiClient using Default or ApiClient instance. /// - /// The prefix of the API key. - private IDictionary _apiKeyPrefix = null; - - private string _dateTimeFormat = ISO8601_DATETIME_FORMAT; - private string _tempFolderPath = Path.GetTempPath(); - - #endregion Private Members + /// An instance of ApiClient. + /// + public void setApiClientUsingDefault (ApiClient apiClient = null) + { + if (apiClient == null) + { + if (Default != null && Default.ApiClient == null) + Default.ApiClient = new ApiClient(); - #region Constructors + ApiClient = Default != null ? Default.ApiClient : new ApiClient(); + } + else + { + if (Default != null && Default.ApiClient == null) + Default.ApiClient = apiClient; - static Configuration() - { - _globalConfiguration = new GlobalConfiguration(); + ApiClient = apiClient; + } } - /// - /// Initializes a new instance of the class - /// - public Configuration() - { - UserAgent = "Swagger-Codegen/1.0.0/csharp"; - BasePath = "https://your-server.com/auth/v3"; - DefaultHeader = new ConcurrentDictionary(); - ApiKey = new ConcurrentDictionary(); - ApiKeyPrefix = new ConcurrentDictionary(); - - // Setting Timeout has side effects (forces ApiClient creation). - Timeout = 100000; - } + private Dictionary _defaultHeaderMap = new Dictionary(); /// - /// Initializes a new instance of the class + /// Gets or sets the default header. /// - public Configuration( - IDictionary defaultHeader, - IDictionary apiKey, - IDictionary apiKeyPrefix, - string basePath = "https://your-server.com/auth/v3") : this() + public Dictionary DefaultHeader { - if (string.IsNullOrWhiteSpace(basePath)) - throw new ArgumentException("The provided basePath is invalid.", "basePath"); - if (defaultHeader == null) - throw new ArgumentNullException("defaultHeader"); - if (apiKey == null) - throw new ArgumentNullException("apiKey"); - if (apiKeyPrefix == null) - throw new ArgumentNullException("apiKeyPrefix"); - - BasePath = basePath; - - foreach (var keyValuePair in defaultHeader) - { - DefaultHeader.Add(keyValuePair); - } + get { return _defaultHeaderMap; } - foreach (var keyValuePair in apiKey) - { - ApiKey.Add(keyValuePair); - } - - foreach (var keyValuePair in apiKeyPrefix) + set { - ApiKeyPrefix.Add(keyValuePair); + _defaultHeaderMap = value; } } /// - /// Initializes a new instance of the class with different settings + /// Add default header. /// - /// Api client - /// Dictionary of default HTTP header - /// Username - /// Password - /// accessToken - /// Dictionary of API key - /// Dictionary of API key prefix - /// Temp folder path - /// DateTime format string - /// HTTP connection timeout (in milliseconds) - /// HTTP user agent - [Obsolete("Use explicit object construction and setting of properties.", true)] - public Configuration( - // ReSharper disable UnusedParameter.Local - ApiClient apiClient = null, - IDictionary defaultHeader = null, - string username = null, - string password = null, - string accessToken = null, - IDictionary apiKey = null, - IDictionary apiKeyPrefix = null, - string tempFolderPath = null, - string dateTimeFormat = null, - int timeout = 100000, - string userAgent = "Swagger-Codegen/1.0.0/csharp" - // ReSharper restore UnusedParameter.Local - ) + /// Header field name. + /// Header field value. + /// + public void AddDefaultHeader(string key, string value) { - + _defaultHeaderMap[key] = value; } /// - /// Initializes a new instance of the Configuration class. + /// Add Api Key Header. /// - /// Api client. - [Obsolete("This constructor caused unexpected sharing of static data. It is no longer supported.", true)] - // ReSharper disable once UnusedParameter.Local - public Configuration(ApiClient apiClient) + /// Api Key name. + /// Api Key value. + /// + public void AddApiKey(string key, string value) { - + ApiKey[key] = value; } - #endregion Constructors - - - #region Properties - - private ApiClient _apiClient = null; /// - /// Gets an instance of an ApiClient for this configuration + /// Sets the API key prefix. /// - public virtual ApiClient ApiClient + /// Api Key name. + /// Api Key value. + public void AddApiKeyPrefix(string key, string value) { - get - { - if (_apiClient == null) _apiClient = CreateApiClient(); - return _apiClient; - } + ApiKeyPrefix[key] = value; } - private String _basePath = null; /// - /// Gets or sets the base path for API access. + /// Gets or sets the HTTP user agent. /// - public virtual string BasePath { - get { return _basePath; } - set { - _basePath = value; - // pass-through to ApiClient if it's set. - if(_apiClient != null) { - _apiClient.RestClient.BaseUrl = new Uri(_basePath); - } - } - } + /// Http user agent. + public String UserAgent { get; set; } /// - /// Gets or sets the default header. + /// Gets or sets the username (HTTP basic authentication). /// - public virtual IDictionary DefaultHeader { get; set; } + /// The username. + public String Username { get; set; } /// - /// Gets or sets the HTTP timeout (milliseconds) of ApiClient. Default to 100000 milliseconds. + /// Gets or sets the password (HTTP basic authentication). /// - public virtual int Timeout - { - - get { return ApiClient.RestClient.Timeout; } - set { ApiClient.RestClient.Timeout = value; } - } + /// The password. + public String Password { get; set; } /// - /// Gets or sets the HTTP user agent. + /// Gets or sets the access token for OAuth2 authentication. /// - /// Http user agent. - public virtual string UserAgent { get; set; } + /// The access token. + public String AccessToken { get; set; } /// - /// Gets or sets the username (HTTP basic authentication). + /// Gets or sets the API key based on the authentication name. /// - /// The username. - public virtual string Username { get; set; } + /// The API key. + public Dictionary ApiKey = new Dictionary(); /// - /// Gets or sets the password (HTTP basic authentication). + /// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name. /// - /// The password. - public virtual string Password { get; set; } + /// The prefix of the API key. + public Dictionary ApiKeyPrefix = new Dictionary(); /// - /// Gets the API key with prefix. + /// Get the API key with prefix. /// /// API key identifier (authentication scheme). /// API key with prefix. - public string GetApiKeyWithPrefix(string apiKeyIdentifier) + public string GetApiKeyWithPrefix (string apiKeyIdentifier) { var apiKeyValue = ""; ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue); @@ -287,47 +243,48 @@ public string GetApiKeyWithPrefix(string apiKeyIdentifier) return apiKeyValue; } - /// - /// Gets or sets the access token for OAuth2 authentication. - /// - /// The access token. - public virtual string AccessToken { get; set; } + private string _tempFolderPath; /// /// Gets or sets the temporary folder path to store the files downloaded from the server. /// /// Folder path. - public virtual string TempFolderPath + public String TempFolderPath { - get { return _tempFolderPath; } + get + { + // default to Path.GetTempPath() if _tempFolderPath is not set + if (String.IsNullOrEmpty(_tempFolderPath)) + { + _tempFolderPath = Path.GetTempPath(); + } + return _tempFolderPath; + } set { - if (string.IsNullOrEmpty(value)) + if (String.IsNullOrEmpty(value)) { - // Possible breaking change since swagger-codegen 2.2.1, enforce a valid temporary path on set. - _tempFolderPath = Path.GetTempPath(); + _tempFolderPath = value; return; } // create the directory if it does not exist if (!Directory.Exists(value)) - { Directory.CreateDirectory(value); - } // check if the path contains directory separator at the end if (value[value.Length - 1] == Path.DirectorySeparatorChar) - { _tempFolderPath = value; - } else - { - _tempFolderPath = value + Path.DirectorySeparatorChar; - } + _tempFolderPath = value + Path.DirectorySeparatorChar; } } + private const string ISO8601_DATETIME_FORMAT = "o"; + + private string _dateTimeFormat = ISO8601_DATETIME_FORMAT; + /// /// Gets or sets the the date time format used when serializing in the ApiClient /// By default, it's set to ISO 8601 - "o", for others see: @@ -336,9 +293,12 @@ public virtual string TempFolderPath /// No validation is done to ensure that the string you're providing is valid /// /// The DateTimeFormat string - public virtual string DateTimeFormat + public String DateTimeFormat { - get { return _dateTimeFormat; } + get + { + return _dateTimeFormat; + } set { if (string.IsNullOrEmpty(value)) @@ -354,100 +314,21 @@ public virtual string DateTimeFormat } } - /// - /// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name. - /// - /// The prefix of the API key. - public virtual IDictionary ApiKeyPrefix - { - get { return _apiKeyPrefix; } - set - { - if (value == null) - { - throw new InvalidOperationException("ApiKeyPrefix collection may not be null."); - } - _apiKeyPrefix = value; - } - } - - /// - /// Gets or sets the API key based on the authentication name. - /// - /// The API key. - public virtual IDictionary ApiKey - { - get { return _apiKey; } - set - { - if (value == null) - { - throw new InvalidOperationException("ApiKey collection may not be null."); - } - _apiKey = value; - } - } - - #endregion Properties - - #region Methods - - /// - /// Add default header. - /// - /// Header field name. - /// Header field value. - /// - public void AddDefaultHeader(string key, string value) - { - DefaultHeader[key] = value; - } - - /// - /// Creates a new based on this instance. - /// - /// - public ApiClient CreateApiClient() - { - return new ApiClient(BasePath) { Configuration = this }; - } - - /// /// Returns a string with essential information for debugging. /// public static String ToDebugReport() { String report = "C# SDK (Genesys.Internal.Authentication) Debug Report:\n"; - report += " OS: " + System.Environment.OSVersion + "\n"; - report += " .NET Framework Version: " + System.Environment.Version + "\n"; + report += " OS: " + Environment.OSVersion + "\n"; + report += " .NET Framework Version: " + Assembly + .GetExecutingAssembly() + .GetReferencedAssemblies() + .Where(x => x.Name == "System.Core").First().Version.ToString() + "\n"; report += " Version of the API: 9.0.000.10.1112\n"; report += " SDK Package Version: 1.0.0\n"; return report; } - - /// - /// Add Api Key Header. - /// - /// Api Key name. - /// Api Key value. - /// - public void AddApiKey(string key, string value) - { - ApiKey[key] = value; - } - - /// - /// Sets the API key prefix. - /// - /// Api Key name. - /// Api Key value. - public void AddApiKeyPrefix(string key, string value) - { - ApiKeyPrefix[key] = value; - } - - #endregion Methods } } diff --git a/src/Genesys.Internal.Authentication/Client/GlobalConfiguration.cs b/src/Genesys.Internal.Authentication/Client/GlobalConfiguration.cs deleted file mode 100644 index 57d4024..0000000 --- a/src/Genesys.Internal.Authentication/Client/GlobalConfiguration.cs +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Authentication API - * - * Authentication API - * - * OpenAPI spec version: 9.0.000.10.1112 - * - * Generated by: https://github.com/swagger-api/swagger-codegen.git - */ - - -using System; -using System.Reflection; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading; - -namespace Genesys.Internal.Authentication.Client -{ - /// - /// provides a compile-time extension point for globally configuring - /// API Clients. - /// - /// - /// A customized implementation via partial class may reside in another file and may - /// be excluded from automatic generation via a .swagger-codegen-ignore file. - /// - public partial class GlobalConfiguration : Configuration - { - - } -} \ No newline at end of file diff --git a/src/Genesys.Internal.Authentication/Client/IReadableConfiguration.cs b/src/Genesys.Internal.Authentication/Client/IReadableConfiguration.cs deleted file mode 100644 index b22913f..0000000 --- a/src/Genesys.Internal.Authentication/Client/IReadableConfiguration.cs +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Authentication API - * - * Authentication API - * - * OpenAPI spec version: 9.0.000.10.1112 - * - * Generated by: https://github.com/swagger-api/swagger-codegen.git - */ - - -using System.Collections.Generic; - -namespace Genesys.Internal.Authentication.Client -{ - /// - /// Represents a readable-only configuration contract. - /// - public interface IReadableConfiguration - { - /// - /// Gets the access token. - /// - /// Access token. - string AccessToken { get; } - - /// - /// Gets the API key. - /// - /// API key. - IDictionary ApiKey { get; } - - /// - /// Gets the API key prefix. - /// - /// API key prefix. - IDictionary ApiKeyPrefix { get; } - - /// - /// Gets the base path. - /// - /// Base path. - string BasePath { get; } - - /// - /// Gets the date time format. - /// - /// Date time foramt. - string DateTimeFormat { get; } - - /// - /// Gets the default header. - /// - /// Default header. - IDictionary DefaultHeader { get; } - - /// - /// Gets the temp folder path. - /// - /// Temp folder path. - string TempFolderPath { get; } - - /// - /// Gets the HTTP connection timeout (in milliseconds) - /// - /// HTTP connection timeout. - int Timeout { get; } - - /// - /// Gets the user agent. - /// - /// User agent. - string UserAgent { get; } - - /// - /// Gets the username. - /// - /// Username. - string Username { get; } - - /// - /// Gets the password. - /// - /// Password. - string Password { get; } - - /// - /// Gets the API key with prefix. - /// - /// API key identifier (authentication scheme). - /// API key with prefix. - string GetApiKeyWithPrefix(string apiKeyIdentifier); - } -} diff --git a/src/Genesys.Internal.Authentication/Genesys.Internal.Authentication.csproj b/src/Genesys.Internal.Authentication/Genesys.Internal.Authentication.csproj index 50dd0f7..7ff08d7 100644 --- a/src/Genesys.Internal.Authentication/Genesys.Internal.Authentication.csproj +++ b/src/Genesys.Internal.Authentication/Genesys.Internal.Authentication.csproj @@ -12,7 +12,7 @@ OpenAPI spec version: 9.0.000.10.1112 Debug AnyCPU - {8789D6BC-260E-4FF3-A0A7-829089A3895D} + {67CDFAE9-DDF6-4949-8628-7841E5569EAC} Library Properties Genesys.Internal.Authentication @@ -53,12 +53,6 @@ OpenAPI spec version: 9.0.000.10.1112 ..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll ..\..\vendor\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll - - $(SolutionDir)\packages\JsonSubTypes.1.2.0\lib\net45\JsonSubTypes.dll - ..\packages\JsonSubTypes.1.2.0\lib\net45\JsonSubTypes.dll - ..\..\packages\JsonSubTypes.1.2.0\lib\net45\JsonSubTypes.dll - ..\..\vendor\JsonSubTypes.1.2.0\lib\net45\JsonSubTypes.dll - $(SolutionDir)\packages\RestSharp.105.1.0\lib\net45\RestSharp.dll ..\packages\RestSharp.105.1.0\lib\net45\RestSharp.dll diff --git a/src/Genesys.Internal.Authentication/Genesys.Internal.Authentication.nuspec b/src/Genesys.Internal.Authentication/Genesys.Internal.Authentication.nuspec index 93f28ce..154b80a 100644 --- a/src/Genesys.Internal.Authentication/Genesys.Internal.Authentication.nuspec +++ b/src/Genesys.Internal.Authentication/Genesys.Internal.Authentication.nuspec @@ -25,7 +25,6 @@ - diff --git a/src/Genesys.Internal.Authentication/Model/ApiResponse.cs b/src/Genesys.Internal.Authentication/Model/ApiResponse.cs index b068c2c..a347819 100644 --- a/src/Genesys.Internal.Authentication/Model/ApiResponse.cs +++ b/src/Genesys.Internal.Authentication/Model/ApiResponse.cs @@ -110,43 +110,45 @@ public string ToJson() /// /// Returns true if objects are equal /// - /// Object to be compared + /// Object to be compared /// Boolean - public override bool Equals(object input) + public override bool Equals(object obj) { - return this.Equals(input as ApiResponse); + // credit: http://stackoverflow.com/a/10454552/677735 + return this.Equals(obj as ApiResponse); } /// /// Returns true if ApiResponse instances are equal /// - /// Instance of ApiResponse to be compared + /// Instance of ApiResponse to be compared /// Boolean - public bool Equals(ApiResponse input) + public bool Equals(ApiResponse other) { - if (input == null) + // credit: http://stackoverflow.com/a/10454552/677735 + if (other == null) return false; return ( - this.Data == input.Data || - (this.Data != null && - this.Data.Equals(input.Data)) + this.Data == other.Data || + this.Data != null && + this.Data.Equals(other.Data) ) && ( - this.Errors == input.Errors || - (this.Errors != null && - this.Errors.Equals(input.Errors)) + this.Errors == other.Errors || + this.Errors != null && + this.Errors.Equals(other.Errors) ) && ( - this.Path == input.Path || - (this.Path != null && - this.Path.Equals(input.Path)) + this.Path == other.Path || + this.Path != null && + this.Path.Equals(other.Path) ) && ( - this.Status == input.Status || - (this.Status != null && - this.Status.Equals(input.Status)) + this.Status == other.Status || + this.Status != null && + this.Status.Equals(other.Status) ); } @@ -156,18 +158,20 @@ public bool Equals(ApiResponse input) /// Hash code public override int GetHashCode() { + // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { - int hashCode = 41; + int hash = 41; + // Suitable nullity checks etc, of course :) if (this.Data != null) - hashCode = hashCode * 59 + this.Data.GetHashCode(); + hash = hash * 59 + this.Data.GetHashCode(); if (this.Errors != null) - hashCode = hashCode * 59 + this.Errors.GetHashCode(); + hash = hash * 59 + this.Errors.GetHashCode(); if (this.Path != null) - hashCode = hashCode * 59 + this.Path.GetHashCode(); + hash = hash * 59 + this.Path.GetHashCode(); if (this.Status != null) - hashCode = hashCode * 59 + this.Status.GetHashCode(); - return hashCode; + hash = hash * 59 + this.Status.GetHashCode(); + return hash; } } diff --git a/src/Genesys.Internal.Authentication/Model/AuthSchemeLookupData.cs b/src/Genesys.Internal.Authentication/Model/AuthSchemeLookupData.cs index 0157391..ee2a8bc 100644 --- a/src/Genesys.Internal.Authentication/Model/AuthSchemeLookupData.cs +++ b/src/Genesys.Internal.Authentication/Model/AuthSchemeLookupData.cs @@ -100,33 +100,35 @@ public string ToJson() /// /// Returns true if objects are equal /// - /// Object to be compared + /// Object to be compared /// Boolean - public override bool Equals(object input) + public override bool Equals(object obj) { - return this.Equals(input as AuthSchemeLookupData); + // credit: http://stackoverflow.com/a/10454552/677735 + return this.Equals(obj as AuthSchemeLookupData); } /// /// Returns true if AuthSchemeLookupData instances are equal /// - /// Instance of AuthSchemeLookupData to be compared + /// Instance of AuthSchemeLookupData to be compared /// Boolean - public bool Equals(AuthSchemeLookupData input) + public bool Equals(AuthSchemeLookupData other) { - if (input == null) + // credit: http://stackoverflow.com/a/10454552/677735 + if (other == null) return false; return ( - this.UserName == input.UserName || - (this.UserName != null && - this.UserName.Equals(input.UserName)) + this.UserName == other.UserName || + this.UserName != null && + this.UserName.Equals(other.UserName) ) && ( - this.Tenant == input.Tenant || - (this.Tenant != null && - this.Tenant.Equals(input.Tenant)) + this.Tenant == other.Tenant || + this.Tenant != null && + this.Tenant.Equals(other.Tenant) ); } @@ -136,14 +138,16 @@ public bool Equals(AuthSchemeLookupData input) /// Hash code public override int GetHashCode() { + // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { - int hashCode = 41; + int hash = 41; + // Suitable nullity checks etc, of course :) if (this.UserName != null) - hashCode = hashCode * 59 + this.UserName.GetHashCode(); + hash = hash * 59 + this.UserName.GetHashCode(); if (this.Tenant != null) - hashCode = hashCode * 59 + this.Tenant.GetHashCode(); - return hashCode; + hash = hash * 59 + this.Tenant.GetHashCode(); + return hash; } } diff --git a/src/Genesys.Internal.Authentication/Model/ChangePasswordOperation.cs b/src/Genesys.Internal.Authentication/Model/ChangePasswordOperation.cs index c230b7c..d807bc8 100644 --- a/src/Genesys.Internal.Authentication/Model/ChangePasswordOperation.cs +++ b/src/Genesys.Internal.Authentication/Model/ChangePasswordOperation.cs @@ -117,38 +117,40 @@ public string ToJson() /// /// Returns true if objects are equal /// - /// Object to be compared + /// Object to be compared /// Boolean - public override bool Equals(object input) + public override bool Equals(object obj) { - return this.Equals(input as ChangePasswordOperation); + // credit: http://stackoverflow.com/a/10454552/677735 + return this.Equals(obj as ChangePasswordOperation); } /// /// Returns true if ChangePasswordOperation instances are equal /// - /// Instance of ChangePasswordOperation to be compared + /// Instance of ChangePasswordOperation to be compared /// Boolean - public bool Equals(ChangePasswordOperation input) + public bool Equals(ChangePasswordOperation other) { - if (input == null) + // credit: http://stackoverflow.com/a/10454552/677735 + if (other == null) return false; return ( - this.UserName == input.UserName || - (this.UserName != null && - this.UserName.Equals(input.UserName)) + this.UserName == other.UserName || + this.UserName != null && + this.UserName.Equals(other.UserName) ) && ( - this.OldPassword == input.OldPassword || - (this.OldPassword != null && - this.OldPassword.Equals(input.OldPassword)) + this.OldPassword == other.OldPassword || + this.OldPassword != null && + this.OldPassword.Equals(other.OldPassword) ) && ( - this.NewPassword == input.NewPassword || - (this.NewPassword != null && - this.NewPassword.Equals(input.NewPassword)) + this.NewPassword == other.NewPassword || + this.NewPassword != null && + this.NewPassword.Equals(other.NewPassword) ); } @@ -158,16 +160,18 @@ public bool Equals(ChangePasswordOperation input) /// Hash code public override int GetHashCode() { + // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { - int hashCode = 41; + int hash = 41; + // Suitable nullity checks etc, of course :) if (this.UserName != null) - hashCode = hashCode * 59 + this.UserName.GetHashCode(); + hash = hash * 59 + this.UserName.GetHashCode(); if (this.OldPassword != null) - hashCode = hashCode * 59 + this.OldPassword.GetHashCode(); + hash = hash * 59 + this.OldPassword.GetHashCode(); if (this.NewPassword != null) - hashCode = hashCode * 59 + this.NewPassword.GetHashCode(); - return hashCode; + hash = hash * 59 + this.NewPassword.GetHashCode(); + return hash; } } diff --git a/src/Genesys.Internal.Authentication/Model/CloudUserDetails.cs b/src/Genesys.Internal.Authentication/Model/CloudUserDetails.cs index ef2823b..43de271 100644 --- a/src/Genesys.Internal.Authentication/Model/CloudUserDetails.cs +++ b/src/Genesys.Internal.Authentication/Model/CloudUserDetails.cs @@ -152,58 +152,60 @@ public string ToJson() /// /// Returns true if objects are equal /// - /// Object to be compared + /// Object to be compared /// Boolean - public override bool Equals(object input) + public override bool Equals(object obj) { - return this.Equals(input as CloudUserDetails); + // credit: http://stackoverflow.com/a/10454552/677735 + return this.Equals(obj as CloudUserDetails); } /// /// Returns true if CloudUserDetails instances are equal /// - /// Instance of CloudUserDetails to be compared + /// Instance of CloudUserDetails to be compared /// Boolean - public bool Equals(CloudUserDetails input) + public bool Equals(CloudUserDetails other) { - if (input == null) + // credit: http://stackoverflow.com/a/10454552/677735 + if (other == null) return false; return ( - this.Authorities == input.Authorities || - (this.Authorities != null && - this.Authorities.Equals(input.Authorities)) + this.Authorities == other.Authorities || + this.Authorities != null && + this.Authorities.Equals(other.Authorities) ) && ( - this.CmeUserName == input.CmeUserName || - (this.CmeUserName != null && - this.CmeUserName.Equals(input.CmeUserName)) + this.CmeUserName == other.CmeUserName || + this.CmeUserName != null && + this.CmeUserName.Equals(other.CmeUserName) ) && ( - this.ContactCenterId == input.ContactCenterId || - (this.ContactCenterId != null && - this.ContactCenterId.Equals(input.ContactCenterId)) + this.ContactCenterId == other.ContactCenterId || + this.ContactCenterId != null && + this.ContactCenterId.Equals(other.ContactCenterId) ) && ( - this.Dbid == input.Dbid || - (this.Dbid != null && - this.Dbid.Equals(input.Dbid)) + this.Dbid == other.Dbid || + this.Dbid != null && + this.Dbid.Equals(other.Dbid) ) && ( - this.EnvironmentId == input.EnvironmentId || - (this.EnvironmentId != null && - this.EnvironmentId.Equals(input.EnvironmentId)) + this.EnvironmentId == other.EnvironmentId || + this.EnvironmentId != null && + this.EnvironmentId.Equals(other.EnvironmentId) ) && ( - this.LoginName == input.LoginName || - (this.LoginName != null && - this.LoginName.Equals(input.LoginName)) + this.LoginName == other.LoginName || + this.LoginName != null && + this.LoginName.Equals(other.LoginName) ) && ( - this.Username == input.Username || - (this.Username != null && - this.Username.Equals(input.Username)) + this.Username == other.Username || + this.Username != null && + this.Username.Equals(other.Username) ); } @@ -213,24 +215,26 @@ public bool Equals(CloudUserDetails input) /// Hash code public override int GetHashCode() { + // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { - int hashCode = 41; + int hash = 41; + // Suitable nullity checks etc, of course :) if (this.Authorities != null) - hashCode = hashCode * 59 + this.Authorities.GetHashCode(); + hash = hash * 59 + this.Authorities.GetHashCode(); if (this.CmeUserName != null) - hashCode = hashCode * 59 + this.CmeUserName.GetHashCode(); + hash = hash * 59 + this.CmeUserName.GetHashCode(); if (this.ContactCenterId != null) - hashCode = hashCode * 59 + this.ContactCenterId.GetHashCode(); + hash = hash * 59 + this.ContactCenterId.GetHashCode(); if (this.Dbid != null) - hashCode = hashCode * 59 + this.Dbid.GetHashCode(); + hash = hash * 59 + this.Dbid.GetHashCode(); if (this.EnvironmentId != null) - hashCode = hashCode * 59 + this.EnvironmentId.GetHashCode(); + hash = hash * 59 + this.EnvironmentId.GetHashCode(); if (this.LoginName != null) - hashCode = hashCode * 59 + this.LoginName.GetHashCode(); + hash = hash * 59 + this.LoginName.GetHashCode(); if (this.Username != null) - hashCode = hashCode * 59 + this.Username.GetHashCode(); - return hashCode; + hash = hash * 59 + this.Username.GetHashCode(); + return hash; } } diff --git a/src/Genesys.Internal.Authentication/Model/DefaultOAuth2AccessToken.cs b/src/Genesys.Internal.Authentication/Model/DefaultOAuth2AccessToken.cs index 7516380..5475242 100644 --- a/src/Genesys.Internal.Authentication/Model/DefaultOAuth2AccessToken.cs +++ b/src/Genesys.Internal.Authentication/Model/DefaultOAuth2AccessToken.cs @@ -111,48 +111,50 @@ public string ToJson() /// /// Returns true if objects are equal /// - /// Object to be compared + /// Object to be compared /// Boolean - public override bool Equals(object input) + public override bool Equals(object obj) { - return this.Equals(input as DefaultOAuth2AccessToken); + // credit: http://stackoverflow.com/a/10454552/677735 + return this.Equals(obj as DefaultOAuth2AccessToken); } /// /// Returns true if DefaultOAuth2AccessToken instances are equal /// - /// Instance of DefaultOAuth2AccessToken to be compared + /// Instance of DefaultOAuth2AccessToken to be compared /// Boolean - public bool Equals(DefaultOAuth2AccessToken input) + public bool Equals(DefaultOAuth2AccessToken other) { - if (input == null) + // credit: http://stackoverflow.com/a/10454552/677735 + if (other == null) return false; return ( - this.AccessToken == input.AccessToken || - (this.AccessToken != null && - this.AccessToken.Equals(input.AccessToken)) + this.AccessToken == other.AccessToken || + this.AccessToken != null && + this.AccessToken.Equals(other.AccessToken) ) && ( - this.ExpiresIn == input.ExpiresIn || - (this.ExpiresIn != null && - this.ExpiresIn.Equals(input.ExpiresIn)) + this.ExpiresIn == other.ExpiresIn || + this.ExpiresIn != null && + this.ExpiresIn.Equals(other.ExpiresIn) ) && ( - this.RefreshToken == input.RefreshToken || - (this.RefreshToken != null && - this.RefreshToken.Equals(input.RefreshToken)) + this.RefreshToken == other.RefreshToken || + this.RefreshToken != null && + this.RefreshToken.Equals(other.RefreshToken) ) && ( - this.Scope == input.Scope || - (this.Scope != null && - this.Scope.Equals(input.Scope)) + this.Scope == other.Scope || + this.Scope != null && + this.Scope.Equals(other.Scope) ) && ( - this.TokenType == input.TokenType || - (this.TokenType != null && - this.TokenType.Equals(input.TokenType)) + this.TokenType == other.TokenType || + this.TokenType != null && + this.TokenType.Equals(other.TokenType) ); } @@ -162,20 +164,22 @@ public bool Equals(DefaultOAuth2AccessToken input) /// Hash code public override int GetHashCode() { + // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { - int hashCode = 41; + int hash = 41; + // Suitable nullity checks etc, of course :) if (this.AccessToken != null) - hashCode = hashCode * 59 + this.AccessToken.GetHashCode(); + hash = hash * 59 + this.AccessToken.GetHashCode(); if (this.ExpiresIn != null) - hashCode = hashCode * 59 + this.ExpiresIn.GetHashCode(); + hash = hash * 59 + this.ExpiresIn.GetHashCode(); if (this.RefreshToken != null) - hashCode = hashCode * 59 + this.RefreshToken.GetHashCode(); + hash = hash * 59 + this.RefreshToken.GetHashCode(); if (this.Scope != null) - hashCode = hashCode * 59 + this.Scope.GetHashCode(); + hash = hash * 59 + this.Scope.GetHashCode(); if (this.TokenType != null) - hashCode = hashCode * 59 + this.TokenType.GetHashCode(); - return hashCode; + hash = hash * 59 + this.TokenType.GetHashCode(); + return hash; } } diff --git a/src/Genesys.Internal.Authentication/Model/ErrorResponse.cs b/src/Genesys.Internal.Authentication/Model/ErrorResponse.cs index d1c3e9b..7564dff 100644 --- a/src/Genesys.Internal.Authentication/Model/ErrorResponse.cs +++ b/src/Genesys.Internal.Authentication/Model/ErrorResponse.cs @@ -79,33 +79,35 @@ public string ToJson() /// /// Returns true if objects are equal /// - /// Object to be compared + /// Object to be compared /// Boolean - public override bool Equals(object input) + public override bool Equals(object obj) { - return this.Equals(input as ErrorResponse); + // credit: http://stackoverflow.com/a/10454552/677735 + return this.Equals(obj as ErrorResponse); } /// /// Returns true if ErrorResponse instances are equal /// - /// Instance of ErrorResponse to be compared + /// Instance of ErrorResponse to be compared /// Boolean - public bool Equals(ErrorResponse input) + public bool Equals(ErrorResponse other) { - if (input == null) + // credit: http://stackoverflow.com/a/10454552/677735 + if (other == null) return false; return ( - this.Error == input.Error || - (this.Error != null && - this.Error.Equals(input.Error)) + this.Error == other.Error || + this.Error != null && + this.Error.Equals(other.Error) ) && ( - this.ErrorDescription == input.ErrorDescription || - (this.ErrorDescription != null && - this.ErrorDescription.Equals(input.ErrorDescription)) + this.ErrorDescription == other.ErrorDescription || + this.ErrorDescription != null && + this.ErrorDescription.Equals(other.ErrorDescription) ); } @@ -115,14 +117,16 @@ public bool Equals(ErrorResponse input) /// Hash code public override int GetHashCode() { + // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { - int hashCode = 41; + int hash = 41; + // Suitable nullity checks etc, of course :) if (this.Error != null) - hashCode = hashCode * 59 + this.Error.GetHashCode(); + hash = hash * 59 + this.Error.GetHashCode(); if (this.ErrorDescription != null) - hashCode = hashCode * 59 + this.ErrorDescription.GetHashCode(); - return hashCode; + hash = hash * 59 + this.ErrorDescription.GetHashCode(); + return hash; } } diff --git a/src/Genesys.Internal.Authentication/Model/JwtConvertResult.cs b/src/Genesys.Internal.Authentication/Model/JwtConvertResult.cs index 4a6ac04..74127cb 100644 --- a/src/Genesys.Internal.Authentication/Model/JwtConvertResult.cs +++ b/src/Genesys.Internal.Authentication/Model/JwtConvertResult.cs @@ -70,28 +70,30 @@ public string ToJson() /// /// Returns true if objects are equal /// - /// Object to be compared + /// Object to be compared /// Boolean - public override bool Equals(object input) + public override bool Equals(object obj) { - return this.Equals(input as JwtConvertResult); + // credit: http://stackoverflow.com/a/10454552/677735 + return this.Equals(obj as JwtConvertResult); } /// /// Returns true if JwtConvertResult instances are equal /// - /// Instance of JwtConvertResult to be compared + /// Instance of JwtConvertResult to be compared /// Boolean - public bool Equals(JwtConvertResult input) + public bool Equals(JwtConvertResult other) { - if (input == null) + // credit: http://stackoverflow.com/a/10454552/677735 + if (other == null) return false; return ( - this.JwtToken == input.JwtToken || - (this.JwtToken != null && - this.JwtToken.Equals(input.JwtToken)) + this.JwtToken == other.JwtToken || + this.JwtToken != null && + this.JwtToken.Equals(other.JwtToken) ); } @@ -101,12 +103,14 @@ public bool Equals(JwtConvertResult input) /// Hash code public override int GetHashCode() { + // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { - int hashCode = 41; + int hash = 41; + // Suitable nullity checks etc, of course :) if (this.JwtToken != null) - hashCode = hashCode * 59 + this.JwtToken.GetHashCode(); - return hashCode; + hash = hash * 59 + this.JwtToken.GetHashCode(); + return hash; } } diff --git a/src/Genesys.Internal.Authentication/Model/ResponseStatus.cs b/src/Genesys.Internal.Authentication/Model/ResponseStatus.cs index 625b362..637bc09 100644 --- a/src/Genesys.Internal.Authentication/Model/ResponseStatus.cs +++ b/src/Genesys.Internal.Authentication/Model/ResponseStatus.cs @@ -88,38 +88,40 @@ public string ToJson() /// /// Returns true if objects are equal /// - /// Object to be compared + /// Object to be compared /// Boolean - public override bool Equals(object input) + public override bool Equals(object obj) { - return this.Equals(input as ResponseStatus); + // credit: http://stackoverflow.com/a/10454552/677735 + return this.Equals(obj as ResponseStatus); } /// /// Returns true if ResponseStatus instances are equal /// - /// Instance of ResponseStatus to be compared + /// Instance of ResponseStatus to be compared /// Boolean - public bool Equals(ResponseStatus input) + public bool Equals(ResponseStatus other) { - if (input == null) + // credit: http://stackoverflow.com/a/10454552/677735 + if (other == null) return false; return ( - this.Code == input.Code || - (this.Code != null && - this.Code.Equals(input.Code)) + this.Code == other.Code || + this.Code != null && + this.Code.Equals(other.Code) ) && ( - this.Detail == input.Detail || - (this.Detail != null && - this.Detail.Equals(input.Detail)) + this.Detail == other.Detail || + this.Detail != null && + this.Detail.Equals(other.Detail) ) && ( - this.Message == input.Message || - (this.Message != null && - this.Message.Equals(input.Message)) + this.Message == other.Message || + this.Message != null && + this.Message.Equals(other.Message) ); } @@ -129,16 +131,18 @@ public bool Equals(ResponseStatus input) /// Hash code public override int GetHashCode() { + // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { - int hashCode = 41; + int hash = 41; + // Suitable nullity checks etc, of course :) if (this.Code != null) - hashCode = hashCode * 59 + this.Code.GetHashCode(); + hash = hash * 59 + this.Code.GetHashCode(); if (this.Detail != null) - hashCode = hashCode * 59 + this.Detail.GetHashCode(); + hash = hash * 59 + this.Detail.GetHashCode(); if (this.Message != null) - hashCode = hashCode * 59 + this.Message.GetHashCode(); - return hashCode; + hash = hash * 59 + this.Message.GetHashCode(); + return hash; } } diff --git a/src/Genesys.Internal.Authentication/Model/UserRole.cs b/src/Genesys.Internal.Authentication/Model/UserRole.cs index 5d2b52a..9692417 100644 --- a/src/Genesys.Internal.Authentication/Model/UserRole.cs +++ b/src/Genesys.Internal.Authentication/Model/UserRole.cs @@ -70,28 +70,30 @@ public string ToJson() /// /// Returns true if objects are equal /// - /// Object to be compared + /// Object to be compared /// Boolean - public override bool Equals(object input) + public override bool Equals(object obj) { - return this.Equals(input as UserRole); + // credit: http://stackoverflow.com/a/10454552/677735 + return this.Equals(obj as UserRole); } /// /// Returns true if UserRole instances are equal /// - /// Instance of UserRole to be compared + /// Instance of UserRole to be compared /// Boolean - public bool Equals(UserRole input) + public bool Equals(UserRole other) { - if (input == null) + // credit: http://stackoverflow.com/a/10454552/677735 + if (other == null) return false; return ( - this.Name == input.Name || - (this.Name != null && - this.Name.Equals(input.Name)) + this.Name == other.Name || + this.Name != null && + this.Name.Equals(other.Name) ); } @@ -101,12 +103,14 @@ public bool Equals(UserRole input) /// Hash code public override int GetHashCode() { + // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { - int hashCode = 41; + int hash = 41; + // Suitable nullity checks etc, of course :) if (this.Name != null) - hashCode = hashCode * 59 + this.Name.GetHashCode(); - return hashCode; + hash = hash * 59 + this.Name.GetHashCode(); + return hash; } } diff --git a/src/Genesys.Internal.Authentication/packages.config b/src/Genesys.Internal.Authentication/packages.config index 3caf34e..351ef13 100644 --- a/src/Genesys.Internal.Authentication/packages.config +++ b/src/Genesys.Internal.Authentication/packages.config @@ -2,5 +2,4 @@ -