Skip to content

Commit

Permalink
Fix odata.type key already exists error for MSgraph OAD (#5470)
Browse files Browse the repository at this point in the history
* Fix odata.type key already exists error for MSgraph OAD

* Add test for repeated property to not throw key already exist
  • Loading branch information
fey101 authored Sep 30, 2024
1 parent 31c9568 commit c52ca2e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Kiota.Builder/Plugins/PluginsGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Kiota.Builder.Configuration;
using Kiota.Builder.Extensions;
using Kiota.Builder.OpenApiExtensions;
using Microsoft.Kiota.Abstractions.Extensions;
using Microsoft.OpenApi.ApiManifest;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Services;
Expand Down Expand Up @@ -82,7 +81,7 @@ public async Task GenerateManifestAsync(CancellationToken cancellationToken = de
case PluginType.APIManifest:
var apiManifest = new ApiManifestDocument("application"); //TODO add application name

Check warning on line 82 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)
// pass empty config 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) ?? [], WorkingDirectory));
apiManifest.ApiDependencies[Configuration.ClientClassName] = Configuration.ToApiDependency(string.Empty, TreeNode?.GetRequestInfo().ToDictionary(static x => x.Key, static x => x.Value) ?? [], WorkingDirectory);
var publisherName = string.IsNullOrEmpty(OAIDocument.Info?.Contact?.Name)
? DefaultContactName
: OAIDocument.Info.Contact.Name;
Expand Down Expand Up @@ -183,7 +182,7 @@ private static OpenApiDocument InlineRequestBodyAllOf(OpenApiDocument openApiDoc
{
foreach (var property in apiSchema.Properties)
{
newSchema.Properties.Add(property.Key, property.Value);
newSchema.Properties.TryAdd(property.Key, property.Value);
}
}
if (apiSchema.MaxProperties is not null) newSchema.MaxProperties = apiSchema.MaxProperties;
Expand Down
20 changes: 20 additions & 0 deletions tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,26 @@ public static TheoryData<string, Action<OpenApiDocument, OpenApiDiagnostic>>
Assert.Equal(3, schema.Properties.Count);
}
},
// objects with repeated properties
{
"""
content:
application/json:
schema:
allOf: [
{type: object, properties: {a: {type: string}, b: {type: number}}},
{type: object, properties: {b: {type: number}}}
]
""", (slicedDocument, _) =>
{
Assert.NotNull(slicedDocument);
Assert.NotEmpty(slicedDocument.Paths);
var schema = slicedDocument.Paths["/test"].Operations[OperationType.Post].RequestBody
.Content["application/json"].Schema;
Assert.Equal("object", schema.Type);
Assert.Equal(2, schema.Properties.Count);
}
},
// AnyOf
{
"""
Expand Down

0 comments on commit c52ca2e

Please sign in to comment.