From 319a2cdf5b9ecb76bb192da29b4d9bf5e78975f2 Mon Sep 17 00:00:00 2001 From: Nick Floyd Date: Wed, 16 Oct 2024 13:20:47 -0500 Subject: [PATCH 1/2] fixes union model deserialization --- src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs | 2 +- .../Writers/Go/CodeMethodWriterTests.cs | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) 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", From 2ff51c184514d118c71d8244cd16a8f6e872223d Mon Sep 17 00:00:00 2001 From: Nick Floyd Date: Wed, 16 Oct 2024 16:30:30 -0500 Subject: [PATCH 2/2] adds changelog for the update. --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20d47e2440..7518d63424 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ 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) + + ## [1.19.1] - 2024-10-11 ### Added