Skip to content

Commit

Permalink
Merge pull request #5106 from Kindest13/fix/typescript-process-null-v…
Browse files Browse the repository at this point in the history
…alues

Fix: Typescript process null values
  • Loading branch information
baywet authored Aug 13, 2024
2 parents 4e9a9ab + b21ee35 commit 1762552
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fixed an issue where models would be missing when they had no properties and a single allOf entry. [#5014](https://github.com/microsoft/kiota/issues/5014)
- Reverts modification of responses in output openApi file when generating plugins [#4945](https://github.com/microsoft/kiota/issues/4945)
- Expand properties types with null type for Typescript. [#4993](https://github.com/microsoft/kiota-typescript/issues/1188)

## [1.17.0] - 2024-08-09

Expand Down
6 changes: 5 additions & 1 deletion src/Kiota.Builder/Writers/TypeScript/CodePropertyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ private static void WriteCodePropertyForInterface(CodeProperty codeElement, Lang
case CodePropertyKind.RequestBuilder:
writer.WriteLine($"get {codeElement.Name.ToFirstCharacterLowerCase()}(): {returnType};");
break;
default:
case CodePropertyKind.QueryParameter:
case CodePropertyKind.AdditionalData:
writer.WriteLine($"{codeElement.Name.ToFirstCharacterLowerCase()}?: {returnType}{(isFlagEnum ? "[]" : string.Empty)};");
break;
default:
writer.WriteLine($"{codeElement.Name.ToFirstCharacterLowerCase()}?: {returnType}{(isFlagEnum ? "[]" : string.Empty)} | null;");
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public void WritesRequestBuilder()
Assert.DoesNotContain("?", result, StringComparison.OrdinalIgnoreCase);
}
[Fact]
public void WritesCustomProperty()
public void WritesCustomPropertyWithDefaultedNullType()
{
property.Kind = CodePropertyKind.Custom;
writer.Write(property);
var result = tw.ToString();
Assert.Contains($"{PropertyName}?: {TypeName}", result);
Assert.Contains($"{PropertyName}?: {TypeName} | null", result);
Assert.DoesNotContain("| undefined", result); // redundant with ?
}
[Fact]
Expand Down

0 comments on commit 1762552

Please sign in to comment.