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

fix; missing null declaration for ts serialization #5163

Merged
merged 4 commits into from
Aug 15, 2024
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
2 changes: 2 additions & 0 deletions src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
} param)
throw new InvalidOperationException("Interface parameter not found for code interface");

writer.StartBlock($"if ({param.Name.ToFirstCharacterLowerCase()}) {{");
if (codeInterface.StartBlock.Implements.FirstOrDefault(static x => x.TypeDefinition is CodeInterface) is CodeType inherits)
{
writer.WriteLine($"serialize{inherits.TypeDefinition!.Name.ToFirstCharacterUpperCase()}(writer, {param.Name.ToFirstCharacterLowerCase()})");
Expand All @@ -151,6 +152,7 @@

if (codeInterface.GetPropertyOfKind(CodePropertyKind.AdditionalData) is CodeProperty additionalDataProperty)
writer.WriteLine($"writer.writeAdditionalData({codeInterface.Name.ToFirstCharacterLowerCase()}.{additionalDataProperty.Name.ToFirstCharacterLowerCase()});");
writer.CloseBlock();
}

private static bool IsCodePropertyCollectionOfEnum(CodeProperty property)
Expand Down Expand Up @@ -213,7 +215,7 @@
return null;
}

private void WriteDeserializerFunction(CodeFunction codeFunction, LanguageWriter writer)

Check warning on line 218 in src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 24 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 218 in src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 24 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
if (codeFunction.OriginalLocalMethod.Parameters.FirstOrDefault() is CodeParameter param && param.Type is CodeType codeType && codeType.TypeDefinition is CodeInterface codeInterface)
{
Expand Down Expand Up @@ -275,7 +277,7 @@
writer.WriteLine($"if(!{parameterName}) throw new Error(\"{parameterName} cannot be undefined\");");
}
}
private string GetDeserializationMethodName(CodeTypeBase propType, CodeFunction codeFunction)

Check warning on line 280 in src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 280 in src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
var isCollection = propType.CollectionKind != CodeTypeBase.CodeTypeCollectionKind.None;
var propertyType = conventions.GetTypeString(propType, codeFunction, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public override string GetParameterSignature(CodeParameter parameter, CodeElemen
var paramType = GetTypeString(parameter.Type, targetElement);
var defaultValueSuffix = (string.IsNullOrEmpty(parameter.DefaultValue), parameter.Kind) switch
{
(false, CodeParameterKind.DeserializationTarget) when parameter.Parent is CodeMethod codeMethod && codeMethod.Kind is CodeMethodKind.Serializer
=> $" | null = {parameter.DefaultValue}",
(false, CodeParameterKind.DeserializationTarget) => $" = {parameter.DefaultValue}",
(false, _) => $" = {parameter.DefaultValue} as {paramType}",
(true, _) => string.Empty,
Expand Down
Loading