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 bitwise enum serialization in typescript. #3261

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Work around a System.ComandLine bug where adjacent matching command names would crash the CLI parser (CLI). [microsoftgraph/msgraph-cli#316](https://github.com/microsoftgraph/msgraph-cli/issues/316) [microsoftgraph/msgraph-cli#320](https://github.com/microsoftgraph/msgraph-cli/issues/320), [dotnet/command-line-api#2260](https://github.com/dotnet/command-line-api/issues/2260)
- Aggregate typescript import statements by source [#3232](https://github.com/microsoft/kiota/issues/3232)
- Fixes a bug in dotnet where enums types would not be fully disambiguated when initialized in constructor with default values and existing conflicting property exists [#3233]
- Fixes a bug in generation of flagged enum properties and their serializer/deserializer functions in typescript [https://github.com/microsoft/kiota/issues/3260]

## [1.5.1] - 2023-08-08

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private string GetSerializationMethodName(CodeTypeBase propType)
private string? GetSerializationMethodNameForCodeType(CodeType propType, string propertyType)
{
if (propType.TypeDefinition is CodeEnum currentEnum)
return $"writeEnumValue<{currentEnum.Name.ToFirstCharacterUpperCase()}>";
return $"writeEnumValue<{currentEnum.Name.ToFirstCharacterUpperCase()}{(currentEnum.Flags && !propType.IsCollection ? "[]" : string.Empty)}>";
else if (conventions.StreamTypeName.Equals(propertyType, StringComparison.OrdinalIgnoreCase))
return "writeByteArrayValue";
else if (propType.CollectionKind != CodeTypeBase.CodeTypeCollectionKind.None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public override void WriteCodeElement(CodeProperty codeElement, LanguageWriter w
if (codeElement.ExistsInExternalBaseType)
return;
var returnType = conventions.GetTypeString(codeElement.Type, codeElement);
var isFlagEnum = codeElement.Type is CodeType currentType && currentType.TypeDefinition is CodeEnum currentEnum && currentEnum.Flags;
var isFlagEnum = codeElement.Type is CodeType { TypeDefinition: CodeEnum { Flags: true } }
&& !codeElement.Type.IsCollection;//collection of flagged enums are not supported/don't make sense

conventions.WriteLongDescription(codeElement, writer);
switch (codeElement.Parent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,23 @@ public void WritesFlagEnums()
var result = tw.ToString();
Assert.Contains("[]", result);
}
[Fact]
public void WritesCollectionFlagEnumsAsOneDimensionalArray()
{
property.Kind = CodePropertyKind.Custom;
property.Type = new CodeType
{
Name = "customEnum",
CollectionKind = CodeTypeBase.CodeTypeCollectionKind.Array
};
(property.Type as CodeType).TypeDefinition = new CodeEnum
{
Name = "customEnumType",
Flags = true,//this is not expected for a collection. So treat as enum collection
};
writer.Write(property);
var result = tw.ToString();
Assert.Contains("[]", result);
Assert.DoesNotContain("[] []", result);
}
}