From e57c84fbe5da09c7917ff1ab6ee4e6f63fae397a Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 1 May 2024 12:33:20 -0400 Subject: [PATCH 1/2] - fixes manifest serialization --- CHANGELOG.md | 5 +++-- .../Plugins/PluginsGenerationService.cs | 2 +- .../Plugins/PluginsGenerationServiceTests.cs | 13 +++++++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e181101aeb..7269d8253c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,11 +15,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Fixed a bug where the Microsoft Plugin Manifests would start with relative paths. [#4583](https://github.com/microsoft/kiota/issues/4583) - Fixed a bug where TypeScript deserialization would fail on Uppercase properties.[#4479](https://github.com/microsoft/kiota/issues/4479) - Changed URI template generation to reuse templates when required templates are absent across operations. -- Fixed path deduplication logic to avoid double `Id` suffixes in indexer names in scenarios where the `Id` suffix is already present.[#4519](https://github.com/microsoft/kiota/issues/4519) +- Fixed path deduplication logic to avoid double `Id` suffixes in indexer names in scenarios where the `Id` suffix is already present.[#4519](https://github.com/microsoft/kiota/issues/4519) - Updated reserved name providers for Java and Php so that "object" can be escaped. -- Fixes request builder disambiguation when child nodes had different prefixes for different paths with same parameters.[#4448](https://github.com/microsoft/kiota/issues/4448) +- Fixes request builder disambiguation when child nodes had different prefixes for different paths with same parameters.[#4448](https://github.com/microsoft/kiota/issues/4448) - Do not generate CS8603 warnings when enabling backing store in CSharp generation. - Fixed excluding operation. [#4399](https://github.com/microsoft/kiota/issues/4399) - Fixed plugin generation of `ApiManifest` type to not include the `x-ms-kiota-hash` in the generated plugin. [#4561](https://github.com/microsoft/kiota/issues/4561) diff --git a/src/Kiota.Builder/Plugins/PluginsGenerationService.cs b/src/Kiota.Builder/Plugins/PluginsGenerationService.cs index 93cc546e55..1e66fce8f5 100644 --- a/src/Kiota.Builder/Plugins/PluginsGenerationService.cs +++ b/src/Kiota.Builder/Plugins/PluginsGenerationService.cs @@ -136,7 +136,7 @@ descriptionExtension is OpenApiDescriptionForModelExtension extension && Auth = new AnonymousAuth(), Spec = new OpenApiRuntimeSpec() { - Url = openApiDocumentPath + Url = openApiDocumentPath.TrimStart('.').TrimStart('/'), }, RunForFunctions = [operation.OperationId] }); diff --git a/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs b/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs index 77e2b4a638..01bd6ba8fc 100644 --- a/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs +++ b/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs @@ -1,11 +1,14 @@ using System; using System.IO; +using System.Linq; using System.Net.Http; +using System.Text.Json; using System.Threading.Tasks; using Kiota.Builder.Configuration; using Kiota.Builder.Plugins; using Microsoft.Extensions.Logging; using Microsoft.OpenApi.Services; +using Microsoft.Plugins.Manifest; using Moq; using Xunit; @@ -63,8 +66,14 @@ public async Task GeneratesManifest() var pluginsGenerationService = new PluginsGenerationService(openApiDocument, urlTreeNode, generationConfiguration); await pluginsGenerationService.GenerateManifestAsync(); - Assert.True(File.Exists(Path.Combine(outputDirectory, "client-microsoft.json"))); + Assert.True(File.Exists(Path.Combine(outputDirectory, ManifestFileName))); Assert.True(File.Exists(Path.Combine(outputDirectory, "client-apimanifest.json"))); - Assert.True(File.Exists(Path.Combine(outputDirectory, "openapi.yml"))); + Assert.True(File.Exists(Path.Combine(outputDirectory, OpenApiFileName))); + var manifestContent = await File.ReadAllTextAsync(Path.Combine(outputDirectory, ManifestFileName)); + using var jsonDocument = JsonDocument.Parse(manifestContent); + var resultingManifest = PluginManifestDocument.Load(jsonDocument.RootElement); + Assert.Equal(OpenApiFileName, resultingManifest.Document.Runtimes.OfType().First().Spec.Url); } + private const string ManifestFileName = "client-microsoft.json"; + private const string OpenApiFileName = "openapi.yml"; } From 393179b1f04e075816b712519e74772271db3536 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 1 May 2024 15:08:20 -0400 Subject: [PATCH 2/2] - code linting Signed-off-by: Vincent Biret --- src/Kiota.Builder/Plugins/PluginsGenerationService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Kiota.Builder/Plugins/PluginsGenerationService.cs b/src/Kiota.Builder/Plugins/PluginsGenerationService.cs index 1e66fce8f5..dc290eeced 100644 --- a/src/Kiota.Builder/Plugins/PluginsGenerationService.cs +++ b/src/Kiota.Builder/Plugins/PluginsGenerationService.cs @@ -33,7 +33,7 @@ public PluginsGenerationService(OpenApiDocument document, OpenApiUrlTreeNode ope } private static readonly OpenAPIRuntimeComparer _openAPIRuntimeComparer = new(); private const string ManifestFileNameSuffix = ".json"; - private const string DescriptionRelativePath = "./openapi.yml"; + private const string DescriptionRelativePath = "openapi.yml"; public async Task GenerateManifestAsync(CancellationToken cancellationToken = default) { // write the decription @@ -136,7 +136,7 @@ descriptionExtension is OpenApiDescriptionForModelExtension extension && Auth = new AnonymousAuth(), Spec = new OpenApiRuntimeSpec() { - Url = openApiDocumentPath.TrimStart('.').TrimStart('/'), + Url = openApiDocumentPath, }, RunForFunctions = [operation.OperationId] });