From 307a41fa06a286e014287da74768e9e77a599e7e Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 30 Oct 2023 12:44:09 -0400 Subject: [PATCH] - fixes a serialization bug in typescript Signed-off-by: Vincent Biret --- CHANGELOG.md | 1 + src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs | 5 +++-- .../Writers/TypeScript/CodeFunctionWriterTests.cs | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da215b47c5..e65cf83f31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The lock file now contains the relative path to the description in case of local path. [#3151](https://github.com/microsoft/kiota/issues/3151) - Fixes a bug where query parameters would be missing in CSharp for ebc clients. [#3583](https://github.com/microsoft/kiota/issues/3583) - Fixed bug where base64url and decimal types would not be generated properly in Java. +- Fixed a bug where object properties would not be serialized in TypeScript. [#3596](https://github.com/microsoft/kiota/issues/3596) - Fixed bug where symbol name cleanup would not work on forward single quotes characters [#3426](https://github.com/microsoft/kiota/issues/3426). - Fixed a bug where a "models" API path segment in the description would derail generation. [#3400](https://github.com/microsoft/kiota/issues/3400) - Changes to the configuration of RequestInformation are preserved instead of being overwritten. [#3401](https://github.com/microsoft/kiota/pull/3401). diff --git a/src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs b/src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs index eab67836f9..c5b3c996a3 100644 --- a/src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs +++ b/src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs @@ -266,8 +266,9 @@ private string GetFactoryMethodName(CodeTypeBase targetClassType, CodeMethod cur private string? getSerializerAlias(CodeType propType, CodeFunction codeFunction, string propertySerializerName) { - if (propType.TypeDefinition?.Parent is not CodeNamespace parentNameSpace) return string.Empty; - var serializationFunction = parentNameSpace.FindChildByName(propertySerializerName); + if (propType.TypeDefinition?.GetImmediateParentOfType() is not CodeFile parentFile || + parentFile.FindChildByName(propertySerializerName, false) is not CodeFunction serializationFunction) + return string.Empty; return conventions.GetTypeString(new CodeType { TypeDefinition = serializationFunction }, codeFunction, false); } } diff --git a/tests/Kiota.Builder.Tests/Writers/TypeScript/CodeFunctionWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/TypeScript/CodeFunctionWriterTests.cs index 8150abc7c1..64299ec16f 100644 --- a/tests/Kiota.Builder.Tests/Writers/TypeScript/CodeFunctionWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/TypeScript/CodeFunctionWriterTests.cs @@ -315,6 +315,7 @@ public async Task WritesSerializerBody() Assert.Contains("writeStringValue", result); Assert.Contains("writeCollectionOfPrimitiveValues", result); Assert.Contains("writeCollectionOfObjectValues", result); + Assert.Contains("serializeSomeComplexType", result); Assert.Contains("writeEnumValue", result); Assert.Contains($"writer.writeAdditionalData", result); Assert.Contains("definedInParent", result, StringComparison.OrdinalIgnoreCase);