Skip to content

Commit

Permalink
- replaces problematic regex with manual implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Biret <[email protected]>
  • Loading branch information
baywet committed Nov 28, 2023
1 parent d1c0ce4 commit 802ad00
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Kiota.Builder.Configuration;
using Microsoft.OpenApi.Models;

namespace Kiota.Builder.Extensions;
public static partial class OpenApiOperationExtensions
{
internal static readonly HashSet<string> 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)..];
}
/// <summary>
/// cleans application/vnd.github.mercy-preview+json to application/json
/// </summary>
Expand Down Expand Up @@ -49,7 +56,7 @@ internal static IEnumerable<OpenApiSchema> GetValidSchemas(this IDictionary<stri
return source
.Where(static c => !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);
}
Expand Down

0 comments on commit 802ad00

Please sign in to comment.