Skip to content

Commit

Permalink
Merge pull request #4567 from microsoft/andrueastman/fixPluginType
Browse files Browse the repository at this point in the history
Excluded kiota hash in generated plugin.
  • Loading branch information
andrueastman authored Apr 29, 2024
2 parents 21309af + e3c68f5 commit 7afc0e8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions src/Kiota.Builder/Configuration/GenerationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,14 @@ public ApiDependency ToApiDependency(string configurationHash, Dictionary<string
{
ApiDescriptionUrl = OpenAPIFilePath,
ApiDeploymentBaseUrl = ApiRootUrl?.EndsWith('/') ?? false ? ApiRootUrl : $"{ApiRootUrl}/",
Extensions = new() {
{ KiotaHashManifestExtensionKey, JsonValue.Create(configurationHash)}
},
Extensions = new(),
Requests = templatesWithOperations.SelectMany(static x => 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;
Expand Down
3 changes: 2 additions & 1 deletion src/Kiota.Builder/Plugins/PluginsGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public async Task GenerateManifestAsync(CancellationToken cancellationToken = de
break;
case PluginType.APIManifest:
var apiManifest = new ApiManifestDocument("application"); //TODO add application name

Check warning on line 68 in src/Kiota.Builder/Plugins/PluginsGenerationService.cs

View workflow job for this annotation

GitHub Actions / Build

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
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

Check warning on line 73 in src/Kiota.Builder/Plugins/PluginsGenerationService.cs

View workflow job for this annotation

GitHub Actions / Build

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,30 @@ public void ToApiDependency()
{ "foo/bar", new HashSet<string>{"GET"}}
});
Assert.NotNull(apiDependency);
Assert.NotNull(apiDependency.Extensions);
Assert.Equal("foo", apiDependency.Extensions[GenerationConfiguration.KiotaHashManifestExtensionKey].GetValue<string>());
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<string, HashSet<string>>{
{ "foo/bar", new HashSet<string>{"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);
}
}

0 comments on commit 7afc0e8

Please sign in to comment.