From d9da63683234df05c014511b400f02954f97b3f7 Mon Sep 17 00:00:00 2001 From: koros Date: Tue, 3 Dec 2024 17:24:01 +0300 Subject: [PATCH] address pr comments --- src/Kiota.Builder/Refiners/HttpRefiner.cs | 16 ++++++++-------- .../Writers/HTTP/CodeClassDeclarationWriter.cs | 14 +++----------- .../Writers/HTTP/HttpConventionService.cs | 1 - 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/Kiota.Builder/Refiners/HttpRefiner.cs b/src/Kiota.Builder/Refiners/HttpRefiner.cs index 3b23a81703..6c5da85000 100644 --- a/src/Kiota.Builder/Refiners/HttpRefiner.cs +++ b/src/Kiota.Builder/Refiners/HttpRefiner.cs @@ -47,7 +47,7 @@ public override Task RefineAsync(CodeNamespace generatedCode, CancellationToken .FindChildrenByName(_configuration.ClientClassName)? .FirstOrDefault()? .Methods? - .FirstOrDefault(x => x.IsOfKind(CodeMethodKind.ClientConstructor))? + .FirstOrDefault(static x => x.IsOfKind(CodeMethodKind.ClientConstructor))? .BaseUrl; } @@ -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)) { @@ -104,13 +104,13 @@ private static void AddPathParameters(CodeElement element) .FirstOrDefault()? .GetChildElements(false) .OfType() - .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: @@ -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)); } } diff --git a/src/Kiota.Builder/Writers/HTTP/CodeClassDeclarationWriter.cs b/src/Kiota.Builder/Writers/HTTP/CodeClassDeclarationWriter.cs index bfc5d78a2e..a1a9142b5b 100644 --- a/src/Kiota.Builder/Writers/HTTP/CodeClassDeclarationWriter.cs +++ b/src/Kiota.Builder/Writers/HTTP/CodeClassDeclarationWriter.cs @@ -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); } diff --git a/src/Kiota.Builder/Writers/HTTP/HttpConventionService.cs b/src/Kiota.Builder/Writers/HTTP/HttpConventionService.cs index 6e41f8c8c7..f51ca9f5d6 100644 --- a/src/Kiota.Builder/Writers/HTTP/HttpConventionService.cs +++ b/src/Kiota.Builder/Writers/HTTP/HttpConventionService.cs @@ -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 = "")