forked from loafle/openapi-generator-original
[csharp-refactor] Minor csharp refactor changes (#1723)
* [csharp-refactor] Minor changes to JSON mime usage
🐎 This maeks the regex static to reduce GC overhead for active clients.
This also removes the lowercase call on the mimetype before evaluating,
as the regex already uses the inline modifier for case insensitivity.
* [csharp-refactor] Regenerate sample
This commit is contained in:
parent
89a0ffa66c
commit
10ecc0e52f
@ -204,7 +204,7 @@ namespace {{packageName}}.Client
|
|||||||
|
|
||||||
foreach (var contentType in contentTypes)
|
foreach (var contentType in contentTypes)
|
||||||
{
|
{
|
||||||
if (IsJsonMime(contentType.ToLower()))
|
if (IsJsonMime(contentType))
|
||||||
return contentType;
|
return contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,6 +229,11 @@ namespace {{packageName}}.Client
|
|||||||
return String.Join(",", accepts);
|
return String.Join(",", accepts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
|
||||||
|
/// </summary>
|
||||||
|
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if the given MIME is a JSON MIME.
|
/// Check if the given MIME is a JSON MIME.
|
||||||
/// JSON MIME examples:
|
/// JSON MIME examples:
|
||||||
@ -241,8 +246,9 @@ namespace {{packageName}}.Client
|
|||||||
/// <returns>Returns True if MIME type is json.</returns>
|
/// <returns>Returns True if MIME type is json.</returns>
|
||||||
public static bool IsJsonMime(String mime)
|
public static bool IsJsonMime(String mime)
|
||||||
{
|
{
|
||||||
var jsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
|
if (String.IsNullOrWhiteSpace(mime)) return false;
|
||||||
return mime != null && (jsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json"));
|
|
||||||
|
return JsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ namespace Org.OpenAPITools.Client
|
|||||||
|
|
||||||
foreach (var contentType in contentTypes)
|
foreach (var contentType in contentTypes)
|
||||||
{
|
{
|
||||||
if (IsJsonMime(contentType.ToLower()))
|
if (IsJsonMime(contentType))
|
||||||
return contentType;
|
return contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,6 +233,11 @@ namespace Org.OpenAPITools.Client
|
|||||||
return String.Join(",", accepts);
|
return String.Join(",", accepts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
|
||||||
|
/// </summary>
|
||||||
|
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if the given MIME is a JSON MIME.
|
/// Check if the given MIME is a JSON MIME.
|
||||||
/// JSON MIME examples:
|
/// JSON MIME examples:
|
||||||
@ -245,8 +250,9 @@ namespace Org.OpenAPITools.Client
|
|||||||
/// <returns>Returns True if MIME type is json.</returns>
|
/// <returns>Returns True if MIME type is json.</returns>
|
||||||
public static bool IsJsonMime(String mime)
|
public static bool IsJsonMime(String mime)
|
||||||
{
|
{
|
||||||
var jsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
|
if (String.IsNullOrWhiteSpace(mime)) return false;
|
||||||
return mime != null && (jsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json"));
|
|
||||||
|
return JsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user