diff --git a/modules/openapi-generator/src/main/resources/csharp-refactor/ClientUtils.mustache b/modules/openapi-generator/src/main/resources/csharp-refactor/ClientUtils.mustache
index 73d368321f3..7b88f488135 100755
--- a/modules/openapi-generator/src/main/resources/csharp-refactor/ClientUtils.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp-refactor/ClientUtils.mustache
@@ -204,7 +204,7 @@ namespace {{packageName}}.Client
foreach (var contentType in contentTypes)
{
- if (IsJsonMime(contentType.ToLower()))
+ if (IsJsonMime(contentType))
return contentType;
}
@@ -229,6 +229,11 @@ namespace {{packageName}}.Client
return String.Join(",", accepts);
}
+ ///
+ /// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
+ ///
+ public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
+
///
/// Check if the given MIME is a JSON MIME.
/// JSON MIME examples:
@@ -241,8 +246,9 @@ namespace {{packageName}}.Client
/// Returns True if MIME type is json.
public static 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"));
+ if (String.IsNullOrWhiteSpace(mime)) return false;
+
+ return JsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json");
}
}
}
diff --git a/samples/client/petstore/csharp-refactor/OpenAPIClient/src/Org.OpenAPITools/Client/ClientUtils.cs b/samples/client/petstore/csharp-refactor/OpenAPIClient/src/Org.OpenAPITools/Client/ClientUtils.cs
index f56a9f185be..cbbe60300fd 100644
--- a/samples/client/petstore/csharp-refactor/OpenAPIClient/src/Org.OpenAPITools/Client/ClientUtils.cs
+++ b/samples/client/petstore/csharp-refactor/OpenAPIClient/src/Org.OpenAPITools/Client/ClientUtils.cs
@@ -208,7 +208,7 @@ namespace Org.OpenAPITools.Client
foreach (var contentType in contentTypes)
{
- if (IsJsonMime(contentType.ToLower()))
+ if (IsJsonMime(contentType))
return contentType;
}
@@ -233,6 +233,11 @@ namespace Org.OpenAPITools.Client
return String.Join(",", accepts);
}
+ ///
+ /// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
+ ///
+ public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
+
///
/// Check if the given MIME is a JSON MIME.
/// JSON MIME examples:
@@ -245,8 +250,9 @@ namespace Org.OpenAPITools.Client
/// Returns True if MIME type is json.
public static 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"));
+ if (String.IsNullOrWhiteSpace(mime)) return false;
+
+ return JsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json");
}
}
}