Skip to content

Commit 5581a2d

Browse files
authored
[csharp][generichost] fix syslib1045, use GeneratedRegex for .net7+ (#20695)
* [csharp][generichost] fix SYSLIB1045 for ClientUtils * make JsonRegex private * on net7 and above use GeneratedRegex for JsonRegex * remove unused SanitizeFilename-Method * [csharp][generichost] regenerate samples
1 parent 30787a1 commit 5581a2d

File tree

35 files changed

+100
-460
lines changed

35 files changed

+100
-460
lines changed

modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ClientUtils.mustache

+9-14
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ using System.Runtime.CompilerServices;
2424
/// <summary>
2525
/// Utility functions providing some benefit to API client consumers.
2626
/// </summary>
27-
{{>visibility}} static class ClientUtils
27+
{{>visibility}} static {{#net70OrLater}}partial {{/net70OrLater}}class ClientUtils
2828
{
2929
{{#useCompareNetObjects}}
3030
/// <summary>
@@ -143,17 +143,6 @@ using System.Runtime.CompilerServices;
143143
}
144144
}
145145

146-
/// <summary>
147-
/// Sanitize filename by removing the path
148-
/// </summary>
149-
/// <param name="filename">Filename</param>
150-
/// <returns>Filename</returns>
151-
public static string SanitizeFilename(string filename)
152-
{
153-
Match match = Regex.Match(filename, @".*[/\\](.*)$");
154-
return match.Success ? match.Groups[1].Value : filename;
155-
}
156-
157146
/// <summary>
158147
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
159148
/// If parameter is a list, join the list with ",".
@@ -325,7 +314,13 @@ using System.Runtime.CompilerServices;
325314
/// <summary>
326315
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
327316
/// </summary>
328-
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
317+
{{#net70OrLater}}
318+
[GeneratedRegex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$")]
319+
private static partial Regex JsonRegex();
320+
{{/net70OrLater}}
321+
{{^net70OrLater}}
322+
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
323+
{{/net70OrLater}}
329324

330325
/// <summary>
331326
/// Check if the given MIME is a JSON MIME.
@@ -341,7 +336,7 @@ using System.Runtime.CompilerServices;
341336
{
342337
if (string.IsNullOrWhiteSpace(mime)) return false;
343338
344-
return JsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json");
339+
return {{#net70OrLater}}JsonRegex(){{/net70OrLater}}{{^net70OrLater}}JsonRegex{{/net70OrLater}}.IsMatch(mime) || mime.Equals("application/json-patch+json");
345340
}
346341

347342
/// <summary>

samples/client/petstore/csharp/generichost/latest/Tags/src/Org.OpenAPITools/Client/ClientUtils.cs

+4-14
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Org.OpenAPITools.Client
2727
/// <summary>
2828
/// Utility functions providing some benefit to API client consumers.
2929
/// </summary>
30-
public static class ClientUtils
30+
public static partial class ClientUtils
3131
{
3232

3333
/// <summary>
@@ -109,17 +109,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
109109
}
110110
}
111111

112-
/// <summary>
113-
/// Sanitize filename by removing the path
114-
/// </summary>
115-
/// <param name="filename">Filename</param>
116-
/// <returns>Filename</returns>
117-
public static string SanitizeFilename(string filename)
118-
{
119-
Match match = Regex.Match(filename, @".*[/\\](.*)$");
120-
return match.Success ? match.Groups[1].Value : filename;
121-
}
122-
123112
/// <summary>
124113
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
125114
/// If parameter is a list, join the list with ",".
@@ -260,7 +249,8 @@ public static byte[] ReadAsBytes(Stream inputStream)
260249
/// <summary>
261250
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
262251
/// </summary>
263-
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
252+
[GeneratedRegex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$")]
253+
private static partial Regex JsonRegex();
264254

265255
/// <summary>
266256
/// Check if the given MIME is a JSON MIME.
@@ -276,7 +266,7 @@ public static bool IsJsonMime(string mime)
276266
{
277267
if (string.IsNullOrWhiteSpace(mime)) return false;
278268

279-
return JsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json");
269+
return JsonRegex().IsMatch(mime) || mime.Equals("application/json-patch+json");
280270
}
281271

282272
/// <summary>

samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Client/ClientUtils.cs

+1-12
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
9696
}
9797
}
9898

99-
/// <summary>
100-
/// Sanitize filename by removing the path
101-
/// </summary>
102-
/// <param name="filename">Filename</param>
103-
/// <returns>Filename</returns>
104-
public static string SanitizeFilename(string filename)
105-
{
106-
Match match = Regex.Match(filename, @".*[/\\](.*)$");
107-
return match.Success ? match.Groups[1].Value : filename;
108-
}
109-
11099
/// <summary>
111100
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
112101
/// If parameter is a list, join the list with ",".
@@ -245,7 +234,7 @@ public static string SelectHeaderAccept(string[] accepts)
245234
/// <summary>
246235
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
247236
/// </summary>
248-
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
237+
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
249238

250239
/// <summary>
251240
/// Check if the given MIME is a JSON MIME.

samples/client/petstore/csharp/generichost/net4.7/AnyOf/src/Org.OpenAPITools/Client/ClientUtils.cs

+1-12
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
9696
}
9797
}
9898

99-
/// <summary>
100-
/// Sanitize filename by removing the path
101-
/// </summary>
102-
/// <param name="filename">Filename</param>
103-
/// <returns>Filename</returns>
104-
public static string SanitizeFilename(string filename)
105-
{
106-
Match match = Regex.Match(filename, @".*[/\\](.*)$");
107-
return match.Success ? match.Groups[1].Value : filename;
108-
}
109-
11099
/// <summary>
111100
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
112101
/// If parameter is a list, join the list with ",".
@@ -245,7 +234,7 @@ public static string SelectHeaderAccept(string[] accepts)
245234
/// <summary>
246235
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
247236
/// </summary>
248-
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
237+
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
249238

250239
/// <summary>
251240
/// Check if the given MIME is a JSON MIME.

samples/client/petstore/csharp/generichost/net4.7/AnyOfNoCompare/src/Org.OpenAPITools/Client/ClientUtils.cs

+1-12
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
8181
}
8282
}
8383

84-
/// <summary>
85-
/// Sanitize filename by removing the path
86-
/// </summary>
87-
/// <param name="filename">Filename</param>
88-
/// <returns>Filename</returns>
89-
public static string SanitizeFilename(string filename)
90-
{
91-
Match match = Regex.Match(filename, @".*[/\\](.*)$");
92-
return match.Success ? match.Groups[1].Value : filename;
93-
}
94-
9584
/// <summary>
9685
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
9786
/// If parameter is a list, join the list with ",".
@@ -230,7 +219,7 @@ public static string SelectHeaderAccept(string[] accepts)
230219
/// <summary>
231220
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
232221
/// </summary>
233-
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
222+
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
234223

235224
/// <summary>
236225
/// Check if the given MIME is a JSON MIME.

samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs

+1-12
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
130130
}
131131
}
132132

133-
/// <summary>
134-
/// Sanitize filename by removing the path
135-
/// </summary>
136-
/// <param name="filename">Filename</param>
137-
/// <returns>Filename</returns>
138-
public static string SanitizeFilename(string filename)
139-
{
140-
Match match = Regex.Match(filename, @".*[/\\](.*)$");
141-
return match.Success ? match.Groups[1].Value : filename;
142-
}
143-
144133
/// <summary>
145134
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
146135
/// If parameter is a list, join the list with ",".
@@ -345,7 +334,7 @@ public static string SelectHeaderAccept(string[] accepts)
345334
/// <summary>
346335
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
347336
/// </summary>
348-
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
337+
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
349338

350339
/// <summary>
351340
/// Check if the given MIME is a JSON MIME.

samples/client/petstore/csharp/generichost/net4.7/OneOf/src/Org.OpenAPITools/Client/ClientUtils.cs

+1-12
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
9696
}
9797
}
9898

