Skip to content

Commit

Permalink
Merge pull request #5618 from nickfloyd/fix-union-deserializer-go
Browse files Browse the repository at this point in the history
Fixes the union deserializer code generation in Go
  • Loading branch information
baywet authored Oct 16, 2024
2 parents 0eadf55 + e5f0bd2 commit f124023
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 }
}).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

0 comments on commit f124023

Please sign in to comment.