forked from loafle/openapi-generator-original
[csharp-netcore] Making HTTP response headers dictionary case-insensitive (#3707)
* fix(csharp-netcore): Making response headers case-insensitive * fix(r): Adding response headers on docs
This commit is contained in:
parent
bb5cd4c42d
commit
6924b3c710
@ -26,3 +26,4 @@ sidebar_label: csharp-netcore
|
|||||||
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|
||||||
|netCoreProjectFile|Use the new format (.NET Core) for .NET project files (.csproj).| |false|
|
|netCoreProjectFile|Use the new format (.NET Core) for .NET project files (.csproj).| |false|
|
||||||
|validatable|Generates self-validatable models.| |true|
|
|validatable|Generates self-validatable models.| |true|
|
||||||
|
|caseInsensitiveResponseHeaders|Make API response's headers case-insensitive| |false|
|
||||||
|
@ -78,6 +78,8 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
|||||||
// By default, generated code is considered public
|
// By default, generated code is considered public
|
||||||
protected boolean nonPublicApi = Boolean.FALSE;
|
protected boolean nonPublicApi = Boolean.FALSE;
|
||||||
|
|
||||||
|
protected boolean caseInsensitiveResponseHeaders = Boolean.FALSE;
|
||||||
|
|
||||||
public CSharpNetCoreClientCodegen() {
|
public CSharpNetCoreClientCodegen() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@ -206,6 +208,10 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
|||||||
CodegenConstants.VALIDATABLE_DESC,
|
CodegenConstants.VALIDATABLE_DESC,
|
||||||
this.validatable);
|
this.validatable);
|
||||||
|
|
||||||
|
addSwitch(CodegenConstants.CASE_INSENSITIVE_RESPONSE_HEADERS,
|
||||||
|
CodegenConstants.CASE_INSENSITIVE_RESPONSE_HEADERS_DESC,
|
||||||
|
this.caseInsensitiveResponseHeaders);
|
||||||
|
|
||||||
regexModifiers = new HashMap<>();
|
regexModifiers = new HashMap<>();
|
||||||
regexModifiers.put('i', "IgnoreCase");
|
regexModifiers.put('i', "IgnoreCase");
|
||||||
regexModifiers.put('m', "Multiline");
|
regexModifiers.put('m', "Multiline");
|
||||||
@ -640,6 +646,10 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
|||||||
this.validatable = validatable;
|
this.validatable = validatable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCaseInsensitiveResponseHeaders(final Boolean caseInsensitiveResponseHeaders) {
|
||||||
|
this.caseInsensitiveResponseHeaders = caseInsensitiveResponseHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toEnumVarName(String value, String datatype) {
|
public String toEnumVarName(String value, String datatype) {
|
||||||
if (value.length() == 0) {
|
if (value.length() == 0) {
|
||||||
|
@ -347,7 +347,7 @@ namespace {{packageName}}.Client
|
|||||||
private ApiResponse<T> toApiResponse<T>({{#supportsAsync}}IRestResponse<T> response{{/supportsAsync}}{{^supportsAsync}}IRestResponse response, CustomJsonCodec des{{/supportsAsync}})
|
private ApiResponse<T> toApiResponse<T>({{#supportsAsync}}IRestResponse<T> response{{/supportsAsync}}{{^supportsAsync}}IRestResponse response, CustomJsonCodec des{{/supportsAsync}})
|
||||||
{
|
{
|
||||||
T result = {{#supportsAsync}}response.Data{{/supportsAsync}}{{^supportsAsync}}(T)des.Deserialize(response, typeof(T)){{/supportsAsync}};
|
T result = {{#supportsAsync}}response.Data{{/supportsAsync}}{{^supportsAsync}}(T)des.Deserialize(response, typeof(T)){{/supportsAsync}};
|
||||||
var transformed = new ApiResponse<T>(response.StatusCode, new Multimap<string, string>(), result)
|
var transformed = new ApiResponse<T>(response.StatusCode, new Multimap<string, string>({{#caseInsensitiveResponseHeaders}}StringComparer.OrdinalIgnoreCase{{/caseInsensitiveResponseHeaders}}), result)
|
||||||
{
|
{
|
||||||
ErrorText = response.ErrorMessage,
|
ErrorText = response.ErrorMessage,
|
||||||
Cookies = new List<Cookie>()
|
Cookies = new List<Cookie>()
|
||||||
|
@ -21,6 +21,26 @@ namespace {{packageName}}.Client
|
|||||||
|
|
||||||
#endregion Private Fields
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Empty Constructor.
|
||||||
|
/// </summary>
|
||||||
|
public Multimap()
|
||||||
|
{
|
||||||
|
_dictionary = new {{^net35}}Concurrent{{/net35}}Dictionary<T, IList<TValue>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor with comparer.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer"></param>
|
||||||
|
public Multimap(IEqualityComparer<T> comparer) {
|
||||||
|
_dictionary = new {{^net35}}Concurrent{{/net35}}Dictionary<T, IList<TValue>>(comparer);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Constructors
|
||||||
|
|
||||||
#region Enumerators
|
#region Enumerators
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -30,6 +30,26 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
#endregion Private Fields
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Empty Constructor.
|
||||||
|
/// </summary>
|
||||||
|
public Multimap()
|
||||||
|
{
|
||||||
|
_dictionary = new ConcurrentDictionary<T, IList<TValue>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor with comparer.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer"></param>
|
||||||
|
public Multimap(IEqualityComparer<T> comparer) {
|
||||||
|
_dictionary = new ConcurrentDictionary<T, IList<TValue>>(comparer);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Constructors
|
||||||
|
|
||||||
#region Enumerators
|
#region Enumerators
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -30,6 +30,26 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
#endregion Private Fields
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Empty Constructor.
|
||||||
|
/// </summary>
|
||||||
|
public Multimap()
|
||||||
|
{
|
||||||
|
_dictionary = new ConcurrentDictionary<T, IList<TValue>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor with comparer.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer"></param>
|
||||||
|
public Multimap(IEqualityComparer<T> comparer) {
|
||||||
|
_dictionary = new ConcurrentDictionary<T, IList<TValue>>(comparer);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Constructors
|
||||||
|
|
||||||
#region Enumerators
|
#region Enumerators
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user