From 802ad00fd30b534c296f8b58d82a752536e63d21 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 28 Nov 2023 12:58:07 -0500 Subject: [PATCH] - replaces problematic regex with manual implementation Signed-off-by: Vincent Biret --- .../Extensions/OpenApiOperationExtensions.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs b/src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs index 8b1843eda1..c65da5aa9c 100644 --- a/src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs +++ b/src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text.RegularExpressions; using Kiota.Builder.Configuration; using Microsoft.OpenApi.Models; @@ -9,8 +8,16 @@ namespace Kiota.Builder.Extensions; public static partial class OpenApiOperationExtensions { internal static readonly HashSet SuccessCodes = new(StringComparer.OrdinalIgnoreCase) { "200", "201", "202", "203", "206", "2XX" }; //204 excluded as it won't have a schema - [GeneratedRegex(@"[^/]+?\+", RegexOptions.IgnoreCase | RegexOptions.Singleline, 100)] - private static partial Regex vendorSpecificCleanup(); + private static string vendorSpecificCleanup(string input) + { + var slashIndex = input.IndexOf('/', StringComparison.OrdinalIgnoreCase); + var plusIndex = input.IndexOf('+', StringComparison.OrdinalIgnoreCase); + if (slashIndex == -1 || plusIndex == -1) + return input; + if (plusIndex < slashIndex) + return input; + return input[0..(slashIndex + 1)] + input[(plusIndex + 1)..]; + } /// /// cleans application/vnd.github.mercy-preview+json to application/json /// @@ -49,7 +56,7 @@ internal static IEnumerable GetValidSchemas(this IDictionary !string.IsNullOrEmpty(c.Key)) .Select(static c => (Key: c.Key.Split(';', StringSplitOptions.RemoveEmptyEntries)[0], c.Value)) - .Where(c => structuredMimeTypes.Contains(c.Key) || structuredMimeTypes.Contains(vendorSpecificCleanup().Replace(c.Key, string.Empty))) + .Where(c => structuredMimeTypes.Contains(c.Key) || structuredMimeTypes.Contains(vendorSpecificCleanup(c.Key))) .Select(static co => co.Value.Schema) .Where(static s => s is not null); }