99-
/// <summary>
100-
/// Sanitize filename by removing the path
101-
/// </summary>
102-
/// <param name="filename">Filename</param>
103-
/// <returns>Filename</returns>
104-
public static string SanitizeFilename(string filename)
105-
{
106-
Match match = Regex.Match(filename, @".*[/\\](.*)$");
107-
return match.Success ? match.Groups[1].Value : filename;
108-
}
109-
11099
/// <summary>
111100
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
112101
/// If parameter is a list, join the list with ",".
@@ -245,7 +234,7 @@ public static string SelectHeaderAccept(string[] accepts)
245234
/// <summary>
246235
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
247236
/// </summary>
248-
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
237+
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
249238

250239
/// <summary>
251240
/// Check if the given MIME is a JSON MIME.

samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs

+1-12
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
130130
}
131131
}
132132

133-
/// <summary>
134-
/// Sanitize filename by removing the path
135-
/// </summary>
136-
/// <param name="filename">Filename</param>
137-
/// <returns>Filename</returns>
138-
public static string SanitizeFilename(string filename)
139-
{
140-
Match match = Regex.Match(filename, @".*[/\\](.*)$");
141-
return match.Success ? match.Groups[1].Value : filename;
142-
}
143-
144133
/// <summary>
145134
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
146135
/// If parameter is a list, join the list with ",".
@@ -349,7 +338,7 @@ public static string SelectHeaderAccept(string[] accepts)
349338
/// <summary>
350339
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
351340
/// </summary>
352-
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
341+
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
353342

