Skip to content

Commit

Permalink
Fixes aggressive flattening
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Omondi committed May 28, 2024
1 parent 4977588 commit a6feb0e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Extensions/OpenApiSchemaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static IEnumerable<string> GetSchemaNames(this OpenApiSchema schema, bool
internal static IEnumerable<OpenApiSchema> FlattenSchemaIfRequired(this IList<OpenApiSchema> schemas, Func<OpenApiSchema, IList<OpenApiSchema>> subsequentGetter)
{
if (schemas is null) return [];
return schemas.Count == 1 && !schemas[0].HasAnyProperty() ?
return schemas.Count == 1 && !schemas[0].HasAnyProperty() && string.IsNullOrEmpty(schemas[0].Reference?.Id) ?
schemas.FlattenEmptyEntries(subsequentGetter, 1) :
schemas;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ private CodeElement AddModelDeclarationIfDoesntExist(OpenApiUrlTreeNode currentN
if (AddEnumDeclaration(currentNode, schema, declarationName, currentNamespace) is CodeEnum enumDeclaration)
return enumDeclaration;

if (schema.IsIntersection() && schema.MergeIntersectionSchemaEntries() is {} mergedSchema &&
if (schema.IsIntersection() && schema.MergeIntersectionSchemaEntries() is { } mergedSchema &&
AddModelDeclarationIfDoesntExist(currentNode, currentOperation, mergedSchema, declarationName, currentNamespace, inheritsFrom) is CodeClass createdClass)
{
// multiple allOf entries that do not translate to inheritance
Expand Down
3 changes: 3 additions & 0 deletions tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7469,6 +7469,9 @@ public async Task InlineSchemaWithSingleAllOfReference()
var memberClass = codeModel.FindChildByName<CodeClass>("member");
Assert.NotNull(memberClass);
Assert.Equal(2, memberClass.Properties.Count());// single prop plus additionalData
var memberProperty = memberClass.Properties.FirstOrDefault(static x => x.Name.Equals("group", StringComparison.OrdinalIgnoreCase));
Assert.NotNull(memberProperty);
Assert.Equal("group", memberProperty.Type.Name);
Assert.Null(memberClass.StartBlock.Inherits);//no base
var userClass = codeModel.FindChildByName<CodeClass>("user");
Assert.NotNull(userClass);
Expand Down

0 comments on commit a6feb0e

Please sign in to comment.