Skip to content

Commit

Permalink
address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
koros committed Dec 3, 2024
1 parent 4ccc263 commit d9da636
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
16 changes: 8 additions & 8 deletions src/Kiota.Builder/Refiners/HttpRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override Task RefineAsync(CodeNamespace generatedCode, CancellationToken
.FindChildrenByName<CodeClass>(_configuration.ClientClassName)?
.FirstOrDefault()?
.Methods?
.FirstOrDefault(x => x.IsOfKind(CodeMethodKind.ClientConstructor))?
.FirstOrDefault(static x => x.IsOfKind(CodeMethodKind.ClientConstructor))?
.BaseUrl;
}

Expand Down Expand Up @@ -76,7 +76,7 @@ private static void SetBaseUrlForRequestBuilderMethods(CodeElement current, stri
CrawlTree(current, (element) => SetBaseUrlForRequestBuilderMethods(element, baseUrl));
}

private static void RemoveUnusedCodeElements(CodeElement element)
private void RemoveUnusedCodeElements(CodeElement element)
{
if (!IsRequestBuilderClass(element) || IsBaseRequestBuilder(element) || IsRequestBuilderClassWithoutAnyHttpOperations(element))
{
Expand Down Expand Up @@ -104,13 +104,13 @@ private static void AddPathParameters(CodeElement element)
.FirstOrDefault()?
.GetChildElements(false)
.OfType<CodeMethod>()
.FirstOrDefault(x => x.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility));
.FirstOrDefault(static x => x.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility));

if (codeIndexer is not null)
{
// Retrieve all the parameters of kind CodeParameterKind.Custom
var customParameters = codeIndexer.Parameters
.Where(param => param.IsOfKind(CodeParameterKind.Custom))
.Where(static param => param.IsOfKind(CodeParameterKind.Custom))
.ToList();

// For each parameter:
Expand Down Expand Up @@ -140,15 +140,15 @@ private static bool IsRequestBuilderClass(CodeElement element)
return element is CodeClass code && code.IsOfKind(CodeClassKind.RequestBuilder);
}

private static bool IsBaseRequestBuilder(CodeElement element)
private bool IsBaseRequestBuilder(CodeElement element)
{
return element is CodeClass codeClass && codeClass.IsOfKind(CodeClassKind.RequestBuilder) &&
codeClass.Properties.Any(property => property.IsOfKind(CodePropertyKind.UrlTemplate) && string.Equals(property.DefaultValue, "\"{+baseurl}\"", StringComparison.Ordinal));
return element is CodeClass codeClass &&
codeClass.Name.Equals(_configuration.ClientClassName, StringComparison.Ordinal);
}

private static bool IsRequestBuilderClassWithoutAnyHttpOperations(CodeElement element)
{
return element is CodeClass codeClass && codeClass.IsOfKind(CodeClassKind.RequestBuilder) &&
!codeClass.Methods.Any(method => method.IsOfKind(CodeMethodKind.RequestExecutor));
!codeClass.Methods.Any(static method => method.IsOfKind(CodeMethodKind.RequestExecutor));
}
}
14 changes: 3 additions & 11 deletions src/Kiota.Builder/Writers/HTTP/CodeClassDeclarationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,19 +361,11 @@ private static string BuildUrlStringFromTemplate(string urlTemplateString, List<
// Build RequestInformation using the URL
var requestInformation = new RequestInformation()
{
UrlTemplate = urlTemplateString
UrlTemplate = urlTemplateString,
QueryParameters = queryParameters.ToDictionary(item => item.WireName, item => $"{{{{{item.Name.ToFirstCharacterLowerCase()}}}}}" as object),
PathParameters = pathParameters.ToDictionary(item => item.WireName, item => $"{{{{{item.Name.ToFirstCharacterLowerCase()}}}}}" as object),
};

queryParameters?.ForEach(param =>
{
requestInformation.QueryParameters.Add(param.WireName, $"{{{{{param.Name.ToFirstCharacterLowerCase()}}}}}");
});

pathParameters?.ForEach(param =>
{
requestInformation.PathParameters.Add(param.WireName, $"{{{{{param.Name.ToFirstCharacterLowerCase()}}}}}");
});

// Erase baseUrl and use the placeholder variable {baseUrl} already defined in the snippet
return requestInformation.URI.ToString().Replace(baseUrl, $"{{{{{BaseUrlPropertyName}}}}}", StringComparison.InvariantCultureIgnoreCase);
}
Expand Down
1 change: 0 additions & 1 deletion src/Kiota.Builder/Writers/HTTP/HttpConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public HttpConventionService()
public override string StreamTypeName => "stream";
public override string VoidTypeName => "void";
public override string DocCommentPrefix => "###";
public static readonly char NullableMarker = '?';
public static string NullableMarkerAsString => "?";
public override string ParseNodeInterfaceName => "ParseNode";
public override bool WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "")
Expand Down

0 comments on commit d9da636

Please sign in to comment.