354343
/// <summary>
355344
/// Check if the given MIME is a JSON MIME.

samples/client/petstore/csharp/generichost/net4.7/UseDateTimeForDate/src/Org.OpenAPITools/Client/ClientUtils.cs

+1-12
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
8181
}
8282
}
8383

84-
/// <summary>
85-
/// Sanitize filename by removing the path
86-
/// </summary>
87-
/// <param name="filename">Filename</param>
88-
/// <returns>Filename</returns>
89-
public static string SanitizeFilename(string filename)
90-
{
91-
Match match = Regex.Match(filename, @".*[/\\](.*)$");
92-
return match.Success ? match.Groups[1].Value : filename;
93-
}
94-
9584
/// <summary>
9685
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
9786
/// If parameter is a list, join the list with ",".
@@ -230,7 +219,7 @@ public static string SelectHeaderAccept(string[] accepts)
230219
/// <summary>
231220
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
232221
/// </summary>
233-
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
222+
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
234223

235224
/// <summary>
236225
/// Check if the given MIME is a JSON MIME.

samples/client/petstore/csharp/generichost/net4.8/AllOf/src/Org.OpenAPITools/Client/ClientUtils.cs

+1-12
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
9696
}
9797
}
9898

99-
/// <summary>
100-
/// Sanitize filename by removing the path
101-
/// </summary>
102-
/// <param name="filename">Filename</param>
103-
/// <returns>Filename</returns>
104-
public static string SanitizeFilename(string filename)
105-
{
106-
Match match = Regex.Match(filename, @".*[/\\](.*)$");
107-
return match.Success ? match.Groups[1].Value : filename;
108-
}
109-
11099
/// <summary>
111100
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
112101
/// If parameter is a list, join the list with ",".
@@ -245,7 +234,7 @@ public static string SelectHeaderAccept(string[] accepts)
245234
/// <summary>
246235
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
247236
/// </summary>
248-
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
237+
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
249238

250239
/// <summary>
251240
/// Check if the given MIME is a JSON MIME.

samples/client/petstore/csharp/generichost/net4.8/AnyOf/src/Org.OpenAPITools/Client/ClientUtils.cs

+1-12
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
9696
}
9797
}
9898

99-
/// <summary>
100-
/// Sanitize filename by removing the path
101-
/// </summary>
102-
/// <param name="filename">Filename</param>
103-
/// <returns>Filename</returns>
104-
public static string SanitizeFilename(string filename)
105-
{
106-
Match match = Regex.Match(filename, @".*[/\\](.*)$");
107-
return match.Success ? match.Groups[1].Value : filename;
108-
}
109-
11099
/// <summary>
111100
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
112101
/// If parameter is a list, join the list with ",".
@@ -245,7 +234,7 @@ public static string SelectHeaderAccept(string[] accepts)
245234
/// <summary>
246235
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
247236
/// </summary>
248-
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
237+
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
249238

250239
/// <summary>
251240
/// Check if the given MIME is a JSON MIME.

samples/client/petstore/csharp/generichost/net4.8/AnyOfNoCompare/src/Org.OpenAPITools/Client/ClientUtils.cs

+1-12
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
8181
}
8282
}
8383

84-
/// <summary>
85-
/// Sanitize filename by removing the path
86-
/// </summary>
87-
/// <param name="filename">Filename</param>
88-
/// <returns>Filename</returns>
89-
public static string SanitizeFilename(string filename)
90-
{
91-
Match match = Regex.Match(filename, @".*[/\\](.*)$");
92-
return match.Success ? match.Groups[1].Value : filename;
93-
}
94-
9584
/// <summary>
9685
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
9786
/// If parameter is a list, join the list with ",".
@@ -230,7 +219,7 @@ public static string SelectHeaderAccept(string[] accepts)
230219
/// <summary>
231220
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
232221
/// </summary>
233-
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
222+
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
234223

235224
/// <summary>
236225
/// Check if the given MIME is a JSON MIME.

samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs

+1-12
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
130130
}
131131
}
132132

133-
/// <summary>
134-
/// Sanitize filename by removing the path
135-
/// </summary>
136-
/// <param name="filename">Filename</param>
137-
/// <returns>Filename</returns>
138-
public static string SanitizeFilename(string filename)
139-
{
140-
Match match = Regex.Match(filename, @".*[/\\](.*)$");
141-
return match.Success ? match.Groups[1].Value : filename;
142-
}
143-
144133
/// <summary>
145134
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
146135
/// If parameter is a list, join the list with ",".
@@ -345,7 +334,7 @@ public static string SelectHeaderAccept(string[] accepts)
345334
/// <summary>
346335
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
347336
/// </summary>
348-
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
337+
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
349338

350339
/// <summary>
351340
/// Check if the given MIME is a JSON MIME.

0 commit comments

Comments
 (0)