diff --git a/src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs b/src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs index 0e725475c2..6b8f9aee1e 100644 --- a/src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs +++ b/src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs @@ -479,6 +479,8 @@ private static CodeTypeBase ConvertComposedTypeToWrapper(CodeClass codeClass, Co if (!supportsInnerClasses) { var @namespace = codeClass.GetImmediateParentOfType(); + if (@namespace.FindChildByName(codeComposedType.Name, false) is not null) + codeComposedType.Name = $"{codeComposedType.Name}Wrapper"; newClass = @namespace.AddClass(new CodeClass { Name = codeComposedType.Name, diff --git a/tests/Kiota.Builder.Tests/Refiners/PhpLanguageRefinerTests.cs b/tests/Kiota.Builder.Tests/Refiners/PhpLanguageRefinerTests.cs index 943a730ab2..9f5f755d91 100644 --- a/tests/Kiota.Builder.Tests/Refiners/PhpLanguageRefinerTests.cs +++ b/tests/Kiota.Builder.Tests/Refiners/PhpLanguageRefinerTests.cs @@ -235,4 +235,31 @@ public async Task ImportsClassForDiscriminatorReturns() await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.PHP }, root); Assert.Equal(2, modelClass.Usings.Count()); } + + [Fact] + public async Task RenamesComposedTypeWrapperWhenSimilarClassExistsInNamespace() + { + var model = new CodeClass + { + Name = "Union", + Kind = CodeClassKind.Model + }; + var parent = new CodeClass + { + Name = "Parent" + }; + root.AddClass(model, parent); + + var composedType = new CodeUnionType { Name = "Union" }; + composedType.AddType(new CodeType { Name = "string" }, new CodeType { Name = "int"}); + + var composedProperty = parent.AddProperty(new CodeProperty + { + Name = "property", + Type = composedType + }).First(); + + await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.PHP }, root); + Assert.NotNull(root.FindChildByName("UnionWrapper", false)); + } }