Skip to content

Commit

Permalink
Merge pull request #3543 from microsoft/feature/typescript/restore-ba…
Browse files Browse the repository at this point in the history
…cking-store-feature

Restore backing store feature for typescript
  • Loading branch information
koros authored Oct 23, 2023
2 parents 2557116 + 9d96594 commit ef1fd73
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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

Expand Down
8 changes: 6 additions & 2 deletions src/Kiota.Builder/Refiners/TypeScriptRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 6 additions & 2 deletions src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand All @@ -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();
Expand Down

0 comments on commit ef1fd73

Please sign in to comment.