Skip to content

Commit

Permalink
- fixes a bug where the hints would miss quotes for paths and always …
Browse files Browse the repository at this point in the history
…use the API manifest

Signed-off-by: Vincent Biret <[email protected]>
  • Loading branch information
baywet committed Sep 22, 2023
1 parent 579e18b commit 48bae4a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private static string NormalizeApiManifestPath(Request request, string? baseUrl)
rawValue = '/' + rawValue;
return rawValue.Split('?', StringSplitOptions.RemoveEmptyEntries)[0];
}
public async Task<Tuple<string, IEnumerable<string>>?> GetApiManifestDetailsAsync(CancellationToken cancellationToken)
public async Task<Tuple<string, IEnumerable<string>>?> GetApiManifestDetailsAsync(bool skipErrorLog = false, CancellationToken cancellationToken = default)
{
try
{
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/kiota/Handlers/BaseKiotaCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
};
Expand All @@ -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\"",
};
Expand Down Expand Up @@ -276,7 +276,7 @@ protected void DisplayGenerateAdvancedHint(IEnumerable<string> 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)
{
Expand Down
9 changes: 6 additions & 3 deletions src/kiota/Handlers/KiotaGenerationCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,19 @@ public override async Task<int> 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
{
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)
Expand Down
4 changes: 2 additions & 2 deletions src/kiota/Handlers/KiotaShowCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public override async Task<int> 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)
Expand All @@ -96,7 +96,7 @@ public override async Task<int> 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)
Expand Down
2 changes: 1 addition & 1 deletion src/kiota/Rpc/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public async Task<ManifestResult> 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());
Expand Down

0 comments on commit 48bae4a

Please sign in to comment.