Skip to content

Commit

Permalink
- fixes a bug with class name extension cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Biret <[email protected]>
  • Loading branch information
baywet committed Nov 30, 2023
1 parent 33962ad commit 6a54826
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/Kiota.Builder/Extensions/OpenApiUrlTreeNodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ internal static string GetNavigationPropertyName(this OpenApiUrlTreeNode current
return $"{result}Path"; // we don't run the change of an operation conflicting with a path on the same request builder
return result;
}
private static readonly HashSet<string> httpVerbs = new(StringComparer.OrdinalIgnoreCase) { "get", "post", "put", "patch", "delete", "head", "options", "trace" };
private static readonly HashSet<string> httpVerbs = new(8, StringComparer.OrdinalIgnoreCase) { "get", "post", "put", "patch", "delete", "head", "options", "trace" };
private static string GetSegmentName(this OpenApiUrlTreeNode currentNode, StructuredMimeTypesCollection structuredMimeTypes, string? suffix, string? prefix, OpenApiOperation? operation, OpenApiResponse? response, OpenApiSchema? schema, bool requestBody, Func<IEnumerable<string>, string> segmentsReducer, bool skipExtension = true)
{
var referenceName = schema?.Reference?.GetClassName();
Expand All @@ -113,7 +113,7 @@ private static string GetSegmentName(this OpenApiUrlTreeNode currentNode, Struct
CleanupParametersFromPath(currentNode.Segment)?.ReplaceValueIdentifier()));
if (!string.IsNullOrEmpty(rawClassName) && string.IsNullOrEmpty(referenceName))
{
if (stripExtensionForIndexersTestRegex().IsMatch(rawClassName))
if (stripExtensionForIndexersRegex().IsMatch(rawClassName))
rawClassName = stripExtensionForIndexersRegex().Replace(rawClassName, string.Empty);
if ((currentNode?.DoesNodeBelongToItemSubnamespace() ?? false) && idClassNameCleanup().Replace(rawClassName, string.Empty) is string cleanedUpClassName && !cleanedUpClassName.Equals(rawClassName, StringComparison.Ordinal))
{
Expand Down Expand Up @@ -177,8 +177,6 @@ private static bool IsPathSegmentWithNumberOfParameters(this string currentSegme
}
[GeneratedRegex(@"\.(?:json|yaml|yml|csv|txt)$", RegexOptions.Singleline, 500)]
private static partial Regex stripExtensionForIndexersRegex(); // so {param-name}.json is considered as indexer
[GeneratedRegex(@"\{\w+\}\.(?:json|yaml|yml|csv|txt)$", RegexOptions.Singleline, 500)]
private static partial Regex stripExtensionForIndexersTestRegex(); // so {param-name}.json is considered as indexer
public static bool IsComplexPathMultipleParameters(this OpenApiUrlTreeNode currentNode) =>
(currentNode?.Segment?.IsPathSegmentWithNumberOfParameters(static x => x.Any()) ?? false) && !currentNode.IsPathSegmentWithSingleSimpleParameter();
public static string GetUrlTemplate(this OpenApiUrlTreeNode currentNode)
Expand Down

0 comments on commit 6a54826

Please sign in to comment.