From 2734a5f78b66eb53c7a132ba7fe49e043b9dad52 Mon Sep 17 00:00:00 2001 From: koros Date: Mon, 23 Oct 2023 18:08:12 +0300 Subject: [PATCH 1/3] restore backing store feature for typescript --- src/Kiota.Builder/Refiners/TypeScriptRefiner.cs | 8 ++++++-- .../Writers/TypeScript/CodeFunctionWriter.cs | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs b/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs index 24acfba6cc..3a9e2c6f5f 100644 --- a/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs +++ b/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs @@ -10,6 +10,7 @@ namespace Kiota.Builder.Refiners; public class TypeScriptRefiner : CommonLanguageRefiner, ILanguageRefiner { + public static readonly string BackingStoreEnabledKey = "backingStoreEnabled"; public TypeScriptRefiner(GenerationConfiguration configuration) : base(configuration) { } public override Task Refine(CodeNamespace generatedCode, CancellationToken cancellationToken) { @@ -66,7 +67,7 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance CodePropertyKind.AdditionalData, }, static (_, s) => s.ToCamelCase(UnderscoreArray), - _configuration.UsesBackingStore, + false, false, string.Empty, string.Empty); @@ -393,7 +394,10 @@ private static void CorrectPropertyType(CodeProperty currentProperty) if (currentProperty.IsOfKind(CodePropertyKind.RequestAdapter)) currentProperty.Type.Name = "RequestAdapter"; else if (currentProperty.IsOfKind(CodePropertyKind.BackingStore)) - currentProperty.Type.Name = currentProperty.Type.Name[1..]; // removing the "I" + { + currentProperty.Type.Name = "boolean"; + currentProperty.Name = BackingStoreEnabledKey; + } else if (currentProperty.IsOfKind(CodePropertyKind.Options)) currentProperty.Type.Name = "RequestOption[]"; else if (currentProperty.IsOfKind(CodePropertyKind.Headers)) diff --git a/src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs b/src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs index fcc2ad4661..167eedc9f2 100644 --- a/src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs +++ b/src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs @@ -5,6 +5,7 @@ using System.Linq; using Kiota.Builder.CodeDOM; using Kiota.Builder.Extensions; +using static Kiota.Builder.Refiners.TypeScriptRefiner; namespace Kiota.Builder.Writers.TypeScript; @@ -184,7 +185,7 @@ private void WriteDeserializerFunction(CodeFunction codeFunction, LanguageWriter { if (codeFunction.OriginalLocalMethod.Parameters.FirstOrDefault() is CodeParameter param && param.Type is CodeType codeType && codeType.TypeDefinition is CodeInterface codeInterface) { - var properties = codeInterface.Properties.Where(static x => x.Kind == CodePropertyKind.Custom && !x.ExistsInBaseType); + var properties = codeInterface.Properties.Where(static x => x.IsOfKind(CodePropertyKind.Custom, CodePropertyKind.BackingStore) && !x.ExistsInBaseType); writer.StartBlock("return {"); if (codeInterface.StartBlock.Implements.FirstOrDefault(static x => x.TypeDefinition is CodeInterface) is CodeType type && type.TypeDefinition is CodeInterface inherits) @@ -206,7 +207,10 @@ private void WriteDeserializerFunction(CodeFunction codeFunction, LanguageWriter { var keyName = !string.IsNullOrWhiteSpace(otherProp.SerializationName) ? otherProp.SerializationName.ToFirstCharacterLowerCase() : otherProp.Name.ToFirstCharacterLowerCase(); var suffix = otherProp.Name.Equals(primaryErrorMappingKey, StringComparison.Ordinal) ? primaryErrorMapping : string.Empty; - writer.WriteLine($"\"{keyName}\": n => {{ {param.Name.ToFirstCharacterLowerCase()}.{otherProp.Name.ToFirstCharacterLowerCase()} = n.{GetDeserializationMethodName(otherProp.Type, codeFunction)};{suffix} }},"); + if (keyName.Equals(BackingStoreEnabledKey, StringComparison.Ordinal)) + writer.WriteLine($"\"{keyName}\": n => {{ {param.Name.ToFirstCharacterLowerCase()}.{otherProp.Name.ToFirstCharacterLowerCase()} = true;{suffix} }},"); + else + writer.WriteLine($"\"{keyName}\": n => {{ {param.Name.ToFirstCharacterLowerCase()}.{otherProp.Name.ToFirstCharacterLowerCase()} = n.{GetDeserializationMethodName(otherProp.Type, codeFunction)};{suffix} }},"); } writer.CloseBlock(); From e5086df9628a1b706cdb7265e7c5f26180a07b5c Mon Sep 17 00:00:00 2001 From: koros Date: Mon, 23 Oct 2023 18:19:11 +0300 Subject: [PATCH 2/3] Add changelog message --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0e61457df..b4a7f397f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix bug where import statements in typescript wasn't using import type notation for types that are erased at runtime. [#3190](https://github.com/microsoft/kiota/issues/3190) - The structured content type generation parameter now supports prioritization with `q=value` syntax. [#3377](https://github.com/microsoft/kiota/issues/3377) - Fixed bug where `Tilde` char convert to Enum member name properly in C#. [#3500](https://github.com/microsoft/kiota/issues/3500) +- Restore backing store feature for typescript. [#2613](https://github.com/microsoft/kiota/issues/2613) ## [1.7.0] - 2023-10-05 From 9d96594f3159eb738861fbb34cb1157b98ac5d5a Mon Sep 17 00:00:00 2001 From: koros Date: Mon, 23 Oct 2023 18:30:43 +0300 Subject: [PATCH 3/3] format code --- src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs b/src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs index 167eedc9f2..eab67836f9 100644 --- a/src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs +++ b/src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs @@ -185,7 +185,7 @@ private void WriteDeserializerFunction(CodeFunction codeFunction, LanguageWriter { if (codeFunction.OriginalLocalMethod.Parameters.FirstOrDefault() is CodeParameter param && param.Type is CodeType codeType && codeType.TypeDefinition is CodeInterface codeInterface) { - var properties = codeInterface.Properties.Where(static x => x.IsOfKind(CodePropertyKind.Custom, CodePropertyKind.BackingStore) && !x.ExistsInBaseType); + var properties = codeInterface.Properties.Where(static x => x.IsOfKind(CodePropertyKind.Custom, CodePropertyKind.BackingStore) && !x.ExistsInBaseType); writer.StartBlock("return {"); if (codeInterface.StartBlock.Implements.FirstOrDefault(static x => x.TypeDefinition is CodeInterface) is CodeType type && type.TypeDefinition is CodeInterface inherits)