From f3cb207df3afced7b43b4c03e2467396d6bcbcf8 Mon Sep 17 00:00:00 2001 From: samwelkanda Date: Tue, 10 Sep 2024 07:49:49 +0300 Subject: [PATCH 1/3] Update logic for getting function descriptions and conversation starters --- .../Plugins/PluginsGenerationService.cs | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Kiota.Builder/Plugins/PluginsGenerationService.cs b/src/Kiota.Builder/Plugins/PluginsGenerationService.cs index bd1ec47cef..31e986bc67 100644 --- a/src/Kiota.Builder/Plugins/PluginsGenerationService.cs +++ b/src/Kiota.Builder/Plugins/PluginsGenerationService.cs @@ -259,8 +259,7 @@ private OpenApiDocument GetDocumentWithTrimmedComponentsAndResponses(OpenApiDocu private PluginManifestDocument GetManifestDocument(string openApiDocumentPath) { - var (runtimes, functions) = GetRuntimesAndFunctionsFromTree(OAIDocument, Configuration.PluginAuthInformation, TreeNode, openApiDocumentPath); - var capabilities = GetPluginCapabilitiesFromFunctions(functions); + var (runtimes, functions, conversationStarters) = GetRuntimesFunctionsAndConversationStartersFromTree(OAIDocument, Configuration.PluginAuthInformation, TreeNode, openApiDocumentPath); var descriptionForHuman = OAIDocument.Info?.Description.CleanupXMLString() is string d && !string.IsNullOrEmpty(d) ? d : $"Description for {OAIDocument.Info?.Title.CleanupXMLString()}"; var manifestInfo = ExtractInfoFromDocument(OAIDocument.Info); var pluginManifestDocument = new PluginManifestDocument @@ -287,11 +286,16 @@ private PluginManifestDocument GetManifestDocument(string openApiDocumentPath) Functions = [.. functions.OrderBy(static x => x.Name, StringComparer.OrdinalIgnoreCase)], }; - // Only add capabilities if there are any - if (capabilities != null) - { - pluginManifestDocument.Capabilities = capabilities; - } + if (conversationStarters.Length > 0) + pluginManifestDocument.Capabilities = new Capabilities + { + ConversationStarters = conversationStarters.Where(static x => !string.IsNullOrEmpty(x.Text)) + .Select(static x => new ConversationStarter + { + Text = x.Text?.Length < 50 ? x.Text : x.Text?[..50] + }) + .ToList() + }; return pluginManifestDocument; } @@ -334,11 +338,12 @@ private sealed record OpenApiManifestInfo( string? PrivacyUrl = null, string ContactEmail = DefaultContactEmail); - private static (OpenApiRuntime[], Function[]) GetRuntimesAndFunctionsFromTree(OpenApiDocument document, PluginAuthConfiguration? authInformation, OpenApiUrlTreeNode currentNode, + private static (OpenApiRuntime[], Function[], ConversationStarter[]) GetRuntimesFunctionsAndConversationStartersFromTree(OpenApiDocument document, PluginAuthConfiguration? authInformation, OpenApiUrlTreeNode currentNode, string openApiDocumentPath) { var runtimes = new List(); var functions = new List(); + var conversationStarters = new List(); var configAuth = authInformation?.ToPluginManifestAuth(); if (currentNode.PathItems.TryGetValue(Constants.DefaultOpenApiLabel, out var pathItem)) { @@ -351,26 +356,34 @@ private static (OpenApiRuntime[], Function[]) GetRuntimesAndFunctionsFromTree(Op Spec = new OpenApiRuntimeSpec { Url = openApiDocumentPath, }, RunForFunctions = [operation.OperationId] }); + + var summary = operation.Summary.CleanupXMLString(); + var description = operation.Description.CleanupXMLString(); + functions.Add(new Function { Name = operation.OperationId, - Description = - operation.Summary.CleanupXMLString() is { } summary && !string.IsNullOrEmpty(summary) - ? summary - : operation.Description.CleanupXMLString(), + Description = !string.IsNullOrEmpty(description) ? description : summary, States = GetStatesFromOperation(operation), + }); + conversationStarters.Add(new ConversationStarter + { + Text = !string.IsNullOrEmpty(summary) ? summary : description + }); + } } foreach (var node in currentNode.Children) { - var (childRuntimes, childFunctions) = GetRuntimesAndFunctionsFromTree(document, authInformation, node.Value, openApiDocumentPath); + var (childRuntimes, childFunctions, childConversationStarters) = GetRuntimesFunctionsAndConversationStartersFromTree(document, authInformation, node.Value, openApiDocumentPath); runtimes.AddRange(childRuntimes); functions.AddRange(childFunctions); + conversationStarters.AddRange(childConversationStarters); } - return (runtimes.ToArray(), functions.ToArray()); + return (runtimes.ToArray(), functions.ToArray(), conversationStarters.ToArray()); } private static Auth GetAuth(IList securityRequirements) @@ -437,17 +450,4 @@ rExtRaw is T rExt && return null; } - - private static Capabilities? GetPluginCapabilitiesFromFunctions(IList functions) - { - var conversionStarters = functions.Select(static x => x.Description) - .Where(static x => !string.IsNullOrEmpty(x)) - .Select(static x => new ConversationStarter - { - Text = x.Length < 50 ? x : x[..50], - }) - .ToList(); - - return conversionStarters.Count > 0 ? new Capabilities { ConversationStarters = conversionStarters } : null; - } } From b2bfbcbd2afeef4f38c7a65dc9d922520cdab89c Mon Sep 17 00:00:00 2001 From: samwelkanda Date: Tue, 10 Sep 2024 08:21:02 +0300 Subject: [PATCH 2/3] Update tests --- .../Plugins/PluginsGenerationServiceTests.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs b/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs index 331f0daa9d..e1d1701d45 100644 --- a/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs +++ b/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs @@ -50,12 +50,14 @@ public async Task GeneratesManifestAsync(string inputPluginName, string expected paths: /test: get: + summary: summary for test path description: description for test path responses: '200': description: test /test/{id}: get: + summary: Summary for test path with id that is longer than 50 characters description: description for test path with id operationId: test.WithId parameters: @@ -107,8 +109,10 @@ public async Task GeneratesManifestAsync(string inputPluginName, string expected Assert.NotNull(resultingManifest.Document); Assert.Equal($"{expectedPluginName.ToLower()}-openapi.yml", resultingManifest.Document.Runtimes.OfType().First().Spec.Url); Assert.Equal(2, resultingManifest.Document.Functions.Count);// all functions are generated despite missing operationIds + Assert.Contains("description for test path with id", resultingManifest.Document.Functions[1].Description);// Uses the operation description Assert.Equal(2, resultingManifest.Document.Capabilities.ConversationStarters.Count);// conversation starters are generated for each function - Assert.True(resultingManifest.Document.Capabilities.ConversationStarters[0].Text.Length < 50);// Conversation starters are limited to 50 characters + Assert.Contains("Summary for test path with id", resultingManifest.Document.Capabilities.ConversationStarters[1].Text);// Uses the operation summary + Assert.True(resultingManifest.Document.Capabilities.ConversationStarters[1].Text.Length <= 50);// Conversation starters are limited to 50 characters Assert.Equal(expectedPluginName, resultingManifest.Document.Namespace);// namespace is cleaned up. Assert.Empty(resultingManifest.Problems);// no problems are expected with names } From 3b061ca98580f832e82db09c2005c65b4e3b03da Mon Sep 17 00:00:00 2001 From: samwelkanda Date: Tue, 10 Sep 2024 10:31:23 +0300 Subject: [PATCH 3/3] Add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a5948d2a4..18a8c17d04 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 - Fixed a bug where collection/array of primitive types members for union/intersection types would be ignored. [#5283](https://github.com/microsoft/kiota/issues/5283) - Fixed a when generating a plugin when only an operation is selected in the root node in the extension. [#5300](https://github.com/microsoft/kiota/issues/5300) +- Fixed a bug where function descriptions in plugin manifest defaults to path summary instead of description[#5301](https://github.com/microsoft/kiota/issues/5301) ## [1.18.0] - 2024-09-05