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: Unused strconv import in Go request builder #5920

Merged
merged 1 commit into from
Dec 18, 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
5 changes: 4 additions & 1 deletion src/Kiota.Builder/Refiners/GoRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public override Task RefineAsync(CodeNamespace generatedCode, CancellationToken
AddConstructorsForDefaultValues(
generatedCode,
true,
true, //forcing add as constructors are required for by factories
true, //forcing add as constructors are required for by factories
new[] { CodeClassKind.RequestConfiguration });
cancellationToken.ThrowIfCancellationRequested();
MakeModelPropertiesNullable(
Expand Down Expand Up @@ -744,6 +744,9 @@ private static void AddErrorAndStringsImportForEnums(CodeElement currentElement)
"Duration",
"TimeOnly",
"DateOnly",
"TimeSpan",
"Time",
"ISODuration",
"string",
"UUID",
"Guid"
Expand Down
41 changes: 41 additions & 0 deletions tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1303,5 +1303,46 @@ public async Task AddsUsingForUntypedNodeInMethodParameterAsync()
Assert.Single(nodeUsing);
Assert.Equal("github.com/microsoft/kiota-abstractions-go/serialization", nodeUsing[0].Declaration.Name);
}
[Theory]
[InlineData("ISODuration", false)]
[InlineData("DateOnly", false)]
[InlineData("TimeOnly", false)]
[InlineData("Time", false)]
[InlineData("DateTimeOffset", false)]
[InlineData("Guid", false)]
[InlineData("string", false)]
[InlineData("boolean", true)]
[InlineData("int64", true)]
[InlineData("integer", true)]
[InlineData("long", true)]
[InlineData("float", true)]
public async Task ImportsStrConvForRelevantTypesOnly(string pathParameterType, bool isImported)
{
var model = root.AddClass(new CodeClass
{
Name = "RequestBuilder",
Kind = CodeClassKind.RequestBuilder
}).First();
var constructor = model.AddMethod(new CodeMethod
{
Name = "NewRequestBuilder",
Kind = CodeMethodKind.Constructor,
ReturnType = new CodeType
{
Name = "void"
}
}).First();
constructor.AddParameter(new CodeParameter
{
Name = "daysInPast",
Kind = CodeParameterKind.Path,
Type = new CodeType
{
Name = pathParameterType
}
});
await ILanguageRefiner.RefineAsync(new GenerationConfiguration { Language = GenerationLanguage.Go }, root);
Assert.Equal(isImported, model.StartBlock.Usings.Any(static x => x.Declaration.Name.Equals("strconv", StringComparison.OrdinalIgnoreCase)));
}
#endregion
}
Loading