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;