diff --git a/CHANGELOG.md b/CHANGELOG.md index 23ea913175..d02c06c805 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Fixed an issue where when generating Go code the deserializer for unions was using `CodeClass` as a filter and not `CodeInterface`. [#4844](https://github.com/microsoft/kiota/issues/4844) - Fixes mapping of `int16` format to the `integer` type rather than `double` when the type is `integer` or `number` [#5611](https://github.com/microsoft/kiota/issues/5611) ## [1.19.1] - 2024-10-11 diff --git a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs index 8a50297c80..59a288062b 100644 --- a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs @@ -632,7 +632,7 @@ private static void WriteDeserializerBodyForUnionModel(CodeMethod method, CodeCl var otherPropGetters = parentClass .GetPropertiesOfKind(CodePropertyKind.Custom) .Where(static x => !x.ExistsInBaseType && x.Getter != null) - .Where(static x => x.Type is CodeType propertyType && !propertyType.IsCollection && propertyType.TypeDefinition is CodeClass) + .Where(static x => x.Type is CodeType propertyType && !propertyType.IsCollection && propertyType.TypeDefinition is CodeInterface) .OrderBy(static x => x, CodePropertyTypeForwardComparer) .ThenBy(static x => x.Name) .Select(static x => x.Getter!.Name.ToFirstCharacterUpperCase()) diff --git a/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs index 771c815782..885af77aae 100644 --- a/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs @@ -291,16 +291,20 @@ private void AddSerializationBackingStoreMethods() } private CodeClass AddUnionTypeWrapper() { - var complexType1 = root.AddClass(new CodeClass + var complexType1 = root.AddInterface(new CodeInterface { Name = "ComplexType1", - Kind = CodeClassKind.Model, + Kind = CodeInterfaceKind.Model, + OriginalClass = new CodeClass { Name = "ComplexType1", Kind = CodeClassKind.Model } }).First(); - var complexType2 = root.AddClass(new CodeClass + + var complexType2 = root.AddInterface(new CodeInterface { Name = "ComplexType2", - Kind = CodeClassKind.Model, + Kind = CodeInterfaceKind.Model, + OriginalClass = new CodeClass { Name = "ComplexType2", Kind = CodeClassKind.Model } }).First(); + var unionTypeWrapper = root.AddClass(new CodeClass { Name = "UnionTypeWrapper",