From 3211d880f8739c744a0d7e848a5da45187bc277b Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 23 Aug 2024 09:42:33 -0400 Subject: [PATCH] chore: upgrade dependencies feat: removes openai plugin generation --- CHANGELOG.md | 1 + src/Kiota.Builder/Kiota.Builder.csproj | 2 +- src/Kiota.Builder/Plugins/AuthComparer.cs | 2 +- .../Plugins/PluginsGenerationService.cs | 32 ++----------------- .../Plugins/PluginsGenerationServiceTests.cs | 11 ++----- 5 files changed, 8 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83f4e52a26..61d59f346a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Removed OpenAI plugins generation since the service does not support them anymore. - Fixed an issue where models would be missing when they had no properties and a single allOf entry. [#5014](https://github.com/microsoft/kiota/issues/5014) - Reverts modification of responses in output openApi file when generating plugins [#4945](https://github.com/microsoft/kiota/issues/4945) - Expand properties types with null type for Typescript. [#4993](https://github.com/microsoft/kiota-typescript/issues/1188) diff --git a/src/Kiota.Builder/Kiota.Builder.csproj b/src/Kiota.Builder/Kiota.Builder.csproj index d6ce9733ec..acad06c42b 100644 --- a/src/Kiota.Builder/Kiota.Builder.csproj +++ b/src/Kiota.Builder/Kiota.Builder.csproj @@ -47,7 +47,7 @@ - + diff --git a/src/Kiota.Builder/Plugins/AuthComparer.cs b/src/Kiota.Builder/Plugins/AuthComparer.cs index e5212d44de..61f85f16df 100644 --- a/src/Kiota.Builder/Plugins/AuthComparer.cs +++ b/src/Kiota.Builder/Plugins/AuthComparer.cs @@ -16,6 +16,6 @@ public bool Equals(Auth? x, Auth? y) public int GetHashCode([DisallowNull] Auth obj) { if (obj == null) return 0; - return obj.Type is null ? 0 : StringComparer.OrdinalIgnoreCase.GetHashCode(obj.Type.Value.ToString()) * 3; + return obj.Type is null ? 0 : StringComparer.OrdinalIgnoreCase.GetHashCode(obj.Type) * 3; } } diff --git a/src/Kiota.Builder/Plugins/PluginsGenerationService.cs b/src/Kiota.Builder/Plugins/PluginsGenerationService.cs index 78c2035864..394d4a274d 100644 --- a/src/Kiota.Builder/Plugins/PluginsGenerationService.cs +++ b/src/Kiota.Builder/Plugins/PluginsGenerationService.cs @@ -39,7 +39,6 @@ public PluginsGenerationService(OpenApiDocument document, OpenApiUrlTreeNode ope private static readonly OpenAPIRuntimeComparer _openAPIRuntimeComparer = new(); private const string ManifestFileNameSuffix = ".json"; private const string DescriptionPathSuffix = "openapi.yml"; - private const string OpenAIManifestFileName = "openai-plugins"; public async Task GenerateManifestAsync(CancellationToken cancellationToken = default) { // 1. cleanup any namings to be used later on. @@ -63,10 +62,10 @@ public async Task GenerateManifestAsync(CancellationToken cancellationToken = de foreach (var pluginType in Configuration.PluginTypes) { - var manifestFileName = pluginType == PluginType.OpenAI ? OpenAIManifestFileName : $"{Configuration.ClientClassName.ToLowerInvariant()}-{pluginType.ToString().ToLowerInvariant()}"; + var manifestFileName = $"{Configuration.ClientClassName.ToLowerInvariant()}-{pluginType.ToString().ToLowerInvariant()}"; var manifestOutputPath = Path.Combine(Configuration.OutputPath, $"{manifestFileName}{ManifestFileNameSuffix}"); #pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task - await using var fileStream = File.Create(manifestOutputPath, 4096); + await using var fileStream = pluginType == PluginType.OpenAI ? Stream.Null : File.Create(manifestOutputPath, 4096); await using var writer = new Utf8JsonWriter(fileStream, new JsonWriterOptions { Indented = true }); #pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task @@ -90,8 +89,7 @@ public async Task GenerateManifestAsync(CancellationToken cancellationToken = de apiManifest.Write(writer); break; case PluginType.OpenAI: - var pluginDocumentV1 = GetV1ManifestDocument(descriptionRelativePath); - pluginDocumentV1.Write(writer); + // OpenAI plugins have been retired and are no longer supported. They only require the OpenAPI description now. break; default: throw new NotImplementedException($"The {pluginType} plugin is not implemented."); @@ -129,29 +127,6 @@ private OpenApiDocument GetDocumentWithTrimmedComponentsAndResponses(OpenApiDocu return OpenApiFilterService.CreateFilteredDocument(doc, predicate); } - private PluginManifestDocument GetV1ManifestDocument(string 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); - return new PluginManifestDocument - { - SchemaVersion = "v1", - NameForHuman = OAIDocument.Info?.Title.CleanupXMLString(), - NameForModel = OAIDocument.Info?.Title.CleanupXMLString(), - DescriptionForHuman = descriptionForHuman, - DescriptionForModel = manifestInfo.DescriptionForModel ?? descriptionForHuman, - Auth = new V1AnonymousAuth(), - Api = new Api() - { - Type = ApiType.openapi, - URL = openApiDocumentPath - }, - ContactEmail = manifestInfo.ContactEmail, - LogoUrl = manifestInfo.LogoUrl, - LegalInfoUrl = manifestInfo.LegalUrl, - }; - } - private PluginManifestDocument GetManifestDocument(string openApiDocumentPath) { var (runtimes, functions) = GetRuntimesAndFunctionsFromTree(TreeNode, openApiDocumentPath); @@ -162,7 +137,6 @@ private PluginManifestDocument GetManifestDocument(string openApiDocumentPath) Schema = "https://aka.ms/json-schemas/copilot-extensions/v2.1/plugin.schema.json", SchemaVersion = "v2.1", NameForHuman = OAIDocument.Info?.Title.CleanupXMLString(), - // TODO name for model ??? DescriptionForHuman = descriptionForHuman, DescriptionForModel = manifestInfo.DescriptionForModel ?? descriptionForHuman, ContactEmail = manifestInfo.ContactEmail, diff --git a/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs b/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs index 9e3a3bd400..4d6d0cbf9b 100644 --- a/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs +++ b/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs @@ -91,7 +91,8 @@ public async Task GeneratesManifest(string inputPluginName, string expectedPlugi Assert.True(File.Exists(Path.Combine(outputDirectory, $"{expectedPluginName.ToLower()}-apiplugin.json"))); Assert.True(File.Exists(Path.Combine(outputDirectory, $"{expectedPluginName.ToLower()}-apimanifest.json"))); - Assert.True(File.Exists(Path.Combine(outputDirectory, OpenAIPluginFileName))); + // v1 plugins are not generated anymore + Assert.False(File.Exists(Path.Combine(outputDirectory, OpenAIPluginFileName))); Assert.True(File.Exists(Path.Combine(outputDirectory, $"{expectedPluginName.ToLower()}-openapi.yml"))); Assert.False(File.Exists(Path.Combine(outputDirectory, "manifest.json"))); Assert.False(File.Exists(Path.Combine(outputDirectory, "color.png"))); @@ -106,14 +107,6 @@ public async Task GeneratesManifest(string inputPluginName, string expectedPlugi Assert.Equal(2, resultingManifest.Document.Functions.Count);// all functions are generated despite missing operationIds Assert.Equal(expectedPluginName, resultingManifest.Document.Namespace);// namespace is cleaned up. Assert.Empty(resultingManifest.Problems);// no problems are expected with names - - // Validate the v1 plugin - var v1ManifestContent = await File.ReadAllTextAsync(Path.Combine(outputDirectory, OpenAIPluginFileName)); - using var v1JsonDocument = JsonDocument.Parse(v1ManifestContent); - var v1Manifest = PluginManifestDocument.Load(v1JsonDocument.RootElement); - Assert.NotNull(resultingManifest.Document); - Assert.Equal($"{expectedPluginName.ToLower()}-openapi.yml", v1Manifest.Document.Api.URL); - Assert.Empty(v1Manifest.Problems); } private const string ManifestFileName = "client-apiplugin.json"; private const string OpenAIPluginFileName = "openai-plugins.json";