Skip to content

Commit

Permalink
Merge pull request microsoft#4927 from microsoft/andrueastman/Simports
Browse files Browse the repository at this point in the history
Adds missing TS imports
  • Loading branch information
baywet authored Jul 3, 2024
2 parents 8dc240c + 273309a commit ef10468
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ensures HashSet properties in `KiotaLock` maintain IgnoreCase comparer across runs [#4916](https://github.com/microsoft/kiota/issues/4916)
- Dropped `client base url set to` message when generating plugins. [#4905](https://github.com/microsoft/kiota/issues/4905)
- Emit `[GeneratedCode]` attribute for C# types. [#4907](https://github.com/microsoft/kiota/issues/4907)
- Fixes missing imports for `UntypedNode` for method parameter and return value scenarios. [#4925](https://github.com/microsoft/kiota/issues/4925)

## [1.15.0] - 2024-06-06

Expand Down
3 changes: 2 additions & 1 deletion src/Kiota.Builder/Refiners/TypeScriptRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ private static bool HasMultipartBody(CodeMethod m) =>
AbstractionsPackageName, true, "BackingStore", "BackedModel"),
new (static x => x is CodeMethod m && HasMultipartBody(m),
AbstractionsPackageName, MultipartBodyClassName, $"serialize{MultipartBodyClassName}"),
new (static x => x is CodeProperty prop && prop.IsOfKind(CodePropertyKind.Custom) && prop.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase),
new (static x => (x is CodeProperty prop && prop.IsOfKind(CodePropertyKind.Custom) && prop.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase))
|| (x is CodeMethod method && (method.Parameters.Any(param => param.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase)) || method.ReturnType.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase))),
AbstractionsPackageName, KiotaBuilder.UntypedNodeName, "createUntypedNodeFromDiscriminatorValue"),
};
private const string MultipartBodyClassName = "MultipartBody";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,5 +840,55 @@ public async Task AddsUsingForUntypedNode()
Assert.Single(nodeUsing);
Assert.Equal("@microsoft/kiota-abstractions", nodeUsing[0].Declaration.Name);
}
[Fact]
public async Task AddsUsingForUntypedNodeInReturnType()
{
var requestBuilderClass = root.AddClass(new CodeClass() { Name = "NodeRequestBuilder" }).First();
var model = new CodeMethod
{
Name = "getAsync",
ReturnType = new CodeType
{
Name = KiotaBuilder.UntypedNodeName
}
};
requestBuilderClass.AddMethod(model);
await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.TypeScript }, root);
Assert.Equal(KiotaBuilder.UntypedNodeName, model.ReturnType.Name);// type is renamed
Assert.NotEmpty(requestBuilderClass.StartBlock.Usings);
var nodeUsing = requestBuilderClass.StartBlock.Usings.Where(static declaredUsing => declaredUsing.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase)).ToArray();
Assert.Single(nodeUsing);
Assert.Equal("@microsoft/kiota-abstractions", nodeUsing[0].Declaration.Name);
}
[Fact]
public async Task AddsUsingForUntypedNodeInMethodParameter()
{
var requestBuilderClass = root.AddClass(new CodeClass() { Name = "NodeRequestBuilder" }).First();
var method = new CodeMethod
{
Name = "getAsync",
ReturnType = new CodeType
{
Name = "string",
IsExternal = true
}
};
method.AddParameter(new CodeParameter()
{
Name = "jsonData",
Type = new CodeType()
{
Name = KiotaBuilder.UntypedNodeName,
IsExternal = true
}
});
requestBuilderClass.AddMethod(method);
await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.TypeScript }, root);
Assert.Equal(KiotaBuilder.UntypedNodeName, method.Parameters.First().Type.Name);// type is renamed
Assert.NotEmpty(requestBuilderClass.StartBlock.Usings);
var nodeUsing = requestBuilderClass.StartBlock.Usings.Where(static declaredUsing => declaredUsing.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase)).ToArray();
Assert.Single(nodeUsing);
Assert.Equal("@microsoft/kiota-abstractions", nodeUsing[0].Declaration.Name);
}
#endregion
}

0 comments on commit ef10468

Please sign in to comment.