diff --git a/CHANGELOG.md b/CHANGELOG.md index 99c931129a..e8d8c116a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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) ## [1.13.0] - 2024-04-04 diff --git a/src/Kiota.Builder/Configuration/GenerationConfiguration.cs b/src/Kiota.Builder/Configuration/GenerationConfiguration.cs index 4a22c24b8a..79d426987c 100644 --- a/src/Kiota.Builder/Configuration/GenerationConfiguration.cs +++ b/src/Kiota.Builder/Configuration/GenerationConfiguration.cs @@ -179,11 +179,14 @@ public ApiDependency ToApiDependency(string configurationHash, Dictionary x.Value.Select(y => new RequestInfo { Method = y.ToUpperInvariant(), UriTemplate = x.Key.DeSanitizeUrlTemplateParameter() })).ToList(), }; + + if (!string.IsNullOrEmpty(configurationHash)) + { + dependency.Extensions.Add(KiotaHashManifestExtensionKey, JsonValue.Create(configurationHash));// only include non empty value. + } return dependency; } public bool IsPluginConfiguration => PluginTypes.Count != 0; diff --git a/src/Kiota.Builder/Plugins/PluginsGenerationService.cs b/src/Kiota.Builder/Plugins/PluginsGenerationService.cs index 09f073b182..93cc546e55 100644 --- a/src/Kiota.Builder/Plugins/PluginsGenerationService.cs +++ b/src/Kiota.Builder/Plugins/PluginsGenerationService.cs @@ -66,7 +66,8 @@ public async Task GenerateManifestAsync(CancellationToken cancellationToken = de break; case PluginType.APIManifest: var apiManifest = new ApiManifestDocument("application"); //TODO add application name - apiManifest.ApiDependencies.AddOrReplace(Configuration.ClientClassName, Configuration.ToApiDependency(OAIDocument.HashCode ?? string.Empty, TreeNode?.GetRequestInfo().ToDictionary(static x => x.Key, static x => x.Value) ?? [])); + // pass empty cong hash so that its not included in this manifest. + apiManifest.ApiDependencies.AddOrReplace(Configuration.ClientClassName, Configuration.ToApiDependency(string.Empty, TreeNode?.GetRequestInfo().ToDictionary(static x => x.Key, static x => x.Value) ?? [])); apiManifest.Write(writer); break; case PluginType.OpenAI://TODO add support for OpenAI plugin type generation diff --git a/tests/Kiota.Builder.Tests/Configuration/GenerationConfigurationTests.cs b/tests/Kiota.Builder.Tests/Configuration/GenerationConfigurationTests.cs index 0ef9d2f6d1..6e3e95e9b5 100644 --- a/tests/Kiota.Builder.Tests/Configuration/GenerationConfigurationTests.cs +++ b/tests/Kiota.Builder.Tests/Configuration/GenerationConfigurationTests.cs @@ -36,9 +36,30 @@ public void ToApiDependency() { "foo/bar", new HashSet{"GET"}} }); Assert.NotNull(apiDependency); + Assert.NotNull(apiDependency.Extensions); Assert.Equal("foo", apiDependency.Extensions[GenerationConfiguration.KiotaHashManifestExtensionKey].GetValue()); Assert.NotEmpty(apiDependency.Requests); Assert.Equal("foo/bar", apiDependency.Requests[0].UriTemplate); Assert.Equal("GET", apiDependency.Requests[0].Method); } + [Fact] + public void ToApiDependencyDoesNotIncludeConfigHashIfEmpty() + { + var generationConfiguration = new GenerationConfiguration + { + ClientClassName = "class1", + IncludePatterns = null, + OpenAPIFilePath = "https://pet.store/openapi.yaml", + ApiRootUrl = "https://pet.store/api", + }; + var apiDependency = generationConfiguration.ToApiDependency(string.Empty, new Dictionary>{ + { "foo/bar", new HashSet{"GET"}} + }); + Assert.NotNull(apiDependency); + Assert.NotNull(apiDependency.Extensions); + Assert.False(apiDependency.Extensions.ContainsKey(GenerationConfiguration.KiotaHashManifestExtensionKey)); + Assert.NotEmpty(apiDependency.Requests); + Assert.Equal("foo/bar", apiDependency.Requests[0].UriTemplate); + Assert.Equal("GET", apiDependency.Requests[0].Method); + } }