Skip to content

Commit

Permalink
Merge pull request #5920 from microsoft/fix/go-unused-import
Browse files Browse the repository at this point in the history
fix: Unused strconv import in Go request builder
  • Loading branch information
Ndiritu authored Dec 18, 2024
2 parents 8971314 + 44f735b commit 12abd43
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
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
}

0 comments on commit 12abd43

Please sign in to comment.