diff --git a/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs b/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs index ffc3426e82..2326c74196 100644 --- a/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs @@ -16,10 +16,14 @@ public override void WriteCodeElement(CodeEnum codeElement, LanguageWriter write if (codeElement.Parent is CodeNamespace ns) writer.WriteLine($"package {ns.Name.GetLastNamespaceSegment().Replace("-", string.Empty, StringComparison.OrdinalIgnoreCase)}"); - writer.StartBlock("import ("); - foreach (var cUsing in codeElement.Usings.OrderBy(static x => x.Name, StringComparer.OrdinalIgnoreCase)) - writer.WriteLine($"\"{cUsing.Name}\""); - writer.CloseBlock(")"); + var usings = codeElement.Usings.OrderBy(static x => x.Name, StringComparer.OrdinalIgnoreCase).ToArray(); + if (usings.Length > 0) + { + writer.StartBlock("import ("); + foreach (var cUsing in usings) + writer.WriteLine($"\"{cUsing.Name}\""); + writer.CloseBlock(")"); + } var typeName = codeElement.Name.ToFirstCharacterUpperCase(); conventions.WriteShortDescription(codeElement, writer); diff --git a/tests/Kiota.Builder.Tests/Writers/Go/CodeEnumWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Go/CodeEnumWriterTests.cs index 85a0453853..39f8ce54af 100644 --- a/tests/Kiota.Builder.Tests/Writers/Go/CodeEnumWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Go/CodeEnumWriterTests.cs @@ -138,4 +138,21 @@ public void WritesEnumOptionDescription() Assert.Contains($"// {option.Documentation.DescriptionTemplate}", result); AssertExtensions.CurlyBracesAreClosed(result); } + [Fact] + public void DoesNotWriteImportOnEmptyImports() + { + var option = new CodeEnumOption + { + Documentation = new() + { + DescriptionTemplate = "Some option description", + }, + Name = "option1", + }; + currentEnum.AddOption(option); + writer.Write(currentEnum); + var result = tw.ToString(); + Assert.DoesNotContain("import", result); + AssertExtensions.CurlyBracesAreClosed(result); + } }