Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes the union deserializer code generation in Go #5618

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
12 changes: 8 additions & 4 deletions tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
baywet marked this conversation as resolved.
Show resolved Hide resolved
}).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",
Expand Down