| | | 1 | | /* |
| | | 2 | | * WeShare API |
| | | 3 | | * |
| | | 4 | | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) |
| | | 5 | | * |
| | | 6 | | * The version of the OpenAPI document: 1.0 |
| | | 7 | | * Generated by: https://github.com/openapitools/openapi-generator.git |
| | | 8 | | */ |
| | | 9 | | |
| | | 10 | | |
| | | 11 | | using System; |
| | | 12 | | using System.Collections.Concurrent; |
| | | 13 | | using System.Collections.Generic; |
| | | 14 | | using System.IO; |
| | | 15 | | using System.Linq; |
| | | 16 | | using System.Net; |
| | | 17 | | using System.Reflection; |
| | | 18 | | using System.Security.Cryptography.X509Certificates; |
| | | 19 | | using System.Text; |
| | | 20 | | using System.Net.Http; |
| | | 21 | | |
| | | 22 | | namespace Applications.WeShare.Swagger.Client |
| | | 23 | | { |
| | | 24 | | /// <summary> |
| | | 25 | | /// Represents a set of configuration settings |
| | | 26 | | /// </summary> |
| | | 27 | | public class Configuration : IReadableConfiguration |
| | | 28 | | { |
| | | 29 | | #region Constants |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Version of the package. |
| | | 33 | | /// </summary> |
| | | 34 | | /// <value>Version of the package.</value> |
| | | 35 | | public const string Version = "1.0.0"; |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Identifier for ISO 8601 DateTime Format |
| | | 39 | | /// </summary> |
| | | 40 | | /// <remarks>See https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8 for more information. |
| | | 41 | | // ReSharper disable once InconsistentNaming |
| | | 42 | | public const string ISO8601_DATETIME_FORMAT = "o"; |
| | | 43 | | |
| | | 44 | | #endregion Constants |
| | | 45 | | |
| | | 46 | | #region Static Members |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Default creation of exceptions for a given method name and response object |
| | | 50 | | /// </summary> |
| | 1 | 51 | | public static readonly ExceptionFactory DefaultExceptionFactory = (methodName, response) => |
| | 34 | 52 | | { |
| | 34 | 53 | | var status = (int)response.StatusCode; |
| | 34 | 54 | | if (status >= 400) |
| | 21 | 55 | | { |
| | 21 | 56 | | return new ApiException(status, |
| | 21 | 57 | | string.Format("Error calling {0}: {1}", methodName, response.RawContent), |
| | 21 | 58 | | response.RawContent, response.Headers); |
| | 1 | 59 | | } |
| | 13 | 60 | | return null; |
| | 35 | 61 | | }; |
| | | 62 | | |
| | | 63 | | #endregion Static Members |
| | | 64 | | |
| | | 65 | | #region Private Members |
| | | 66 | | |
| | | 67 | | /// <summary> |
| | | 68 | | /// Defines the base path of the target API server. |
| | | 69 | | /// Example: http://localhost:3000/v1/ |
| | | 70 | | /// </summary> |
| | | 71 | | private string _basePath; |
| | | 72 | | |
| | | 73 | | /// <summary> |
| | | 74 | | /// Gets or sets the API key based on the authentication name. |
| | | 75 | | /// This is the key and value comprising the "secret" for accessing an API. |
| | | 76 | | /// </summary> |
| | | 77 | | /// <value>The API key.</value> |
| | | 78 | | private IDictionary<string, string> _apiKey; |
| | | 79 | | |
| | | 80 | | /// <summary> |
| | | 81 | | /// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name. |
| | | 82 | | /// </summary> |
| | | 83 | | /// <value>The prefix of the API key.</value> |
| | | 84 | | private IDictionary<string, string> _apiKeyPrefix; |
| | | 85 | | |
| | 15 | 86 | | private string _dateTimeFormat = ISO8601_DATETIME_FORMAT; |
| | 15 | 87 | | private string _tempFolderPath = Path.GetTempPath(); |
| | | 88 | | |
| | | 89 | | /// <summary> |
| | | 90 | | /// Gets or sets the servers defined in the OpenAPI spec. |
| | | 91 | | /// </summary> |
| | | 92 | | /// <value>The servers</value> |
| | | 93 | | private IList<IReadOnlyDictionary<string, object>> _servers; |
| | | 94 | | |
| | | 95 | | /// <summary> |
| | | 96 | | /// Gets or sets the operation servers defined in the OpenAPI spec. |
| | | 97 | | /// </summary> |
| | | 98 | | /// <value>The operation servers</value> |
| | | 99 | | private IReadOnlyDictionary<string, List<IReadOnlyDictionary<string, object>>> _operationServers; |
| | | 100 | | |
| | | 101 | | #endregion Private Members |
| | | 102 | | |
| | | 103 | | #region Constructors |
| | | 104 | | |
| | | 105 | | /// <summary> |
| | | 106 | | /// Initializes a new instance of the <see cref="Configuration" /> class |
| | | 107 | | /// </summary> |
| | | 108 | | [System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")] |
| | 15 | 109 | | public Configuration() |
| | 15 | 110 | | { |
| | 15 | 111 | | Proxy = null; |
| | 15 | 112 | | UserAgent = WebUtility.UrlEncode("OpenAPI-Generator/1.0.0/csharp"); |
| | 15 | 113 | | BasePath = "http://localhost"; |
| | 15 | 114 | | DefaultHeaders = new ConcurrentDictionary<string, string>(); |
| | 15 | 115 | | ApiKey = new ConcurrentDictionary<string, string>(); |
| | 15 | 116 | | ApiKeyPrefix = new ConcurrentDictionary<string, string>(); |
| | 15 | 117 | | Servers = new List<IReadOnlyDictionary<string, object>>() |
| | 15 | 118 | | { |
| | 15 | 119 | | { |
| | 15 | 120 | | new Dictionary<string, object> { |
| | 15 | 121 | | {"url", ""}, |
| | 15 | 122 | | {"description", "No description provided"}, |
| | 15 | 123 | | } |
| | 15 | 124 | | } |
| | 15 | 125 | | }; |
| | 15 | 126 | | OperationServers = new Dictionary<string, List<IReadOnlyDictionary<string, object>>>() |
| | 15 | 127 | | { |
| | 15 | 128 | | }; |
| | | 129 | | |
| | | 130 | | // Setting Timeout has side effects (forces ApiClient creation). |
| | 15 | 131 | | Timeout = 100000; |
| | 15 | 132 | | } |
| | | 133 | | |
| | | 134 | | /// <summary> |
| | | 135 | | /// Initializes a new instance of the <see cref="Configuration" /> class |
| | | 136 | | /// </summary> |
| | | 137 | | [System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")] |
| | | 138 | | public Configuration( |
| | | 139 | | IDictionary<string, string> defaultHeaders, |
| | | 140 | | IDictionary<string, string> apiKey, |
| | | 141 | | IDictionary<string, string> apiKeyPrefix, |
| | 0 | 142 | | string basePath = "http://localhost") : this() |
| | 0 | 143 | | { |
| | 0 | 144 | | if (string.IsNullOrWhiteSpace(basePath)) |
| | 0 | 145 | | throw new ArgumentException("The provided basePath is invalid.", "basePath"); |
| | 0 | 146 | | if (defaultHeaders == null) |
| | 0 | 147 | | throw new ArgumentNullException("defaultHeaders"); |
| | 0 | 148 | | if (apiKey == null) |
| | 0 | 149 | | throw new ArgumentNullException("apiKey"); |
| | 0 | 150 | | if (apiKeyPrefix == null) |
| | 0 | 151 | | throw new ArgumentNullException("apiKeyPrefix"); |
| | | 152 | | |
| | 0 | 153 | | BasePath = basePath; |
| | | 154 | | |
| | 0 | 155 | | foreach (var keyValuePair in defaultHeaders) |
| | 0 | 156 | | { |
| | 0 | 157 | | DefaultHeaders.Add(keyValuePair); |
| | 0 | 158 | | } |
| | | 159 | | |
| | 0 | 160 | | foreach (var keyValuePair in apiKey) |
| | 0 | 161 | | { |
| | 0 | 162 | | ApiKey.Add(keyValuePair); |
| | 0 | 163 | | } |
| | | 164 | | |
| | 0 | 165 | | foreach (var keyValuePair in apiKeyPrefix) |
| | 0 | 166 | | { |
| | 0 | 167 | | ApiKeyPrefix.Add(keyValuePair); |
| | 0 | 168 | | } |
| | 0 | 169 | | } |
| | | 170 | | |
| | | 171 | | #endregion Constructors |
| | | 172 | | |
| | | 173 | | #region Properties |
| | | 174 | | |
| | | 175 | | /// <summary> |
| | | 176 | | /// Gets or sets the base path for API access. |
| | | 177 | | /// </summary> |
| | | 178 | | public virtual string BasePath { |
| | 63 | 179 | | get { return _basePath; } |
| | 87 | 180 | | set { _basePath = value; } |
| | | 181 | | } |
| | | 182 | | |
| | | 183 | | /// <summary> |
| | | 184 | | /// Gets or sets the default header. |
| | | 185 | | /// </summary> |
| | | 186 | | [Obsolete("Use DefaultHeaders instead.")] |
| | | 187 | | public virtual IDictionary<string, string> DefaultHeader |
| | | 188 | | { |
| | | 189 | | get |
| | 0 | 190 | | { |
| | 0 | 191 | | return DefaultHeaders; |
| | 0 | 192 | | } |
| | | 193 | | set |
| | 0 | 194 | | { |
| | 0 | 195 | | DefaultHeaders = value; |
| | 0 | 196 | | } |
| | | 197 | | } |
| | | 198 | | |
| | | 199 | | /// <summary> |
| | | 200 | | /// Gets or sets the default headers. |
| | | 201 | | /// </summary> |
| | 104 | 202 | | public virtual IDictionary<string, string> DefaultHeaders { get; set; } |
| | | 203 | | |
| | | 204 | | /// <summary> |
| | | 205 | | /// Gets or sets the HTTP timeout (milliseconds) of ApiClient. Default to 100000 milliseconds. |
| | | 206 | | /// </summary> |
| | 63 | 207 | | public virtual int Timeout { get; set; } |
| | | 208 | | |
| | | 209 | | /// <summary> |
| | | 210 | | /// Gets or sets the proxy |
| | | 211 | | /// </summary> |
| | | 212 | | /// <value>Proxy.</value> |
| | 70 | 213 | | public virtual WebProxy Proxy { get; set; } |
| | | 214 | | |
| | | 215 | | /// <summary> |
| | | 216 | | /// Gets or sets the HTTP user agent. |
| | | 217 | | /// </summary> |
| | | 218 | | /// <value>Http user agent.</value> |
| | 63 | 219 | | public virtual string UserAgent { get; set; } |
| | | 220 | | |
| | | 221 | | /// <summary> |
| | | 222 | | /// Gets or sets the username (HTTP basic authentication). |
| | | 223 | | /// </summary> |
| | | 224 | | /// <value>The username.</value> |
| | 21 | 225 | | public virtual string Username { get; set; } |
| | | 226 | | |
| | | 227 | | /// <summary> |
| | | 228 | | /// Gets or sets the password (HTTP basic authentication). |
| | | 229 | | /// </summary> |
| | | 230 | | /// <value>The password.</value> |
| | 21 | 231 | | public virtual string Password { get; set; } |
| | | 232 | | |
| | | 233 | | /// <summary> |
| | | 234 | | /// Gets the API key with prefix. |
| | | 235 | | /// </summary> |
| | | 236 | | /// <param name="apiKeyIdentifier">API key identifier (authentication scheme).</param> |
| | | 237 | | /// <returns>API key with prefix.</returns> |
| | | 238 | | public string GetApiKeyWithPrefix(string apiKeyIdentifier) |
| | 0 | 239 | | { |
| | | 240 | | string apiKeyValue; |
| | 0 | 241 | | ApiKey.TryGetValue(apiKeyIdentifier, out apiKeyValue); |
| | | 242 | | string apiKeyPrefix; |
| | 0 | 243 | | if (ApiKeyPrefix.TryGetValue(apiKeyIdentifier, out apiKeyPrefix)) |
| | 0 | 244 | | { |
| | 0 | 245 | | return apiKeyPrefix + " " + apiKeyValue; |
| | | 246 | | } |
| | | 247 | | |
| | 0 | 248 | | return apiKeyValue; |
| | 0 | 249 | | } |
| | | 250 | | |
| | | 251 | | /// <summary> |
| | | 252 | | /// Gets or sets certificate collection to be sent with requests. |
| | | 253 | | /// </summary> |
| | | 254 | | /// <value>X509 Certificate collection.</value> |
| | 55 | 255 | | public X509CertificateCollection ClientCertificates { get; set; } |
| | | 256 | | |
| | | 257 | | /// <summary> |
| | | 258 | | /// Gets or sets the access token for OAuth2 authentication. |
| | | 259 | | /// |
| | | 260 | | /// This helper property simplifies code generation. |
| | | 261 | | /// </summary> |
| | | 262 | | /// <value>The access token.</value> |
| | 21 | 263 | | public virtual string AccessToken { get; set; } |
| | | 264 | | |
| | | 265 | | /// <summary> |
| | | 266 | | /// Gets or sets the temporary folder path to store the files downloaded from the server. |
| | | 267 | | /// </summary> |
| | | 268 | | /// <value>Folder path.</value> |
| | | 269 | | public virtual string TempFolderPath |
| | | 270 | | { |
| | 21 | 271 | | get { return _tempFolderPath; } |
| | | 272 | | |
| | | 273 | | set |
| | 7 | 274 | | { |
| | 7 | 275 | | if (string.IsNullOrEmpty(value)) |
| | 0 | 276 | | { |
| | 0 | 277 | | _tempFolderPath = Path.GetTempPath(); |
| | 0 | 278 | | return; |
| | | 279 | | } |
| | | 280 | | |
| | | 281 | | // create the directory if it does not exist |
| | 7 | 282 | | if (!Directory.Exists(value)) |
| | 0 | 283 | | { |
| | 0 | 284 | | Directory.CreateDirectory(value); |
| | 0 | 285 | | } |
| | | 286 | | |
| | | 287 | | // check if the path contains directory separator at the end |
| | 7 | 288 | | if (value[value.Length - 1] == Path.DirectorySeparatorChar) |
| | 7 | 289 | | { |
| | 7 | 290 | | _tempFolderPath = value; |
| | 7 | 291 | | } |
| | | 292 | | else |
| | 0 | 293 | | { |
| | 0 | 294 | | _tempFolderPath = value + Path.DirectorySeparatorChar; |
| | 0 | 295 | | } |
| | 7 | 296 | | } |
| | | 297 | | } |
| | | 298 | | |
| | | 299 | | /// <summary> |
| | | 300 | | /// Gets or sets the date time format used when serializing in the ApiClient |
| | | 301 | | /// By default, it's set to ISO 8601 - "o", for others see: |
| | | 302 | | /// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx |
| | | 303 | | /// and https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx |
| | | 304 | | /// No validation is done to ensure that the string you're providing is valid |
| | | 305 | | /// </summary> |
| | | 306 | | /// <value>The DateTimeFormat string</value> |
| | | 307 | | public virtual string DateTimeFormat |
| | | 308 | | { |
| | 21 | 309 | | get { return _dateTimeFormat; } |
| | | 310 | | set |
| | 7 | 311 | | { |
| | 7 | 312 | | if (string.IsNullOrEmpty(value)) |
| | 0 | 313 | | { |
| | | 314 | | // Never allow a blank or null string, go back to the default |
| | 0 | 315 | | _dateTimeFormat = ISO8601_DATETIME_FORMAT; |
| | 0 | 316 | | return; |
| | | 317 | | } |
| | | 318 | | |
| | | 319 | | // Caution, no validation when you choose date time format other than ISO 8601 |
| | | 320 | | // Take a look at the above links |
| | 7 | 321 | | _dateTimeFormat = value; |
| | 7 | 322 | | } |
| | | 323 | | } |
| | | 324 | | |
| | | 325 | | /// <summary> |
| | | 326 | | /// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name. |
| | | 327 | | /// |
| | | 328 | | /// Whatever you set here will be prepended to the value defined in AddApiKey. |
| | | 329 | | /// |
| | | 330 | | /// An example invocation here might be: |
| | | 331 | | /// <example> |
| | | 332 | | /// ApiKeyPrefix["Authorization"] = "Bearer"; |
| | | 333 | | /// </example> |
| | | 334 | | /// … where ApiKey["Authorization"] would then be used to set the value of your bearer token. |
| | | 335 | | /// |
| | | 336 | | /// <remarks> |
| | | 337 | | /// OAuth2 workflows should set tokens via AccessToken. |
| | | 338 | | /// </remarks> |
| | | 339 | | /// </summary> |
| | | 340 | | /// <value>The prefix of the API key.</value> |
| | | 341 | | public virtual IDictionary<string, string> ApiKeyPrefix |
| | | 342 | | { |
| | 42 | 343 | | get { return _apiKeyPrefix; } |
| | | 344 | | set |
| | 22 | 345 | | { |
| | 22 | 346 | | if (value == null) |
| | 0 | 347 | | { |
| | 0 | 348 | | throw new InvalidOperationException("ApiKeyPrefix collection may not be null."); |
| | | 349 | | } |
| | 22 | 350 | | _apiKeyPrefix = value; |
| | 22 | 351 | | } |
| | | 352 | | } |
| | | 353 | | |
| | | 354 | | /// <summary> |
| | | 355 | | /// Gets or sets the API key based on the authentication name. |
| | | 356 | | /// </summary> |
| | | 357 | | /// <value>The API key.</value> |
| | | 358 | | public virtual IDictionary<string, string> ApiKey |
| | | 359 | | { |
| | 42 | 360 | | get { return _apiKey; } |
| | | 361 | | set |
| | 22 | 362 | | { |
| | 22 | 363 | | if (value == null) |
| | 0 | 364 | | { |
| | 0 | 365 | | throw new InvalidOperationException("ApiKey collection may not be null."); |
| | | 366 | | } |
| | 22 | 367 | | _apiKey = value; |
| | 22 | 368 | | } |
| | | 369 | | } |
| | | 370 | | |
| | | 371 | | /// <summary> |
| | | 372 | | /// Gets or sets the servers. |
| | | 373 | | /// </summary> |
| | | 374 | | /// <value>The servers.</value> |
| | | 375 | | public virtual IList<IReadOnlyDictionary<string, object>> Servers |
| | | 376 | | { |
| | 0 | 377 | | get { return _servers; } |
| | | 378 | | set |
| | 15 | 379 | | { |
| | 15 | 380 | | if (value == null) |
| | 0 | 381 | | { |
| | 0 | 382 | | throw new InvalidOperationException("Servers may not be null."); |
| | | 383 | | } |
| | 15 | 384 | | _servers = value; |
| | 15 | 385 | | } |
| | | 386 | | } |
| | | 387 | | |
| | | 388 | | /// <summary> |
| | | 389 | | /// Gets or sets the operation servers. |
| | | 390 | | /// </summary> |
| | | 391 | | /// <value>The operation servers.</value> |
| | | 392 | | public virtual IReadOnlyDictionary<string, List<IReadOnlyDictionary<string, object>>> OperationServers |
| | | 393 | | { |
| | 102 | 394 | | get { return _operationServers; } |
| | | 395 | | set |
| | 15 | 396 | | { |
| | 15 | 397 | | if (value == null) |
| | 0 | 398 | | { |
| | 0 | 399 | | throw new InvalidOperationException("Operation servers may not be null."); |
| | | 400 | | } |
| | 15 | 401 | | _operationServers = value; |
| | 15 | 402 | | } |
| | | 403 | | } |
| | | 404 | | |
| | | 405 | | /// <summary> |
| | | 406 | | /// Returns URL based on server settings without providing values |
| | | 407 | | /// for the variables |
| | | 408 | | /// </summary> |
| | | 409 | | /// <param name="index">Array index of the server settings.</param> |
| | | 410 | | /// <return>The server URL.</return> |
| | | 411 | | public string GetServerUrl(int index) |
| | 0 | 412 | | { |
| | 0 | 413 | | return GetServerUrl(Servers, index, null); |
| | 0 | 414 | | } |
| | | 415 | | |
| | | 416 | | /// <summary> |
| | | 417 | | /// Returns URL based on server settings. |
| | | 418 | | /// </summary> |
| | | 419 | | /// <param name="index">Array index of the server settings.</param> |
| | | 420 | | /// <param name="inputVariables">Dictionary of the variables and the corresponding values.</param> |
| | | 421 | | /// <return>The server URL.</return> |
| | | 422 | | public string GetServerUrl(int index, Dictionary<string, string> inputVariables) |
| | 0 | 423 | | { |
| | 0 | 424 | | return GetServerUrl(Servers, index, inputVariables); |
| | 0 | 425 | | } |
| | | 426 | | |
| | | 427 | | /// <summary> |
| | | 428 | | /// Returns URL based on operation server settings. |
| | | 429 | | /// </summary> |
| | | 430 | | /// <param name="operation">Operation associated with the request path.</param> |
| | | 431 | | /// <param name="index">Array index of the server settings.</param> |
| | | 432 | | /// <return>The operation server URL.</return> |
| | | 433 | | public string GetOperationServerUrl(string operation, int index) |
| | 34 | 434 | | { |
| | 34 | 435 | | return GetOperationServerUrl(operation, index, null); |
| | 34 | 436 | | } |
| | | 437 | | |
| | | 438 | | /// <summary> |
| | | 439 | | /// Returns URL based on operation server settings. |
| | | 440 | | /// </summary> |
| | | 441 | | /// <param name="operation">Operation associated with the request path.</param> |
| | | 442 | | /// <param name="index">Array index of the server settings.</param> |
| | | 443 | | /// <param name="inputVariables">Dictionary of the variables and the corresponding values.</param> |
| | | 444 | | /// <return>The operation server URL.</return> |
| | | 445 | | public string GetOperationServerUrl(string operation, int index, Dictionary<string, string> inputVariables) |
| | 34 | 446 | | { |
| | 34 | 447 | | if (OperationServers.TryGetValue(operation, out var operationServer)) |
| | 0 | 448 | | { |
| | 0 | 449 | | return GetServerUrl(operationServer, index, inputVariables); |
| | | 450 | | } |
| | | 451 | | |
| | 34 | 452 | | return null; |
| | 34 | 453 | | } |
| | | 454 | | |
| | | 455 | | /// <summary> |
| | | 456 | | /// Returns URL based on server settings. |
| | | 457 | | /// </summary> |
| | | 458 | | /// <param name="servers">Dictionary of server settings.</param> |
| | | 459 | | /// <param name="index">Array index of the server settings.</param> |
| | | 460 | | /// <param name="inputVariables">Dictionary of the variables and the corresponding values.</param> |
| | | 461 | | /// <return>The server URL.</return> |
| | | 462 | | private string GetServerUrl(IList<IReadOnlyDictionary<string, object>> servers, int index, Dictionary<string, st |
| | 0 | 463 | | { |
| | 0 | 464 | | if (index < 0 || index >= servers.Count) |
| | 0 | 465 | | { |
| | 0 | 466 | | throw new InvalidOperationException($"Invalid index {index} when selecting the server. Must be less than |
| | | 467 | | } |
| | | 468 | | |
| | 0 | 469 | | if (inputVariables == null) |
| | 0 | 470 | | { |
| | 0 | 471 | | inputVariables = new Dictionary<string, string>(); |
| | 0 | 472 | | } |
| | | 473 | | |
| | 0 | 474 | | IReadOnlyDictionary<string, object> server = servers[index]; |
| | 0 | 475 | | string url = (string)server["url"]; |
| | | 476 | | |
| | 0 | 477 | | if (server.ContainsKey("variables")) |
| | 0 | 478 | | { |
| | | 479 | | // go through each variable and assign a value |
| | 0 | 480 | | foreach (KeyValuePair<string, object> variable in (IReadOnlyDictionary<string, object>)server["variables |
| | 0 | 481 | | { |
| | | 482 | | |
| | 0 | 483 | | IReadOnlyDictionary<string, object> serverVariables = (IReadOnlyDictionary<string, object>)(variable |
| | | 484 | | |
| | 0 | 485 | | if (inputVariables.ContainsKey(variable.Key)) |
| | 0 | 486 | | { |
| | 0 | 487 | | if (((List<string>)serverVariables["enum_values"]).Contains(inputVariables[variable.Key])) |
| | 0 | 488 | | { |
| | 0 | 489 | | url = url.Replace("{" + variable.Key + "}", inputVariables[variable.Key]); |
| | 0 | 490 | | } |
| | | 491 | | else |
| | 0 | 492 | | { |
| | 0 | 493 | | throw new InvalidOperationException($"The variable `{variable.Key}` in the server URL has in |
| | | 494 | | } |
| | 0 | 495 | | } |
| | | 496 | | else |
| | 0 | 497 | | { |
| | | 498 | | // use default value |
| | 0 | 499 | | url = url.Replace("{" + variable.Key + "}", (string)serverVariables["default_value"]); |
| | 0 | 500 | | } |
| | 0 | 501 | | } |
| | 0 | 502 | | } |
| | | 503 | | |
| | 0 | 504 | | return url; |
| | 0 | 505 | | } |
| | | 506 | | |
| | | 507 | | #endregion Properties |
| | | 508 | | |
| | | 509 | | #region Methods |
| | | 510 | | |
| | | 511 | | /// <summary> |
| | | 512 | | /// Returns a string with essential information for debugging. |
| | | 513 | | /// </summary> |
| | | 514 | | public static string ToDebugReport() |
| | 0 | 515 | | { |
| | 0 | 516 | | string report = "C# SDK (Applications.WeShare.Swagger) Debug Report:\n"; |
| | 0 | 517 | | report += " OS: " + System.Environment.OSVersion + "\n"; |
| | 0 | 518 | | report += " .NET Framework Version: " + System.Environment.Version + "\n"; |
| | 0 | 519 | | report += " Version of the API: 1.0\n"; |
| | 0 | 520 | | report += " SDK Package Version: 1.0.0\n"; |
| | | 521 | | |
| | 0 | 522 | | return report; |
| | 0 | 523 | | } |
| | | 524 | | |
| | | 525 | | /// <summary> |
| | | 526 | | /// Add Api Key Header. |
| | | 527 | | /// </summary> |
| | | 528 | | /// <param name="key">Api Key name.</param> |
| | | 529 | | /// <param name="value">Api Key value.</param> |
| | | 530 | | /// <returns></returns> |
| | | 531 | | public void AddApiKey(string key, string value) |
| | 0 | 532 | | { |
| | 0 | 533 | | ApiKey[key] = value; |
| | 0 | 534 | | } |
| | | 535 | | |
| | | 536 | | /// <summary> |
| | | 537 | | /// Sets the API key prefix. |
| | | 538 | | /// </summary> |
| | | 539 | | /// <param name="key">Api Key name.</param> |
| | | 540 | | /// <param name="value">Api Key value.</param> |
| | | 541 | | public void AddApiKeyPrefix(string key, string value) |
| | 0 | 542 | | { |
| | 0 | 543 | | ApiKeyPrefix[key] = value; |
| | 0 | 544 | | } |
| | | 545 | | |
| | | 546 | | #endregion Methods |
| | | 547 | | |
| | | 548 | | #region Static Members |
| | | 549 | | /// <summary> |
| | | 550 | | /// Merge configurations. |
| | | 551 | | /// </summary> |
| | | 552 | | /// <param name="first">First configuration.</param> |
| | | 553 | | /// <param name="second">Second configuration.</param> |
| | | 554 | | /// <return>Merged configuration.</return> |
| | | 555 | | public static IReadableConfiguration MergeConfigurations(IReadableConfiguration first, IReadableConfiguration se |
| | 7 | 556 | | { |
| | 7 | 557 | | if (second == null) return first ?? GlobalConfiguration.Instance; |
| | | 558 | | |
| | 7 | 559 | | Dictionary<string, string> apiKey = first.ApiKey.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); |
| | 7 | 560 | | Dictionary<string, string> apiKeyPrefix = first.ApiKeyPrefix.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); |
| | 7 | 561 | | Dictionary<string, string> defaultHeaders = first.DefaultHeaders.ToDictionary(kvp => kvp.Key, kvp => kvp.Val |
| | | 562 | | |
| | 21 | 563 | | foreach (var kvp in second.ApiKey) apiKey[kvp.Key] = kvp.Value; |
| | 21 | 564 | | foreach (var kvp in second.ApiKeyPrefix) apiKeyPrefix[kvp.Key] = kvp.Value; |
| | 21 | 565 | | foreach (var kvp in second.DefaultHeaders) defaultHeaders[kvp.Key] = kvp.Value; |
| | | 566 | | |
| | 7 | 567 | | var config = new Configuration |
| | 7 | 568 | | { |
| | 7 | 569 | | ApiKey = apiKey, |
| | 7 | 570 | | ApiKeyPrefix = apiKeyPrefix, |
| | 7 | 571 | | DefaultHeaders = defaultHeaders, |
| | 7 | 572 | | BasePath = second.BasePath ?? first.BasePath, |
| | 7 | 573 | | Timeout = second.Timeout, |
| | 7 | 574 | | Proxy = second.Proxy ?? first.Proxy, |
| | 7 | 575 | | UserAgent = second.UserAgent ?? first.UserAgent, |
| | 7 | 576 | | Username = second.Username ?? first.Username, |
| | 7 | 577 | | Password = second.Password ?? first.Password, |
| | 7 | 578 | | AccessToken = second.AccessToken ?? first.AccessToken, |
| | 7 | 579 | | TempFolderPath = second.TempFolderPath ?? first.TempFolderPath, |
| | 7 | 580 | | DateTimeFormat = second.DateTimeFormat ?? first.DateTimeFormat, |
| | 7 | 581 | | ClientCertificates = second.ClientCertificates ?? first.ClientCertificates, |
| | 7 | 582 | | }; |
| | 7 | 583 | | return config; |
| | 7 | 584 | | } |
| | | 585 | | #endregion Static Members |
| | | 586 | | } |
| | | 587 | | } |