Skip to content

Commit

Permalink
use SelectMany for AllOf flattening loop
Browse files Browse the repository at this point in the history
  • Loading branch information
calebkiage committed Sep 6, 2024
1 parent d98569d commit aa7065c
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/Kiota.Builder/Plugins/PluginsGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,16 @@ public async Task GenerateManifestAsync(CancellationToken cancellationToken = de
private static OpenApiDocument InlineRequestBodyAllOf(OpenApiDocument openApiDocument)
{
if (openApiDocument.Paths is null) return openApiDocument;
foreach (var path in openApiDocument.Paths.Values.Where(static x => x?.Operations is not null))
var contentItems = openApiDocument.Paths.Values.Where(static x => x?.Operations is not null)
.SelectMany(static x => x.Operations.Values.Where(static x => x?.RequestBody?.Content is not null)
.SelectMany(static x => x.RequestBody.Content.Values));
foreach (var contentItem in contentItems)
{
foreach (var operation in path.Operations.Values.Where(static x => x?.RequestBody?.Content is not null))
{
foreach (var contentItem in operation.RequestBody.Content.Values)
{
var schema = contentItem.Schema;
// Merge all schemas in allOf `schema.MergeAllOfSchemaEntries()` doesn't seem to do the right thing.
schema = MergeAllOfInSchema(schema);
schema = SelectFirstAnyOfOrOneOf(schema);
contentItem.Schema = schema;
}
}
var schema = contentItem.Schema;
// Merge all schemas in allOf `schema.MergeAllOfSchemaEntries()` doesn't seem to do the right thing.
schema = MergeAllOfInSchema(schema);
schema = SelectFirstAnyOfOrOneOf(schema);
contentItem.Schema = schema;
}

return openApiDocument;
Expand Down

0 comments on commit aa7065c

Please sign in to comment.