Skip to content

Commit

Permalink
remove unused code in the refiner
Browse files Browse the repository at this point in the history
  • Loading branch information
koros committed Nov 14, 2024
1 parent 9bcac7d commit 5154280
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions src/Kiota.Builder/Refiners/HttpRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public override Task RefineAsync(CodeNamespace generatedCode, CancellationToken
{
cancellationToken.ThrowIfCancellationRequested();
CapitalizeNamespacesFirstLetters(generatedCode);
AddRootClassForExtensions(generatedCode);
ReplaceIndexersByMethodsWithParameter(
generatedCode,
false,
Expand All @@ -44,10 +43,9 @@ public override Task RefineAsync(CodeNamespace generatedCode, CancellationToken
AddDefaultImports(
generatedCode,
defaultUsingEvaluators);
RemoveUntypedNodePropertyValues(generatedCode);
cancellationToken.ThrowIfCancellationRequested();
SetBaseUrlForRequestBuilderMethods(generatedCode, GetBaseUrl(generatedCode));
// Remove unused code from the DOM e.g Models
// Remove unused code from the DOM e.g Models, BarrelInitializers, e.t.c
RemoveUnusedCodeElements(generatedCode);
CorrectCoreType(
generatedCode,
Expand Down Expand Up @@ -228,23 +226,6 @@ private static void SetBaseUrlForRequestBuilderMethods(CodeElement current, stri
CrawlTree(current, (element) => SetBaseUrlForRequestBuilderMethods(element, baseUrl));
}

private void AddRootClassForExtensions(CodeElement current)
{
if (current is CodeNamespace currentNamespace &&
currentNamespace.FindNamespaceByName(_configuration.ClientNamespaceName) is CodeNamespace clientNamespace)
{
clientNamespace.AddClass(new CodeClass
{
Name = clientNamespace.Name.Split('.', StringSplitOptions.RemoveEmptyEntries).Last().ToFirstCharacterUpperCase(),
Kind = CodeClassKind.BarrelInitializer,
Documentation = new()
{
DescriptionTemplate = "Root class for extensions",
},
});
}
}

private static void RemoveUnusedCodeElements(CodeElement element)
{
if (element is CodeClass code && (code.IsOfKind(CodeClassKind.Model) || code.IsOfKind(CodeClassKind.BarrelInitializer) || IsBaseRequestBuilder(code)))
Expand Down

0 comments on commit 5154280

Please sign in to comment.