From 12373fa6388091af2af9c5f6bb51dc5ef852731a Mon Sep 17 00:00:00 2001 From: silaskenneth Date: Thu, 25 Apr 2024 15:52:48 +0300 Subject: [PATCH] Try to fix generation of multiple identical classes #4191 --- src/Kiota.Builder/KiotaBuilder.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Kiota.Builder/KiotaBuilder.cs b/src/Kiota.Builder/KiotaBuilder.cs index e067f7157e..329c594a05 100644 --- a/src/Kiota.Builder/KiotaBuilder.cs +++ b/src/Kiota.Builder/KiotaBuilder.cs @@ -1656,9 +1656,13 @@ private CodeTypeBase CreateModelDeclarations(OpenApiUrlTreeNode currentNode, Ope true => (GetShortestNamespace(parentElement.GetImmediateParentOfType(), schema), response, string.Empty), // referenced schema false => (parentElement.GetImmediateParentOfType(), null, suffixForInlineSchema), // Inline schema, i.e. specific to the Operation }; - // If typeNameForInlineSchema is not null and the schema is referenced, we have most likely unwrapped a referenced schema(most likely from an AllOf/OneOf/AnyOf). // Therefore the current type/schema is not really inlined, so invalidate the typeNameForInlineSchema and just work with the information from the schema reference. + if (schema.AllOf.Count == 1 && schema.Reference == null && !schema.Properties.Any()) + { + schema.Reference = schema.AllOf.First().Reference; + } + if (schema.IsReferencedSchema() && !string.IsNullOrEmpty(typeNameForInlineSchema)) { typeNameForInlineSchema = string.Empty;