From 48bae4ad24fdadd89d881e948ecbd4604083d9f3 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 22 Sep 2023 09:03:05 -0400 Subject: [PATCH] - fixes a bug where the hints would miss quotes for paths and always use the API manifest Signed-off-by: Vincent Biret --- CHANGELOG.md | 1 + src/Kiota.Builder/KiotaBuilder.cs | 7 ++++--- src/kiota/Handlers/BaseKiotaCommandHandler.cs | 8 ++++---- src/kiota/Handlers/KiotaGenerationCommandHandler.cs | 9 ++++++--- src/kiota/Handlers/KiotaShowCommandHandler.cs | 4 ++-- src/kiota/Rpc/Server.cs | 2 +- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 982b48ab79..c61e9e09e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Localhost based descriptions are not cached anymore to facilitate development workflows. [#3316](https://github.com/microsoft/kiota/issues/3316) +- Fixed a bug where the hints would miss quotes for paths and always use the API manifest. [#3342](https://github.com/microsoft/kiota/issues/3342) - Fixed a bug where inline composed types for components schemas would have the wrong name. [#3067](https://github.com/microsoft/kiota/issues/3067) - Changed parameter order in with_url method body to match the signature of RequestBuilder constructor in Python. [#3328](https://github.com/microsoft/kiota/issues/3328) - Removed redundant undefined qualifier in TypeScript for properties. [#3244](https://github.com/microsoft/kiota/issues/3244) diff --git a/src/Kiota.Builder/KiotaBuilder.cs b/src/Kiota.Builder/KiotaBuilder.cs index 7af65ef437..a2f621bfc1 100644 --- a/src/Kiota.Builder/KiotaBuilder.cs +++ b/src/Kiota.Builder/KiotaBuilder.cs @@ -91,7 +91,7 @@ private static string NormalizeApiManifestPath(Request request, string? baseUrl) rawValue = '/' + rawValue; return rawValue.Split('?', StringSplitOptions.RemoveEmptyEntries)[0]; } - public async Task>?> GetApiManifestDetailsAsync(CancellationToken cancellationToken) + public async Task>?> GetApiManifestDetailsAsync(bool skipErrorLog = false, CancellationToken cancellationToken = default) { try { @@ -129,7 +129,8 @@ private static string NormalizeApiManifestPath(Request request, string? baseUrl) catch (Exception ex) #pragma warning restore CA1031 { - logger.LogCritical("error getting the API manifest: {ExceptionMessage}", ex.Message); + if (!skipErrorLog) + logger.LogCritical("error getting the API manifest: {ExceptionMessage}", ex.Message); return null; } } @@ -140,7 +141,7 @@ private static string NormalizeApiManifestPath(Request request, string? baseUrl) if (config.ShouldGetApiManifest) { sw.Start(); - var manifestDetails = await GetApiManifestDetailsAsync(cancellationToken).ConfigureAwait(false); + var manifestDetails = await GetApiManifestDetailsAsync(cancellationToken: cancellationToken).ConfigureAwait(false); if (manifestDetails is not null) { inputPath = manifestDetails.Item1; diff --git a/src/kiota/Handlers/BaseKiotaCommandHandler.cs b/src/kiota/Handlers/BaseKiotaCommandHandler.cs index abf42bab4f..af680b9c65 100644 --- a/src/kiota/Handlers/BaseKiotaCommandHandler.cs +++ b/src/kiota/Handlers/BaseKiotaCommandHandler.cs @@ -223,7 +223,7 @@ protected void DisplayShowHint(string searchTerm, string version, string? path = { var example = path switch { - _ when !string.IsNullOrEmpty(path) => $"Example: kiota show -d {path}", + _ when !string.IsNullOrEmpty(path) => $"Example: kiota show -d \"{path}\"", _ when string.IsNullOrEmpty(version) => $"Example: kiota show -k {searchTerm}", _ => $"Example: kiota show -k {searchTerm} -v {version}", }; @@ -235,8 +235,8 @@ protected void DisplayShowAdvancedHint(string searchTerm, string version, IEnume { var example = path switch { - _ when !string.IsNullOrEmpty(path) => $"Example: kiota show -d {path} --include-path \"**/foo\"", - _ when !string.IsNullOrEmpty(manifest) => $"Example: kiota show -m {manifest} --include-path \"**/foo\"", + _ when !string.IsNullOrEmpty(path) => $"Example: kiota show -d \"{path}\" --include-path \"**/foo\"", + _ when !string.IsNullOrEmpty(manifest) => $"Example: kiota show -m \"{manifest}\" --include-path \"**/foo\"", _ when string.IsNullOrEmpty(version) => $"Example: kiota show -k {searchTerm} --include-path \"**/foo\"", _ => $"Example: kiota show -k {searchTerm} -v {version} --include-path \"**/foo\"", }; @@ -276,7 +276,7 @@ protected void DisplayGenerateAdvancedHint(IEnumerable includePaths, IEn } private static string GetSourceArg(string path, string manifest) { - return string.IsNullOrEmpty(manifest) ? $"-d {path}" : $"-m {manifest}"; + return string.IsNullOrEmpty(manifest) ? $"-d \"{path}\"" : $"-m \"{manifest}\""; } protected void DisplayInfoHint(GenerationLanguage language, string path, string manifest) { diff --git a/src/kiota/Handlers/KiotaGenerationCommandHandler.cs b/src/kiota/Handlers/KiotaGenerationCommandHandler.cs index 9b07ee21b9..5976c0c455 100644 --- a/src/kiota/Handlers/KiotaGenerationCommandHandler.cs +++ b/src/kiota/Handlers/KiotaGenerationCommandHandler.cs @@ -124,7 +124,8 @@ public override async Task InvokeAsync(InvocationContext context) try { - var result = await new KiotaBuilder(logger, Configuration.Generation, httpClient).GenerateClientAsync(cancellationToken); + var builder = new KiotaBuilder(logger, Configuration.Generation, httpClient); + var result = await builder.GenerateClientAsync(cancellationToken).ConfigureAwait(false); if (result) DisplaySuccess("Generation completed successfully"); else @@ -132,8 +133,10 @@ public override async Task InvokeAsync(InvocationContext context) DisplaySuccess("Generation skipped as no changes were detected"); DisplayCleanHint("generate"); } - DisplayInfoHint(language, Configuration.Generation.OpenAPIFilePath, Configuration.Generation.ApiManifestPath); - DisplayGenerateAdvancedHint(includePatterns, excludePatterns, Configuration.Generation.OpenAPIFilePath, Configuration.Generation.ApiManifestPath); + var manifestResult = await builder.GetApiManifestDetailsAsync(true, cancellationToken).ConfigureAwait(false); + var manifestPath = manifestResult is null ? string.Empty : Configuration.Generation.ApiManifestPath; + DisplayInfoHint(language, Configuration.Generation.OpenAPIFilePath, manifestPath); + DisplayGenerateAdvancedHint(includePatterns, excludePatterns, Configuration.Generation.OpenAPIFilePath, manifestPath); return 0; } catch (Exception ex) diff --git a/src/kiota/Handlers/KiotaShowCommandHandler.cs b/src/kiota/Handlers/KiotaShowCommandHandler.cs index 1808311458..33b51b2376 100644 --- a/src/kiota/Handlers/KiotaShowCommandHandler.cs +++ b/src/kiota/Handlers/KiotaShowCommandHandler.cs @@ -86,7 +86,7 @@ public override async Task InvokeAsync(InvocationContext context) Configuration.Generation.ClearCache = clearCache; try { - var urlTreeNode = await new KiotaBuilder(logger, Configuration.Generation, httpClient).GetUrlTreeNodeAsync(cancellationToken); + var urlTreeNode = await new KiotaBuilder(logger, Configuration.Generation, httpClient).GetUrlTreeNodeAsync(cancellationToken).ConfigureAwait(false); var builder = new StringBuilder(); if (urlTreeNode != null) @@ -96,7 +96,7 @@ public override async Task InvokeAsync(InvocationContext context) if (descriptionProvided) DisplayShowAdvancedHint(string.Empty, string.Empty, includePatterns, excludePatterns, openapi, manifest); else - DisplayShowAdvancedHint(searchTerm, version, includePatterns, excludePatterns, openapi, manifest); + DisplayShowAdvancedHint(searchTerm, version, includePatterns, excludePatterns, openapi); DisplayGenerateHint(openapi, manifest, includePatterns, excludePatterns); } catch (Exception ex) diff --git a/src/kiota/Rpc/Server.cs b/src/kiota/Rpc/Server.cs index 07924de6e9..7ed84daf7d 100644 --- a/src/kiota/Rpc/Server.cs +++ b/src/kiota/Rpc/Server.cs @@ -100,7 +100,7 @@ public async Task GetManifestDetailsAsync(string manifestPath, s var configuration = Configuration.Generation; configuration.ApiManifestPath = $"{manifestPath}#{apiIdentifier}"; var builder = new KiotaBuilder(logger, configuration, httpClient); - var manifestResult = await builder.GetApiManifestDetailsAsync(cancellationToken); + var manifestResult = await builder.GetApiManifestDetailsAsync(cancellationToken: cancellationToken); return new ManifestResult(logger.LogEntries, manifestResult?.Item1, manifestResult?.Item2.ToArray());