Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[csharp-netcore] Add DefaultHeaders in favor of DefaultHeader
  • Loading branch information
Mario De Schaepmeester committed Aug 5, 2019
commit a4edebc1260d56d756ab62a310d830efd6080531
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ namespace {{packageName}}.Client
}
}

if (configuration.DefaultHeader != null)
if (configuration.DefaultHeaders != null)
{
foreach (var headerParam in configuration.DefaultHeader)
foreach (var headerParam in configuration.DefaultHeaders)
{
request.AddHeader(headerParam.Key, headerParam.Value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace {{packageName}}.Client
#endregion Constants

#region Static Members

/// <summary>
/// Default creation of exceptions for a given method name and response object
/// </summary>
Expand Down Expand Up @@ -65,7 +65,7 @@ namespace {{packageName}}.Client
/// Example: http://localhost:3000/v1/
/// </summary>
private String _basePath;

/// <summary>
/// Gets or sets the API key based on the authentication name.
/// This is the key and value comprising the "secret" for acessing an API.
Expand Down Expand Up @@ -94,7 +94,7 @@ namespace {{packageName}}.Client
{
UserAgent = "{{#httpUserAgent}}{{.}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{packageVersion}}/csharp{{/httpUserAgent}}";
BasePath = "{{{basePath}}}";
DefaultHeader = new {{^net35}}Concurrent{{/net35}}Dictionary<string, string>();
DefaultHeaders = new {{^net35}}Concurrent{{/net35}}Dictionary<string, string>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mario-d-s I suggest we keep DefaultHeader as switching to DefaultHeaders will make this PR a breaking changes (without fallback), which means we will need to target this change to 5.0.x branch instead (scheduled to be released next year May)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a matter of fact I do keep the DefaultHeader around and loop it through the new DefaultHeaders (both get and set), but marked it as obsolete (see). I subsequently adjusted the rest of the files from using the obsolete property to the new one.

That is not to say I might not have missed a place where this is a breaking change, in that case please let me know but it should be safe AFAIK.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go with what you've and see if the community (users) spot anything we missed.

ApiKey = new {{^net35}}Concurrent{{/net35}}Dictionary<string, string>();
ApiKeyPrefix = new {{^net35}}Concurrent{{/net35}}Dictionary<string, string>();

Expand All @@ -107,25 +107,25 @@ namespace {{packageName}}.Client
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")]
public Configuration(
IDictionary<string, string> defaultHeader,
IDictionary<string, string> defaultHeaders,
IDictionary<string, string> apiKey,
IDictionary<string, string> apiKeyPrefix,
string basePath = "{{{basePath}}}") : this()
{
if (string.{{^net35}}IsNullOrWhiteSpace{{/net35}}{{#net35}}IsNullOrEmpty{{/net35}}(basePath))
throw new ArgumentException("The provided basePath is invalid.", "basePath");
if (defaultHeader == null)
throw new ArgumentNullException("defaultHeader");
if (defaultHeaders == null)
throw new ArgumentNullException("defaultHeaders");
if (apiKey == null)
throw new ArgumentNullException("apiKey");
if (apiKeyPrefix == null)
throw new ArgumentNullException("apiKeyPrefix");

BasePath = basePath;

foreach (var keyValuePair in defaultHeader)
foreach (var keyValuePair in defaultHeaders)
{
DefaultHeader.Add(keyValuePair);
DefaultHeaders.Add(keyValuePair);
}

foreach (var keyValuePair in apiKey)
Expand Down Expand Up @@ -156,7 +156,23 @@ namespace {{packageName}}.Client
/// <summary>
/// Gets or sets the default header.
/// </summary>
public virtual IDictionary<string, string> DefaultHeader { get; set; }
[Obsolete("Use DefaultHeaders instead.")]
public virtual IDictionary<string, string> DefaultHeader
{
get
{
return DefaultHeaders;
}
set
{
DefaultHeaders = value;
}
}

/// <summary>
/// Gets or sets the default headers.
/// </summary>
public virtual IDictionary<string, string> DefaultHeaders { get; set; }

/// <summary>
/// Gets or sets the HTTP timeout (milliseconds) of ApiClient. Default to 100000 milliseconds.
Expand Down Expand Up @@ -374,17 +390,17 @@ namespace {{packageName}}.Client

Dictionary<string, string> apiKey = first.ApiKey.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
Dictionary<string, string> apiKeyPrefix = first.ApiKeyPrefix.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
Dictionary<string, string> defaultHeader = first.DefaultHeader.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
Dictionary<string, string> defaultHeaders = first.DefaultHeaders.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

foreach (var kvp in second.ApiKey) apiKey[kvp.Key] = kvp.Value;
foreach (var kvp in second.ApiKeyPrefix) apiKeyPrefix[kvp.Key] = kvp.Value;
foreach (var kvp in second.DefaultHeader) defaultHeader[kvp.Key] = kvp.Value;
foreach (var kvp in second.DefaultHeaders) defaultHeaders[kvp.Key] = kvp.Value;

var config = new Configuration
{
ApiKey = apiKey,
ApiKeyPrefix = apiKeyPrefix,
DefaultHeader = defaultHeader,
DefaultHeader = defaultHeaders,
BasePath = second.BasePath ?? first.BasePath,
Timeout = second.Timeout,
UserAgent = second.UserAgent ?? first.UserAgent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{>partial_header}}

using System;
using System.Collections.Generic;

namespace {{packageName}}.Client
Expand Down Expand Up @@ -43,8 +44,15 @@ namespace {{packageName}}.Client
/// Gets the default header.
/// </summary>
/// <value>Default header.</value>
[Obsolete("Use DefaultHeaders instead.")]
IDictionary<string, string> DefaultHeader { get; }

/// <summary>
/// Gets the default headers.
/// </summary>
/// <value>Default headers.</value>
IDictionary<string, string> DefaultHeaders { get; }

/// <summary>
/// Gets the temp folder path.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ private RestRequest newRequest(
}
}

if (configuration.DefaultHeader != null)
if (configuration.DefaultHeaders != null)
{
foreach (var headerParam in configuration.DefaultHeader)
foreach (var headerParam in configuration.DefaultHeaders)
{
request.AddHeader(headerParam.Key, headerParam.Value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class Configuration : IReadableConfiguration
#endregion Constants

#region Static Members

/// <summary>
/// Default creation of exceptions for a given method name and response object
/// </summary>
Expand All @@ -68,7 +68,7 @@ public class Configuration : IReadableConfiguration
/// Example: http://localhost:3000/v1/
/// </summary>
private String _basePath;

/// <summary>
/// Gets or sets the API key based on the authentication name.
/// This is the key and value comprising the "secret" for acessing an API.
Expand Down Expand Up @@ -97,7 +97,7 @@ public Configuration()
{
UserAgent = "OpenAPI-Generator/1.0.0/csharp";
BasePath = "http://petstore.swagger.io:80/v2";
DefaultHeader = new ConcurrentDictionary<string, string>();
DefaultHeaders = new ConcurrentDictionary<string, string>();
ApiKey = new ConcurrentDictionary<string, string>();
ApiKeyPrefix = new ConcurrentDictionary<string, string>();

Expand All @@ -110,25 +110,25 @@ public Configuration()
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")]
public Configuration(
IDictionary<string, string> defaultHeader,
IDictionary<string, string> defaultHeaders,
IDictionary<string, string> apiKey,
IDictionary<string, string> apiKeyPrefix,
string basePath = "http://petstore.swagger.io:80/v2") : this()
{
if (string.IsNullOrWhiteSpace(basePath))
throw new ArgumentException("The provided basePath is invalid.", "basePath");
if (defaultHeader == null)
throw new ArgumentNullException("defaultHeader");
if (defaultHeaders == null)
throw new ArgumentNullException("defaultHeaders");
if (apiKey == null)
throw new ArgumentNullException("apiKey");
if (apiKeyPrefix == null)
throw new ArgumentNullException("apiKeyPrefix");

BasePath = basePath;

foreach (var keyValuePair in defaultHeader)
foreach (var keyValuePair in defaultHeaders)
{
DefaultHeader.Add(keyValuePair);
DefaultHeaders.Add(keyValuePair);
}

foreach (var keyValuePair in apiKey)
Expand Down Expand Up @@ -159,7 +159,23 @@ public virtual string BasePath {
/// <summary>
/// Gets or sets the default header.
/// </summary>
public virtual IDictionary<string, string> DefaultHeader { get; set; }
[Obsolete("Use DefaultHeaders instead.")]
public virtual IDictionary<string, string> DefaultHeader
{
get
{
return DefaultHeaders;
}
set
{
DefaultHeaders = value;
}
}

/// <summary>
/// Gets or sets the default headers.
/// </summary>
public virtual IDictionary<string, string> DefaultHeaders { get; set; }

/// <summary>
/// Gets or sets the HTTP timeout (milliseconds) of ApiClient. Default to 100000 milliseconds.
Expand Down Expand Up @@ -369,17 +385,17 @@ public static IReadableConfiguration MergeConfigurations(IReadableConfiguration

Dictionary<string, string> apiKey = first.ApiKey.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
Dictionary<string, string> apiKeyPrefix = first.ApiKeyPrefix.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
Dictionary<string, string> defaultHeader = first.DefaultHeader.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
Dictionary<string, string> defaultHeaders = first.DefaultHeaders.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

foreach (var kvp in second.ApiKey) apiKey[kvp.Key] = kvp.Value;
foreach (var kvp in second.ApiKeyPrefix) apiKeyPrefix[kvp.Key] = kvp.Value;
foreach (var kvp in second.DefaultHeader) defaultHeader[kvp.Key] = kvp.Value;
foreach (var kvp in second.DefaultHeaders) defaultHeaders[kvp.Key] = kvp.Value;

var config = new Configuration
{
ApiKey = apiKey,
ApiKeyPrefix = apiKeyPrefix,
DefaultHeader = defaultHeader,
DefaultHeader = defaultHeaders,
BasePath = second.BasePath ?? first.BasePath,
Timeout = second.Timeout,
UserAgent = second.UserAgent ?? first.UserAgent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/


using System;
using System.Collections.Generic;

namespace Org.OpenAPITools.Client
Expand Down Expand Up @@ -52,8 +53,15 @@ public interface IReadableConfiguration
/// Gets the default header.
/// </summary>
/// <value>Default header.</value>
[Obsolete("Use DefaultHeaders instead.")]
IDictionary<string, string> DefaultHeader { get; }

/// <summary>
/// Gets the default headers.
/// </summary>
/// <value>Default headers.</value>
IDictionary<string, string> DefaultHeaders { get; }

/// <summary>
/// Gets the temp folder path.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ private RestRequest newRequest(
}
}

if (configuration.DefaultHeader != null)
if (configuration.DefaultHeaders != null)
{
foreach (var headerParam in configuration.DefaultHeader)
foreach (var headerParam in configuration.DefaultHeaders)
{
request.AddHeader(headerParam.Key, headerParam.Value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class Configuration : IReadableConfiguration
#endregion Constants

#region Static Members

/// <summary>
/// Default creation of exceptions for a given method name and response object
/// </summary>
Expand Down Expand Up @@ -72,7 +72,7 @@ public class Configuration : IReadableConfiguration
/// Example: http://localhost:3000/v1/
/// </summary>
private String _basePath;

/// <summary>
/// Gets or sets the API key based on the authentication name.
/// This is the key and value comprising the "secret" for acessing an API.
Expand Down Expand Up @@ -101,7 +101,7 @@ public Configuration()
{
UserAgent = "OpenAPI-Generator/1.0.0/csharp";
BasePath = "http://petstore.swagger.io:80/v2";
DefaultHeader = new ConcurrentDictionary<string, string>();
DefaultHeaders = new ConcurrentDictionary<string, string>();
ApiKey = new ConcurrentDictionary<string, string>();
ApiKeyPrefix = new ConcurrentDictionary<string, string>();

Expand All @@ -114,25 +114,25 @@ public Configuration()
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")]
public Configuration(
IDictionary<string, string> defaultHeader,
IDictionary<string, string> defaultHeaders,
IDictionary<string, string> apiKey,
IDictionary<string, string> apiKeyPrefix,
string basePath = "http://petstore.swagger.io:80/v2") : this()
{
if (string.IsNullOrWhiteSpace(basePath))
throw new ArgumentException("The provided basePath is invalid.", "basePath");
if (defaultHeader == null)
throw new ArgumentNullException("defaultHeader");
if (defaultHeaders == null)
throw new ArgumentNullException("defaultHeaders");
if (apiKey == null)
throw new ArgumentNullException("apiKey");
if (apiKeyPrefix == null)
throw new ArgumentNullException("apiKeyPrefix");

BasePath = basePath;

foreach (var keyValuePair in defaultHeader)
foreach (var keyValuePair in defaultHeaders)
{
DefaultHeader.Add(keyValuePair);
DefaultHeaders.Add(keyValuePair);
}

foreach (var keyValuePair in apiKey)
Expand Down Expand Up @@ -163,7 +163,23 @@ public virtual string BasePath {
/// <summary>
/// Gets or sets the default header.
/// </summary>
public virtual IDictionary<string, string> DefaultHeader { get; set; }
[Obsolete("Use DefaultHeaders instead.")]
public virtual IDictionary<string, string> DefaultHeader
{
get
{
return DefaultHeaders;
}
set
{
DefaultHeaders = value;
}
}

/// <summary>
/// Gets or sets the default headers.
/// </summary>
public virtual IDictionary<string, string> DefaultHeaders { get; set; }

/// <summary>
/// Gets or sets the HTTP timeout (milliseconds) of ApiClient. Default to 100000 milliseconds.
Expand Down Expand Up @@ -374,17 +390,17 @@ public static IReadableConfiguration MergeConfigurations(IReadableConfiguration

Dictionary<string, string> apiKey = first.ApiKey.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
Dictionary<string, string> apiKeyPrefix = first.ApiKeyPrefix.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
Dictionary<string, string> defaultHeader = first.DefaultHeader.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
Dictionary<string, string> defaultHeaders = first.DefaultHeaders.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

foreach (var kvp in second.ApiKey) apiKey[kvp.Key] = kvp.Value;
foreach (var kvp in second.ApiKeyPrefix) apiKeyPrefix[kvp.Key] = kvp.Value;
foreach (var kvp in second.DefaultHeader) defaultHeader[kvp.Key] = kvp.Value;
foreach (var kvp in second.DefaultHeaders) defaultHeaders[kvp.Key] = kvp.Value;

var config = new Configuration
{
ApiKey = apiKey,
ApiKeyPrefix = apiKeyPrefix,
DefaultHeader = defaultHeader,
DefaultHeader = defaultHeaders,
BasePath = second.BasePath ?? first.BasePath,
Timeout = second.Timeout,
UserAgent = second.UserAgent ?? first.UserAgent,
Expand Down
Loading