From 78ef3caecb767da1df6e70f6e4e670a7262ea62c Mon Sep 17 00:00:00 2001 From: firefart <105281+firefart@users.noreply.github.com> Date: Sun, 6 Apr 2025 08:39:54 +0000 Subject: [PATCH 01/35] fix devcontainer --- .devcontainer/devcontainer.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 70eb569548..ec4d3ecfb4 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -58,7 +58,10 @@ "ghcr.io/devcontainers-contrib/features/gradle-sdkman:2": {}, "ghcr.io/devcontainers/features/python:1": {}, "ghcr.io/devcontainers/features/go:1": {}, - "ghcr.io/devcontainers/features/java:1": {}, + "ghcr.io/devcontainers/features/java:1": { + // https://github.com/devcontainers/features/issues/1308 + "version": "23" + }, "ghcr.io/devcontainers/features/rust:1": {}, // disabled swift & ruby as their are failing for now "ghcr.io/devcontainers/features/powershell:1": {} From d5d258830fb7b852c3a1f15e2b7e633234ea05c9 Mon Sep 17 00:00:00 2001 From: firefart <105281+firefart@users.noreply.github.com> Date: Sun, 6 Apr 2025 09:39:47 +0000 Subject: [PATCH 02/35] remove brackets on return types when there is only one --- src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs index ea026bd4c8..f64eb3697d 100644 --- a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs @@ -469,11 +469,16 @@ private void WriteMethodPrototype(CodeMethod code, CodeElement parentBlock, Lang CodeMethodKind.ErrorMessageOverride) || code.IsAsync ? string.Empty : "error"; - if (!string.IsNullOrEmpty(finalReturnType) && !string.IsNullOrEmpty(errorDeclaration)) - finalReturnType += ", "; var openingBracket = writePrototypeOnly ? string.Empty : " {"; var funcPrefix = writePrototypeOnly ? string.Empty : "func "; - writer.WriteLine($"{funcPrefix}{associatedTypePrefix}{methodName}({parameters})({finalReturnType}{errorDeclaration}){openingBracket}"); + var returnTypeString = (finalReturnType, errorDeclaration) switch + { + _ when !string.IsNullOrEmpty(finalReturnType) && !string.IsNullOrEmpty(errorDeclaration) => $"({finalReturnType}, {errorDeclaration})", + _ when string.IsNullOrEmpty(finalReturnType) && !string.IsNullOrEmpty(errorDeclaration) => errorDeclaration, + _ when !string.IsNullOrEmpty(finalReturnType) && string.IsNullOrEmpty(errorDeclaration) => finalReturnType, + _ => string.Empty + }; + writer.WriteLine($"{funcPrefix}{associatedTypePrefix}{methodName}({parameters}) {returnTypeString}{openingBracket}"); } private void WriteGetterBody(CodeMethod codeElement, LanguageWriter writer, CodeClass parentClass) { From 9f610d59d944407f18fda940d0957a4235c264c7 Mon Sep 17 00:00:00 2001 From: firefart <105281+firefart@users.noreply.github.com> Date: Sun, 6 Apr 2025 09:43:22 +0000 Subject: [PATCH 03/35] replace and remove deprecated extensions --- .devcontainer/devcontainer.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ec4d3ecfb4..eb548b0e66 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -41,13 +41,12 @@ "kosunix.guid", "wix.vscode-import-cost", "ms-vsliveshare.vsliveshare", - "eg2.vscode-npm-script", "fknop.vscode-npm", "ms-vscode.powershell", - "rebornix.ruby", + "Shopify.ruby-lsp", "visualstudioexptteam.vscodeintellicode", "streetsidesoftware.code-spell-checker", - "sswg.swift-lang", + "swiftlang.swift-vscode", "ms-dotnettools.blazorwasm-companion" ] } From ea19d2b3e86d27a33867fe77e0d70a7aefad0db2 Mon Sep 17 00:00:00 2001 From: firefart <105281+firefart@users.noreply.github.com> Date: Sun, 6 Apr 2025 10:24:09 +0000 Subject: [PATCH 04/35] use tabs instead of spaces --- src/Kiota.Builder/Writers/Go/GoWriter.cs | 22 ++++++++++++++++++++- src/Kiota.Builder/Writers/LanguageWriter.cs | 6 +++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Kiota.Builder/Writers/Go/GoWriter.cs b/src/Kiota.Builder/Writers/Go/GoWriter.cs index eec90e228a..606db767fc 100644 --- a/src/Kiota.Builder/Writers/Go/GoWriter.cs +++ b/src/Kiota.Builder/Writers/Go/GoWriter.cs @@ -1,4 +1,6 @@ -using Kiota.Builder.PathSegmenters; +using System; +using System.Linq; +using Kiota.Builder.PathSegmenters; namespace Kiota.Builder.Writers.Go; public class GoWriter : LanguageWriter @@ -16,4 +18,22 @@ public GoWriter(string rootPath, string clientNamespaceName, bool excludeBackwar AddOrReplaceCodeElementWriter(new CodeFileBlockEndWriter()); AddOrReplaceCodeElementWriter(new CodeFileDeclarationWriter(conventionService)); } + + // Override the Ident functions as golang indents with tabs instead of spaces + private int currentIndent; + private static readonly string indentString = Enumerable.Repeat("\t", 1000).Aggregate(static (x, y) => x + y); + public override void IncreaseIndent(int factor = 1) + { + currentIndent += 1; + } + + public override void DecreaseIndent() + { + currentIndent -= 1; + } + + public override string GetIndent() + { + return indentString[..Math.Max(0, currentIndent)]; + } } diff --git a/src/Kiota.Builder/Writers/LanguageWriter.cs b/src/Kiota.Builder/Writers/LanguageWriter.cs index d181eb5ba1..2072e89f2a 100644 --- a/src/Kiota.Builder/Writers/LanguageWriter.cs +++ b/src/Kiota.Builder/Writers/LanguageWriter.cs @@ -43,19 +43,19 @@ public IPathSegmenter? PathSegmenter } private readonly Stack factorStack = new(); - public void IncreaseIndent(int factor = 1) + public virtual void IncreaseIndent(int factor = 1) { factorStack.Push(factor); currentIndent += IndentSize * factor; } - public void DecreaseIndent() + public virtual void DecreaseIndent() { var popped = factorStack.TryPop(out var factor); currentIndent -= IndentSize * (popped ? factor : 1); } - public string GetIndent() + public virtual string GetIndent() { return indentString[..Math.Max(0, currentIndent)]; } From 762b0641a7cf006a44cbe6c95a61e550da44c5e2 Mon Sep 17 00:00:00 2001 From: firefart <105281+firefart@users.noreply.github.com> Date: Sun, 6 Apr 2025 23:01:51 +0200 Subject: [PATCH 05/35] update changelog --- CHANGELOG.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2e24fc728..31595df04c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,16 +14,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Fixed a bug where Dart properties casing would change for serialization. +- golang: indent with tabs instead of spaces +- golang: if there is only one return argument, omit the parentheses ## [1.25.1] - 2025-04-03 ### Changed + - Fixed a bug with http client generation where query parameters were being processed incorrectly. [#6268](https://github.com/microsoft/kiota/issues/6268) ### Added + - Extracted and created an npm package from the VS Code - Kiota interop module. [#6172](https://github.com/microsoft/kiota/pull/6172) -- Added support for generating function capabilities in plugin manifest from x-ai-capabilities OpenApi extension. [#6369](https://github.com/microsoft/kiota/issues/6369) +- Added support for generating function capabilities in plugin manifest from x-ai-capabilities OpenApi extension. [#6369](https://github.com/microsoft/kiota/issues/6369) - Added a comment on top of every golang file to indicate the file is machine generated so it can be excluded from various tools. [#6363](https://github.com/microsoft/kiota/issues/6363) @@ -131,7 +135,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed Python error when a class inherits from a base class and implements an interface. [#5637](https://github.com/microsoft/kiota/issues/5637) - Fixed a bug where one/any schemas with single schema entries would be missing properties. [#5808](https://github.com/microsoft/kiota/issues/5808) - Fixed anyOf/oneOf generation in TypeScript. [5353](https://github.com/microsoft/kiota/issues/5353) -- Fixed invalid code in Php caused by "*/*/" in property description. [5635](https://github.com/microsoft/kiota/issues/5635) +- Fixed invalid code in Php caused by "_/_/" in property description. [5635](https://github.com/microsoft/kiota/issues/5635) - Fixed a bug where discriminator property name lookup could end up in an infinite loop. [#5771](https://github.com/microsoft/kiota/issues/5771) - Fixed TypeScript generation error when generating usings from shaken serializers. [#5634](https://github.com/microsoft/kiota/issues/5634) - Multiple fixed and improvements in OpenAPI description generation for plugins. [#5806](https://github.com/microsoft/kiota/issues/5806) @@ -272,7 +276,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added uri-form encoded serialization for PHP. [#2074](https://github.com/microsoft/kiota/issues/2074) - Added information message with base URL in the CLI experience. [#4635](https://github.com/microsoft/kiota/issues/4635) - Added optional parameter --disable-ssl-validation for generate, show, and download commands. [#4176](https://github.com/microsoft/kiota/issues/4176) -- For *Debug* builds of kiota, the `--log-level` / `--ll` option is now observed if specified explicitly on the command line. It still defaults to `Debug` for *Debug* builds and `Warning` for *Release* builds. [#4739](https://github.com/microsoft/kiota/pull/4739) +- For _Debug_ builds of kiota, the `--log-level` / `--ll` option is now observed if specified explicitly on the command line. It still defaults to `Debug` for _Debug_ builds and `Warning` for _Release_ builds. [#4739](https://github.com/microsoft/kiota/pull/4739) ### Changed @@ -874,7 +878,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed unused generated import for PHP Generation. - Fixed a bug where long namespaces would make Ruby packaging fail. - Fixed a bug where classes with namespace names are generated outside namespace in Python. [#2188](https://github.com/microsoft/kiota/issues/2188) -- Changed signature of escaped reserved names from {x}*escaped to {x}* in line with Python style guides. +- Changed signature of escaped reserved names from {x}_escaped to {x}_ in line with Python style guides. - Add null checks in generated Shell language code. - Fixed a bug where Go indexers would fail to pass the index parameter. - Fixed a bug where path segments with parameters could be missing words. [#2209](https://github.com/microsoft/kiota/issues/2209) @@ -1623,5 +1627,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Initial GitHub release - - From 6f4eb4f0f62562765404cc84fce0f272f197bde0 Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 11:35:19 +0000 Subject: [PATCH 06/35] add recommended c# devkit extension --- .devcontainer/devcontainer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index eb548b0e66..6d12cb395b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -47,7 +47,8 @@ "visualstudioexptteam.vscodeintellicode", "streetsidesoftware.code-spell-checker", "swiftlang.swift-vscode", - "ms-dotnettools.blazorwasm-companion" + "ms-dotnettools.blazorwasm-companion", + "ms-dotnettools.csdevkit" ] } }, From b8e41c52b1807f162d5ad0d923fb198ca06173e6 Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 11:50:09 +0000 Subject: [PATCH 07/35] also add github actions extension --- .devcontainer/devcontainer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 6d12cb395b..78f81c7e8d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -48,7 +48,8 @@ "streetsidesoftware.code-spell-checker", "swiftlang.swift-vscode", "ms-dotnettools.blazorwasm-companion", - "ms-dotnettools.csdevkit" + "ms-dotnettools.csdevkit", + "github.vscode-github-actions" ] } }, From 9d2165d1a62d127a8c9de77061c486b7fcf66561 Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 12:34:47 +0000 Subject: [PATCH 08/35] fix more code --- src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs index f64eb3697d..2d59e04e55 100644 --- a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs @@ -437,9 +437,6 @@ private void WriteSerializerBodyForIntersectionModel(CodeClass parentClass, Lang private void WriteMethodPrototype(CodeMethod code, CodeElement parentBlock, LanguageWriter writer, string returnType, bool writePrototypeOnly) { - var returnTypeAsyncSuffix = code.IsAsync ? "error" : string.Empty; - if (!string.IsNullOrEmpty(returnType) && code.IsAsync) - returnTypeAsyncSuffix = $", {returnTypeAsyncSuffix}"; var isConstructor = code.IsOfKind(CodeMethodKind.Constructor, CodeMethodKind.ClientConstructor, CodeMethodKind.RawUrlConstructor); var methodName = code.Kind switch { @@ -454,7 +451,7 @@ private void WriteMethodPrototype(CodeMethod code, CodeElement parentBlock, Lang var parameters = string.Join(", ", code.Parameters.OrderBy(x => x, ParameterOrderComparer).Select(p => conventions.GetParameterSignature(p, parentBlock)).ToList()); var classType = conventions.GetTypeString(new CodeType { Name = parentBlock.Name, TypeDefinition = parentBlock }, parentBlock); var associatedTypePrefix = isConstructor || code.IsStatic || writePrototypeOnly ? string.Empty : $"(m {classType}) "; - var finalReturnType = isConstructor ? classType : $"{returnType}{returnTypeAsyncSuffix}"; + var finalReturnType = isConstructor ? classType : returnType; var errorDeclaration = code.IsOfKind(CodeMethodKind.ClientConstructor, CodeMethodKind.Constructor, CodeMethodKind.Getter, @@ -471,8 +468,9 @@ private void WriteMethodPrototype(CodeMethod code, CodeElement parentBlock, Lang "error"; var openingBracket = writePrototypeOnly ? string.Empty : " {"; var funcPrefix = writePrototypeOnly ? string.Empty : "func "; - var returnTypeString = (finalReturnType, errorDeclaration) switch + var returnTypeString = (code, finalReturnType, errorDeclaration) switch { + _ when code.IsAsync && !string.IsNullOrEmpty(finalReturnType) => $"({finalReturnType}, error)", _ when !string.IsNullOrEmpty(finalReturnType) && !string.IsNullOrEmpty(errorDeclaration) => $"({finalReturnType}, {errorDeclaration})", _ when string.IsNullOrEmpty(finalReturnType) && !string.IsNullOrEmpty(errorDeclaration) => errorDeclaration, _ when !string.IsNullOrEmpty(finalReturnType) && string.IsNullOrEmpty(errorDeclaration) => finalReturnType, From 2c3cba15d7ddae64038f52b42731675cffe363de Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 12:42:19 +0000 Subject: [PATCH 09/35] more work --- it/go/app.go | 8 ++++---- src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/it/go/app.go b/it/go/app.go index 2f6a363bd3..9df30ce9e7 100644 --- a/it/go/app.go +++ b/it/go/app.go @@ -1,12 +1,12 @@ package integrationtest import ( - c "integrationtest/client" + "context" + "fmt" azidentity "github.com/Azure/azure-sdk-for-go/sdk/azidentity" a "github.com/microsoft/kiota-authentication-azure-go" r "github.com/microsoft/kiota-http-go" - "fmt" - "context" + c "integrationtest/client" ) func main() { @@ -33,4 +33,4 @@ func main() { } client := c.NewApiClient(adapter) fmt.Printf("Message: %v\n", client) -} \ No newline at end of file +} diff --git a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs index 2d59e04e55..4eadc3913b 100644 --- a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs @@ -466,7 +466,6 @@ private void WriteMethodPrototype(CodeMethod code, CodeElement parentBlock, Lang CodeMethodKind.ErrorMessageOverride) || code.IsAsync ? string.Empty : "error"; - var openingBracket = writePrototypeOnly ? string.Empty : " {"; var funcPrefix = writePrototypeOnly ? string.Empty : "func "; var returnTypeString = (code, finalReturnType, errorDeclaration) switch { @@ -476,6 +475,12 @@ _ when string.IsNullOrEmpty(finalReturnType) && !string.IsNullOrEmpty(errorDecla _ when !string.IsNullOrEmpty(finalReturnType) && string.IsNullOrEmpty(errorDeclaration) => finalReturnType, _ => string.Empty }; + var openingBracket = (writePrototypeOnly, returnTypeString) switch + { + _ when writePrototypeOnly => string.Empty, + _ when string.IsNullOrEmpty(returnTypeString) => "{", // no leading space in this case + _ => " {", + }; writer.WriteLine($"{funcPrefix}{associatedTypePrefix}{methodName}({parameters}) {returnTypeString}{openingBracket}"); } private void WriteGetterBody(CodeMethod codeElement, LanguageWriter writer, CodeClass parentClass) From 2f83574e699427fbbb96b315f2d417e7999d42b8 Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 12:45:17 +0000 Subject: [PATCH 10/35] fix changelog format --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31595df04c..4df439fe52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -135,7 +135,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed Python error when a class inherits from a base class and implements an interface. [#5637](https://github.com/microsoft/kiota/issues/5637) - Fixed a bug where one/any schemas with single schema entries would be missing properties. [#5808](https://github.com/microsoft/kiota/issues/5808) - Fixed anyOf/oneOf generation in TypeScript. [5353](https://github.com/microsoft/kiota/issues/5353) -- Fixed invalid code in Php caused by "_/_/" in property description. [5635](https://github.com/microsoft/kiota/issues/5635) +- Fixed invalid code in Php caused by `"*/*/"` in property description. [5635](https://github.com/microsoft/kiota/issues/5635) - Fixed a bug where discriminator property name lookup could end up in an infinite loop. [#5771](https://github.com/microsoft/kiota/issues/5771) - Fixed TypeScript generation error when generating usings from shaken serializers. [#5634](https://github.com/microsoft/kiota/issues/5634) - Multiple fixed and improvements in OpenAPI description generation for plugins. [#5806](https://github.com/microsoft/kiota/issues/5806) @@ -878,7 +878,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed unused generated import for PHP Generation. - Fixed a bug where long namespaces would make Ruby packaging fail. - Fixed a bug where classes with namespace names are generated outside namespace in Python. [#2188](https://github.com/microsoft/kiota/issues/2188) -- Changed signature of escaped reserved names from {x}_escaped to {x}_ in line with Python style guides. +- Changed signature of escaped reserved names from `{x}*escaped` to `{x}*` in line with Python style guides. - Add null checks in generated Shell language code. - Fixed a bug where Go indexers would fail to pass the index parameter. - Fixed a bug where path segments with parameters could be missing words. [#2209](https://github.com/microsoft/kiota/issues/2209) From d1fd88b0ad2fe6f2f5c530fc181826e5e6b5339b Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 13:26:15 +0000 Subject: [PATCH 11/35] remove trailing spaces on comments --- CHANGELOG.md | 1 + .../Writers/Go/GoConventionService.cs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4df439fe52..31145530a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed a bug where Dart properties casing would change for serialization. - golang: indent with tabs instead of spaces - golang: if there is only one return argument, omit the parentheses +- golang: remove trailing spaces on comments ## [1.25.1] - 2025-04-03 diff --git a/src/Kiota.Builder/Writers/Go/GoConventionService.cs b/src/Kiota.Builder/Writers/Go/GoConventionService.cs index 7a297fe86d..6d5277f0fa 100644 --- a/src/Kiota.Builder/Writers/Go/GoConventionService.cs +++ b/src/Kiota.Builder/Writers/Go/GoConventionService.cs @@ -6,6 +6,7 @@ using Kiota.Builder.CodeDOM; using Kiota.Builder.Extensions; using Kiota.Builder.Refiners; +using Microsoft.VisualBasic; namespace Kiota.Builder.Writers.Go; public class GoConventionService : CommonLanguageConventionService @@ -14,7 +15,7 @@ public class GoConventionService : CommonLanguageConventionService public override string VoidTypeName => string.Empty; - public override string DocCommentPrefix => "// "; + public override string DocCommentPrefix => "//"; public override string ParseNodeInterfaceName => "ParseNode"; #pragma warning disable CA1822 // Method should be static public string AbstractionsHash => "i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f"; @@ -186,14 +187,20 @@ public override bool WriteShortDescription(IDocumentedElement element, LanguageW public void WriteGeneratorComment(LanguageWriter writer) { ArgumentNullException.ThrowIfNull(writer); - writer.WriteLine($"{DocCommentPrefix}Code generated by Microsoft Kiota - DO NOT EDIT."); - writer.WriteLine($"{DocCommentPrefix}Changes may cause incorrect behavior and will be lost if the code is regenerated."); + writer.WriteLine($"{DocCommentPrefix} Code generated by Microsoft Kiota - DO NOT EDIT."); + writer.WriteLine($"{DocCommentPrefix} Changes may cause incorrect behavior and will be lost if the code is regenerated."); writer.WriteLine(string.Empty); } public void WriteDescriptionItem(string description, LanguageWriter writer) { ArgumentNullException.ThrowIfNull(writer); - writer.WriteLine($"{DocCommentPrefix}{description}"); + // account for a trailing whitespace on comments then the description is empty + var comment = description switch + { + _ when string.IsNullOrEmpty(description) => DocCommentPrefix, + _ => $"{DocCommentPrefix} {description}", + }; + writer.WriteLine(comment); } public void WriteLinkDescription(CodeDocumentation documentation, LanguageWriter writer) { From 98c5003c6126b5ca7a4dbcb7256a6b0c8a1c55c7 Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 13:42:06 +0000 Subject: [PATCH 12/35] fix import ordering --- CHANGELOG.md | 1 + src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31145530a9..bb72d49cdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - golang: indent with tabs instead of spaces - golang: if there is only one return argument, omit the parentheses - golang: remove trailing spaces on comments +- golang: fix import ordering ## [1.25.1] - 2025-04-03 diff --git a/src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs b/src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs index dadac0950e..106416ee57 100644 --- a/src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs @@ -32,8 +32,8 @@ public override void WriteCodeElement(CodeFileDeclaration codeElement, LanguageW .Where(static x => x.Declaration != null && x.Declaration.IsExternal) .Select(static x => new Tuple(x.Name.StartsWith('*') ? x.Name[1..] : x.Declaration!.Name.GetNamespaceImportSymbol(), x.Declaration!.Name)) .Distinct()) - .OrderBy(static x => x.Item2.Count(static y => y == '/')) - .ThenBy(static x => x) + .OrderBy(static x => x.Item2) + .ThenBy(static x => x.Item2.Count(static y => y == '/')) .ToList(); if (importSegments.Count != 0) { From 669d86eb87acc55fe8eae5849ca6202163f55acc Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 14:07:46 +0000 Subject: [PATCH 13/35] remove dependency --- src/Kiota.Builder/Writers/Go/GoConventionService.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Kiota.Builder/Writers/Go/GoConventionService.cs b/src/Kiota.Builder/Writers/Go/GoConventionService.cs index 6d5277f0fa..449cd02a8e 100644 --- a/src/Kiota.Builder/Writers/Go/GoConventionService.cs +++ b/src/Kiota.Builder/Writers/Go/GoConventionService.cs @@ -6,7 +6,6 @@ using Kiota.Builder.CodeDOM; using Kiota.Builder.Extensions; using Kiota.Builder.Refiners; -using Microsoft.VisualBasic; namespace Kiota.Builder.Writers.Go; public class GoConventionService : CommonLanguageConventionService From a446f6afa6e5029c9818cb7149e5ca97a040a793 Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 14:35:07 +0000 Subject: [PATCH 14/35] use a constructor --- src/Kiota.Builder/Writers/Go/GoWriter.cs | 24 ++------------------- src/Kiota.Builder/Writers/LanguageWriter.cs | 16 +++++++------- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/Kiota.Builder/Writers/Go/GoWriter.cs b/src/Kiota.Builder/Writers/Go/GoWriter.cs index 606db767fc..5d8cb3961e 100644 --- a/src/Kiota.Builder/Writers/Go/GoWriter.cs +++ b/src/Kiota.Builder/Writers/Go/GoWriter.cs @@ -1,11 +1,9 @@ -using System; -using System.Linq; -using Kiota.Builder.PathSegmenters; +using Kiota.Builder.PathSegmenters; namespace Kiota.Builder.Writers.Go; public class GoWriter : LanguageWriter { - public GoWriter(string rootPath, string clientNamespaceName, bool excludeBackwardCompatible = false) + public GoWriter(string rootPath, string clientNamespaceName, bool excludeBackwardCompatible = false) : base("\t", 1) { PathSegmenter = new GoPathSegmenter(rootPath, clientNamespaceName); var conventionService = new GoConventionService(); @@ -18,22 +16,4 @@ public GoWriter(string rootPath, string clientNamespaceName, bool excludeBackwar AddOrReplaceCodeElementWriter(new CodeFileBlockEndWriter()); AddOrReplaceCodeElementWriter(new CodeFileDeclarationWriter(conventionService)); } - - // Override the Ident functions as golang indents with tabs instead of spaces - private int currentIndent; - private static readonly string indentString = Enumerable.Repeat("\t", 1000).Aggregate(static (x, y) => x + y); - public override void IncreaseIndent(int factor = 1) - { - currentIndent += 1; - } - - public override void DecreaseIndent() - { - currentIndent -= 1; - } - - public override string GetIndent() - { - return indentString[..Math.Max(0, currentIndent)]; - } } diff --git a/src/Kiota.Builder/Writers/LanguageWriter.cs b/src/Kiota.Builder/Writers/LanguageWriter.cs index 2072e89f2a..ffd92c868f 100644 --- a/src/Kiota.Builder/Writers/LanguageWriter.cs +++ b/src/Kiota.Builder/Writers/LanguageWriter.cs @@ -19,11 +19,11 @@ namespace Kiota.Builder.Writers; -public abstract class LanguageWriter +public abstract class LanguageWriter(string indentationChar = " ", int indentSize = 4) { private TextWriter? writer; - private const int IndentSize = 4; - private static readonly string indentString = Enumerable.Repeat(" ", 1000).Aggregate(static (x, y) => x + y); + private readonly int indentSize = indentSize; + private readonly string indentString = Enumerable.Repeat(indentationChar, 1000).Aggregate(static (x, y) => x + y); private int currentIndent; /// @@ -43,19 +43,19 @@ public IPathSegmenter? PathSegmenter } private readonly Stack factorStack = new(); - public virtual void IncreaseIndent(int factor = 1) + public void IncreaseIndent(int factor = 1) { factorStack.Push(factor); - currentIndent += IndentSize * factor; + currentIndent += indentSize * factor; } - public virtual void DecreaseIndent() + public void DecreaseIndent() { var popped = factorStack.TryPop(out var factor); - currentIndent -= IndentSize * (popped ? factor : 1); + currentIndent -= indentSize * (popped ? factor : 1); } - public virtual string GetIndent() + public string GetIndent() { return indentString[..Math.Max(0, currentIndent)]; } From 50f05e9a5fac45191441dd084b30787e0d84dd12 Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 15:58:55 +0000 Subject: [PATCH 15/35] add comment --- src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs b/src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs index 106416ee57..eae44846ec 100644 --- a/src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs @@ -32,7 +32,7 @@ public override void WriteCodeElement(CodeFileDeclaration codeElement, LanguageW .Where(static x => x.Declaration != null && x.Declaration.IsExternal) .Select(static x => new Tuple(x.Name.StartsWith('*') ? x.Name[1..] : x.Declaration!.Name.GetNamespaceImportSymbol(), x.Declaration!.Name)) .Distinct()) - .OrderBy(static x => x.Item2) + .OrderBy(static x => x.Item2) // Item1: import alias, Item2: import path .ThenBy(static x => x.Item2.Count(static y => y == '/')) .ToList(); if (importSegments.Count != 0) From 8af47032371751901b56a5e02af606b5796003b3 Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:11:20 +0000 Subject: [PATCH 16/35] simplify sort --- src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs | 1 - src/Kiota.Builder/Writers/Go/GoNamespaceExtensions.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs b/src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs index eae44846ec..1b780b2136 100644 --- a/src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs @@ -33,7 +33,6 @@ public override void WriteCodeElement(CodeFileDeclaration codeElement, LanguageW .Select(static x => new Tuple(x.Name.StartsWith('*') ? x.Name[1..] : x.Declaration!.Name.GetNamespaceImportSymbol(), x.Declaration!.Name)) .Distinct()) .OrderBy(static x => x.Item2) // Item1: import alias, Item2: import path - .ThenBy(static x => x.Item2.Count(static y => y == '/')) .ToList(); if (importSegments.Count != 0) { diff --git a/src/Kiota.Builder/Writers/Go/GoNamespaceExtensions.cs b/src/Kiota.Builder/Writers/Go/GoNamespaceExtensions.cs index 80573818ba..ab5243e4b2 100644 --- a/src/Kiota.Builder/Writers/Go/GoNamespaceExtensions.cs +++ b/src/Kiota.Builder/Writers/Go/GoNamespaceExtensions.cs @@ -19,7 +19,7 @@ public static string GetInternalNamespaceImport(this CodeElement ns) { if (ns == null) return string.Empty; var urlPrefixIndex = ns.Name.LastIndexOf('/') + 1; - return (ns.Name[..urlPrefixIndex] + string.Join("/", ns.Name[urlPrefixIndex..].Split('.', StringSplitOptions.RemoveEmptyEntries))); + return ns.Name[..urlPrefixIndex] + string.Join("/", ns.Name[urlPrefixIndex..].Split('.', StringSplitOptions.RemoveEmptyEntries)); } public static string GetNamespaceImportSymbol(this CodeElement ns) { From cfad40c5f9f71e6f74043d601166a714829f5072 Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:16:53 +0000 Subject: [PATCH 17/35] use correct helper method --- src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs b/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs index ba6e68414c..e8332e9c66 100644 --- a/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs @@ -43,7 +43,7 @@ public override void WriteCodeElement(CodeEnum codeElement, LanguageWriter write foreach (var item in enumOptions) { if (item.Documentation.DescriptionAvailable) - writer.WriteLine($"// {item.Documentation.DescriptionTemplate}"); + conventions.WriteDescriptionItem(item.Documentation.DescriptionTemplate, writer); if (isMultiValue) writer.WriteLine($"{item.Name.ToUpperInvariant()}_{typeName.ToUpperInvariant()} = {(int)Math.Pow(2, power)}"); From f5c02e65255225b55bed33a48490144c172baf59 Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:22:43 +0000 Subject: [PATCH 18/35] simplify another import statement --- src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs b/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs index e8332e9c66..c06d4589c1 100644 --- a/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs @@ -20,12 +20,11 @@ public override void WriteCodeElement(CodeEnum codeElement, LanguageWriter write writer.WriteLine($"package {ns.Name.GetLastNamespaceSegment().Replace("-", string.Empty, StringComparison.OrdinalIgnoreCase)}"); } - var usings = codeElement.Usings.OrderBy(static x => x.Name, StringComparer.OrdinalIgnoreCase).ToArray(); - if (usings.Length > 0) + var usings = codeElement.Usings.Select(static x => x.Name).OrderBy(static x => x, StringComparer.OrdinalIgnoreCase).ToList(); + if (usings.Count > 0) { writer.StartBlock("import ("); - foreach (var cUsing in usings) - writer.WriteLine($"\"{cUsing.Name}\""); + usings.ForEach(x => writer.WriteLine($"\"{x}\"")); writer.CloseBlock(")"); } From 050a088349d7761a93c02a6bd647d28881cfcc07 Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:25:31 +0000 Subject: [PATCH 19/35] more import ordering fixes --- src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs | 2 +- .../Writers/Go/CodeProprietableBlockDeclarationWriter.cs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs b/src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs index 1b780b2136..dc55e0e83d 100644 --- a/src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs @@ -38,7 +38,7 @@ public override void WriteCodeElement(CodeFileDeclaration codeElement, LanguageW { writer.WriteLines(string.Empty, "import ("); writer.IncreaseIndent(); - importSegments.ForEach(x => writer.WriteLine(x.Item1.Equals(x.Item2, StringComparison.Ordinal) ? $"\"{x.Item2}\"" : $"{x.Item1} \"{x.Item2}\"")); + importSegments.ForEach(x => writer.WriteLine(string.IsNullOrEmpty(x.Item1) ? $"\"{x.Item2}\"" : $"{x.Item1} \"{x.Item2}\"")); writer.DecreaseIndent(); writer.WriteLines(")", string.Empty); } diff --git a/src/Kiota.Builder/Writers/Go/CodeProprietableBlockDeclarationWriter.cs b/src/Kiota.Builder/Writers/Go/CodeProprietableBlockDeclarationWriter.cs index 500c64daf7..bac3b8de83 100644 --- a/src/Kiota.Builder/Writers/Go/CodeProprietableBlockDeclarationWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeProprietableBlockDeclarationWriter.cs @@ -32,14 +32,13 @@ public override void WriteCodeElement(T codeElement, LanguageWriter writer) .Where(static x => x.Declaration != null && x.Declaration.IsExternal) .Select(static x => new Tuple(x.Name.StartsWith('*') ? x.Name[1..] : x.Declaration!.Name.GetNamespaceImportSymbol(), x.Declaration!.Name)) .Distinct()) - .OrderBy(static x => x.Item2.Count(static y => y == '/')) - .ThenBy(static x => x) + .OrderBy(static x => x.Item2) // Item1: import alias, Item2: import path .ToList(); if (importSegments.Count != 0) { writer.WriteLines(string.Empty, "import ("); writer.IncreaseIndent(); - importSegments.ForEach(x => writer.WriteLine(x.Item1.Equals(x.Item2, StringComparison.Ordinal) ? $"\"{x.Item2}\"" : $"{x.Item1} \"{x.Item2}\"")); + importSegments.ForEach(x => writer.WriteLine(string.IsNullOrEmpty(x.Item1) ? $"\"{x.Item2}\"" : $"{x.Item1} \"{x.Item2}\"")); writer.DecreaseIndent(); writer.WriteLines(")", string.Empty); } From a021acd74403b47ccd78e1bfc5c6d000c6b6e908 Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:29:15 +0000 Subject: [PATCH 20/35] correctly indent switch statements --- src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs b/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs index c06d4589c1..7c10b38418 100644 --- a/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs @@ -108,7 +108,8 @@ private static void WriteParsableEnum(CodeEnum codeElement, LanguageWriter write writer.StartBlock("switch str {"); foreach (var item in enumOptions) { - writer.StartBlock($"case \"{item.WireName}\":"); + writer.WriteLine($"case \"{item.WireName}\":"); + writer.IncreaseIndent(); writer.WriteLine($"result |= {item.Name.ToUpperInvariant()}_{typeName.ToUpperInvariant()}"); writer.DecreaseIndent(); } @@ -119,7 +120,8 @@ private static void WriteParsableEnum(CodeEnum codeElement, LanguageWriter write writer.StartBlock("switch v {"); foreach (var item in enumOptions) { - writer.StartBlock($"case \"{item.WireName}\":"); + writer.WriteLine($"case \"{item.WireName}\":"); + writer.IncreaseIndent(); writer.WriteLine($"result = {item.Name.ToUpperInvariant()}_{typeName.ToUpperInvariant()}"); writer.DecreaseIndent(); } From 19b4464f90e2e9aee176dba28275d7623a8bcc46 Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 17:01:52 +0000 Subject: [PATCH 21/35] fix switch statements --- CHANGELOG.md | 1 + .../Writers/Go/CodeEnumWriter.cs | 20 +++++++++++-------- .../Writers/Go/CodeMethodWriter.cs | 4 ++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index affb966795..92ff3e7200 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - golang: if there is only one return argument, omit the parentheses - golang: remove trailing spaces on comments - golang: fix import ordering +- golang: correctly indent case statements inside a switch - Fixed a bug where default response definitions were being considered for Media Type selection [#6413](https://github.com/microsoft/kiota/issues/6413) ## [1.25.1] - 2025-04-03 diff --git a/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs b/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs index 7c10b38418..053b1e9bcc 100644 --- a/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs @@ -105,7 +105,7 @@ private static void WriteParsableEnum(CodeEnum codeElement, LanguageWriter write writer.WriteLine($"var result {typeName}"); writer.WriteLine("values := strings.Split(v, \",\")"); writer.StartBlock("for _, str := range values {"); - writer.StartBlock("switch str {"); + writer.WriteLine("switch str {"); foreach (var item in enumOptions) { writer.WriteLine($"case \"{item.WireName}\":"); @@ -113,11 +113,17 @@ private static void WriteParsableEnum(CodeEnum codeElement, LanguageWriter write writer.WriteLine($"result |= {item.Name.ToUpperInvariant()}_{typeName.ToUpperInvariant()}"); writer.DecreaseIndent(); } + writer.WriteLine("default:"); + writer.IncreaseIndent(); + writer.WriteLine($"return nil, nil"); + writer.DecreaseIndent(); + writer.WriteLine("}"); // close the switch statement + writer.CloseBlock(); // close the for loop } else { writer.WriteLine($"result := {enumOptions[0].Name.ToUpperInvariant()}_{typeName.ToUpperInvariant()}"); - writer.StartBlock("switch v {"); + writer.WriteLine("switch v {"); foreach (var item in enumOptions) { writer.WriteLine($"case \"{item.WireName}\":"); @@ -125,13 +131,11 @@ private static void WriteParsableEnum(CodeEnum codeElement, LanguageWriter write writer.WriteLine($"result = {item.Name.ToUpperInvariant()}_{typeName.ToUpperInvariant()}"); writer.DecreaseIndent(); } + writer.StartBlock("default:"); + writer.WriteLine($"return nil, nil"); + writer.DecreaseIndent(); + writer.WriteLine("}"); } - - writer.StartBlock("default:"); - writer.WriteLine($"return nil, nil"); - writer.DecreaseIndent(); - writer.CloseBlock(); - if (isMultiValue) writer.CloseBlock(); writer.WriteLine("return &result, nil"); writer.CloseBlock(); } diff --git a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs index 4eadc3913b..722605e4d8 100644 --- a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs @@ -162,7 +162,7 @@ private void WriteFactoryMethodBody(CodeMethod codeElement, CodeClass parentClas } private void WriteFactoryMethodBodyForInheritedModel(CodeClass parentClass, LanguageWriter writer) { - writer.StartBlock($"switch *{DiscriminatorMappingVarName} {{"); + writer.WriteLine($"switch *{DiscriminatorMappingVarName} {{"); foreach (var mappedType in parentClass.DiscriminatorInformation.DiscriminatorMappings) { writer.WriteLine($"case \"{mappedType.Key}\":"); @@ -170,7 +170,7 @@ private void WriteFactoryMethodBodyForInheritedModel(CodeClass parentClass, Lang writer.WriteLine($"return {conventions.GetImportedStaticMethodName(mappedType.Value, parentClass)}(), nil"); writer.DecreaseIndent(); } - writer.CloseBlock(); + writer.WriteLine("}"); } private void WriteFactoryMethodBodyForIntersectionModel(CodeMethod codeElement, CodeClass parentClass, CodeParameter parseNodeParameter, LanguageWriter writer) { From 90be6d03c329dcc604edecbd08c8ca4cb55442e9 Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 17:12:30 +0000 Subject: [PATCH 22/35] more formatting tweaks --- src/Kiota.Builder/Refiners/GoRefiner.cs | 2 +- src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Kiota.Builder/Refiners/GoRefiner.cs b/src/Kiota.Builder/Refiners/GoRefiner.cs index 234cb625bf..ee417bbc2d 100644 --- a/src/Kiota.Builder/Refiners/GoRefiner.cs +++ b/src/Kiota.Builder/Refiners/GoRefiner.cs @@ -826,7 +826,7 @@ private static void CorrectMethodType(CodeMethod currentMethod) currentMethod.Parameters.Where(static x => x.Type.Name.Equals("ISerializationWriter", StringComparison.Ordinal)).ToList().ForEach(x => x.Type.Name = "SerializationWriter"); else if (currentMethod.IsOfKind(CodeMethodKind.Deserializer)) { - currentMethod.ReturnType.Name = $"map[string]func({conventions.SerializationHash}.ParseNode)(error)"; + currentMethod.ReturnType.Name = $"map[string]func({conventions.SerializationHash}.ParseNode) error"; currentMethod.Name = "getFieldDeserializers"; } else if (currentMethod.IsOfKind(CodeMethodKind.ClientConstructor, CodeMethodKind.Constructor, CodeMethodKind.RawUrlConstructor)) diff --git a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs index 722605e4d8..0065bc5475 100644 --- a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs @@ -717,7 +717,7 @@ private void WriteDeserializerBodyForInheritedModel(CodeMethod codeElement, Code private void WriteFieldDeserializer(CodeProperty property, LanguageWriter writer, CodeClass parentClass, string parsableImportSymbol) { if (property.Setter is null) return; - writer.StartBlock($"res[\"{property.WireName}\"] = func (n {parsableImportSymbol}) error {{"); + writer.StartBlock($"res[\"{property.WireName}\"] = func(n {parsableImportSymbol}) error {{"); var propertyTypeImportName = conventions.GetTypeString(property.Type, parentClass, false, false); var deserializationMethodName = GetDeserializationMethodName(property.Type, parentClass); writer.WriteLine($"val, err := n.{deserializationMethodName}"); @@ -803,7 +803,7 @@ private void WriteRequestExecutorBody(CodeMethod codeElement, RequestParams requ if (codeElement.ErrorMappings.Any()) { errorMappingVarName = "errorMapping"; - writer.WriteLine($"{errorMappingVarName} := {conventions.AbstractionsHash}.ErrorMappings {{"); + writer.WriteLine($"{errorMappingVarName} := {conventions.AbstractionsHash}.ErrorMappings{{"); writer.IncreaseIndent(); foreach (var errorMapping in codeElement.ErrorMappings) { From 009d9527d482c97551e9286a97faddec102269db Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 21:12:11 +0000 Subject: [PATCH 23/35] more formatting --- src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs index 0065bc5475..7e1604b812 100644 --- a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs @@ -542,14 +542,18 @@ private void WriteSerializationRegistration(HashSet serializationModules { var moduleImportSymbol = conventions.GetTypeString(new CodeType { Name = module, IsExternal = true }, parentClass, false, false); moduleImportSymbol = moduleImportSymbol.Split('.').First(); - writer.WriteLine($"{methodImportSymbol}(func() {interfaceImportSymbol} {{ return {moduleImportSymbol}.New{module}() }})"); + writer.WriteLine($"{methodImportSymbol}(func() {interfaceImportSymbol} {{"); + writer.IncreaseIndent(); + writer.WriteLine($"return {moduleImportSymbol}.New{module}()"); + writer.DecreaseIndent(); + writer.WriteLine("})"); } } private void WriteConstructorBody(CodeClass parentClass, CodeMethod currentMethod, LanguageWriter writer, bool inherits) { - writer.WriteLine($"m := &{parentClass.Name.ToFirstCharacterUpperCase()}{{"); if (inherits || parentClass.IsErrorDefinition) { + writer.WriteLine($"m := &{parentClass.Name.ToFirstCharacterUpperCase()}{{"); writer.IncreaseIndent(); var parentClassName = parentClass.StartBlock.Inherits!.Name.ToFirstCharacterUpperCase(); var newMethodName = conventions.GetImportedStaticMethodName(parentClass.StartBlock.Inherits, parentClass); @@ -565,8 +569,12 @@ private void WriteConstructorBody(CodeClass parentClass, CodeMethod currentMetho else writer.WriteLine($"{parentClassName}: *{newMethodName}(),"); writer.DecreaseIndent(); + writer.CloseBlock(decreaseIndent: false); + } + else + { + writer.WriteLine($"m := &{parentClass.Name.ToFirstCharacterUpperCase()}{{}}"); } - writer.CloseBlock(decreaseIndent: false); foreach (var propWithDefault in parentClass.GetPropertiesOfKind(CodePropertyKind.BackingStore, CodePropertyKind.RequestBuilder) .Where(static x => !string.IsNullOrEmpty(x.DefaultValue)) From 710513bf72a1e72c257478bc7f6442ff824325bf Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 21:19:05 +0000 Subject: [PATCH 24/35] newline after each func --- src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs index 7e1604b812..96a33f793f 100644 --- a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs @@ -92,6 +92,7 @@ public override void WriteCodeElement(CodeMethod codeElement, LanguageWriter wri break; } writer.CloseBlock(); + writer.WriteLine(); // empty line after each func } private static void WriteErrorMethodOverride(CodeClass parentClass, LanguageWriter writer) { From dc627cb1431afe389a30fe6807cb6dbff35ec4aa Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 7 Apr 2025 22:07:28 +0000 Subject: [PATCH 25/35] more formatting --- src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs index 96a33f793f..a02ae281a8 100644 --- a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs @@ -109,7 +109,7 @@ private void WriteRawUrlBuilderBody(CodeClass parentClass, CodeMethod codeElemen { var rawUrlParameter = codeElement.Parameters.OfKind(CodeParameterKind.RawUrl) ?? throw new InvalidOperationException("RawUrlBuilder method should have a RawUrl parameter"); var requestAdapterProperty = parentClass.GetPropertyOfKind(CodePropertyKind.RequestAdapter) ?? throw new InvalidOperationException("RawUrlBuilder method should have a RequestAdapter property"); - writer.WriteLine($"return New{parentClass.Name.ToFirstCharacterUpperCase()}({rawUrlParameter.Name.ToFirstCharacterLowerCase()}, m.BaseRequestBuilder.{requestAdapterProperty.Name.ToFirstCharacterUpperCase()});"); + writer.WriteLine($"return New{parentClass.Name.ToFirstCharacterUpperCase()}({rawUrlParameter.Name.ToFirstCharacterLowerCase()}, m.BaseRequestBuilder.{requestAdapterProperty.Name.ToFirstCharacterUpperCase()})"); } private void WriteComposedTypeMarkerBody(LanguageWriter writer) { From 77a350cee28f857a40ea66213c54ccf7a040ffb1 Mon Sep 17 00:00:00 2001 From: firefart <105281+firefart@users.noreply.github.com> Date: Tue, 8 Apr 2025 20:43:31 +0000 Subject: [PATCH 26/35] remove more unneeded ; --- src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs index a02ae281a8..eb77de0ade 100644 --- a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs @@ -499,8 +499,8 @@ private void WriteGetterBody(CodeMethod codeElement, LanguageWriter writer, Code $"val , err := m.{backingStore.NamePrefix}{backingStore.Name.ToFirstCharacterLowerCase()}.Get(\"{codeElement.AccessedProperty.Name.ToFirstCharacterLowerCase()}\")"); writer.WriteBlock("if err != nil {", "}", "panic(err)"); writer.WriteBlock("if val == nil {", "}", - $"var value = {codeElement.AccessedProperty.DefaultValue};", - $"m.Set{codeElement.AccessedProperty.Name?.ToFirstCharacterUpperCase()}(value);"); + $"var value = {codeElement.AccessedProperty.DefaultValue}", + $"m.Set{codeElement.AccessedProperty.Name?.ToFirstCharacterUpperCase()}(value)"); writer.WriteLine($"return val.({conventions.GetTypeString(codeElement.AccessedProperty.Type, parentClass)})"); } @@ -532,7 +532,7 @@ private void WriteApiConstructorBody(CodeClass parentClass, CodeMethod method, L writer.WriteLine($"m.{BaseRequestBuilderVarName}.{pathParametersProperty.Name.ToFirstCharacterUpperCase()}[\"baseurl\"] = m.{requestAdapterPropertyName}.GetBaseUrl()"); } if (backingStoreParameter != null) - writer.WriteLine($"m.{requestAdapterPropertyName}.EnableBackingStore({backingStoreParameter.Name});"); + writer.WriteLine($"m.{requestAdapterPropertyName}.EnableBackingStore({backingStoreParameter.Name})"); } private void WriteSerializationRegistration(HashSet serializationModules, LanguageWriter writer, CodeClass parentClass, string methodName, string interfaceName) { @@ -581,7 +581,7 @@ private void WriteConstructorBody(CodeClass parentClass, CodeMethod currentMetho .Where(static x => !string.IsNullOrEmpty(x.DefaultValue)) .OrderBy(static x => x.Name)) { - writer.WriteLine($"m.{propWithDefault.NamePrefix}{propWithDefault.Name.ToFirstCharacterLowerCase()} = {propWithDefault.DefaultValue};"); + writer.WriteLine($"m.{propWithDefault.NamePrefix}{propWithDefault.Name.ToFirstCharacterLowerCase()} = {propWithDefault.DefaultValue}"); } foreach (var propWithDefault in parentClass.GetPropertiesOfKind(CodePropertyKind.AdditionalData, CodePropertyKind.Custom) //additional data and custom rely on accessors .Where(static x => !string.IsNullOrEmpty(x.DefaultValue)) @@ -876,7 +876,7 @@ private static void WriteMethodCall(CodeMethod codeElement, RequestParams reques private static void WriteGeneratorMethodCall(CodeMethod codeElement, RequestParams requestParams, CodeClass parentClass, LanguageWriter writer, string prefix) { WriteMethodCall(codeElement, requestParams, parentClass, writer, CodeMethodKind.RequestGenerator, (name, paramsCall) => - $"{prefix}m.{name}({paramsCall});" + $"{prefix}m.{name}({paramsCall})" ); } private const string RequestInfoVarName = "requestInfo"; From 0abfc98118e50cc88423b847e1140dfb9140fceb Mon Sep 17 00:00:00 2001 From: firefart <105281+firefart@users.noreply.github.com> Date: Tue, 8 Apr 2025 21:05:44 +0000 Subject: [PATCH 27/35] cleanup --- src/Kiota.Builder/Writers/Go/CodeClassDeclarationWriter.cs | 2 +- src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs | 6 +++--- .../Writers/Go/CodeInterfaceDeclarationWriter.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Kiota.Builder/Writers/Go/CodeClassDeclarationWriter.cs b/src/Kiota.Builder/Writers/Go/CodeClassDeclarationWriter.cs index 6e7c26b7f9..1721613252 100644 --- a/src/Kiota.Builder/Writers/Go/CodeClassDeclarationWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeClassDeclarationWriter.cs @@ -22,7 +22,7 @@ protected override void WriteTypeDeclaration(ClassDeclaration codeElement, Langu if (codeElement.Inherits?.AllTypes?.Any() ?? false) { var parentTypeName = conventions.GetTypeString(codeElement.Inherits.AllTypes.First(), currentClass, true, false); - writer.WriteLine($"{parentTypeName}"); + writer.WriteLine(parentTypeName); } } } diff --git a/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs b/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs index 053b1e9bcc..e13e3f1528 100644 --- a/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs @@ -76,7 +76,7 @@ private static void WriteStringFunction(CodeEnum codeElement, LanguageWriter wri writer.StartBlock($"for p := 0; p < {enumOptions.Count}; p++ {{"); writer.WriteLine($"mantis := {typeName}(int(math.Pow(2, float64(p))))"); writer.StartBlock($"if i&mantis == mantis {{"); - writer.WriteLine($"values = append(values, options[p])"); + writer.WriteLine("values = append(values, options[p])"); writer.CloseBlock(); writer.CloseBlock(); writer.WriteLine("return strings.Join(values, \",\")"); @@ -115,7 +115,7 @@ private static void WriteParsableEnum(CodeEnum codeElement, LanguageWriter write } writer.WriteLine("default:"); writer.IncreaseIndent(); - writer.WriteLine($"return nil, nil"); + writer.WriteLine("return nil, nil"); writer.DecreaseIndent(); writer.WriteLine("}"); // close the switch statement writer.CloseBlock(); // close the for loop @@ -132,7 +132,7 @@ private static void WriteParsableEnum(CodeEnum codeElement, LanguageWriter write writer.DecreaseIndent(); } writer.StartBlock("default:"); - writer.WriteLine($"return nil, nil"); + writer.WriteLine("return nil, nil"); writer.DecreaseIndent(); writer.WriteLine("}"); } diff --git a/src/Kiota.Builder/Writers/Go/CodeInterfaceDeclarationWriter.cs b/src/Kiota.Builder/Writers/Go/CodeInterfaceDeclarationWriter.cs index 7bb0f7b09f..cbdc83190c 100644 --- a/src/Kiota.Builder/Writers/Go/CodeInterfaceDeclarationWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeInterfaceDeclarationWriter.cs @@ -22,7 +22,7 @@ protected override void WriteTypeDeclaration(InterfaceDeclaration codeElement, L foreach (var implement in codeElement.Implements) { var parentTypeName = conventions.GetTypeString(implement, inter, true, false); - writer.WriteLine($"{parentTypeName}"); + writer.WriteLine(parentTypeName); } } } From b95be2b79d942d18d7a66cb273c5bfef752871d0 Mon Sep 17 00:00:00 2001 From: firefart <105281+firefart@users.noreply.github.com> Date: Sun, 4 May 2025 21:13:43 +0000 Subject: [PATCH 28/35] the java feature is fixed --- .devcontainer/devcontainer.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 78f81c7e8d..eb4c0b9680 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -59,10 +59,7 @@ "ghcr.io/devcontainers-contrib/features/gradle-sdkman:2": {}, "ghcr.io/devcontainers/features/python:1": {}, "ghcr.io/devcontainers/features/go:1": {}, - "ghcr.io/devcontainers/features/java:1": { - // https://github.com/devcontainers/features/issues/1308 - "version": "23" - }, + "ghcr.io/devcontainers/features/java:1": {}, "ghcr.io/devcontainers/features/rust:1": {}, // disabled swift & ruby as their are failing for now "ghcr.io/devcontainers/features/powershell:1": {} From 2a20e36eabf08854dcbee7bbc83a8a4bdebc6d8c Mon Sep 17 00:00:00 2001 From: firefart <105281+firefart@users.noreply.github.com> Date: Fri, 16 May 2025 20:32:21 +0000 Subject: [PATCH 29/35] remove more spaces at the end --- src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs | 8 +++++++- src/Kiota.Builder/Writers/Go/CodePropertyWriter.cs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs index eb77de0ade..5ed3275377 100644 --- a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs @@ -482,7 +482,13 @@ _ when string.IsNullOrEmpty(finalReturnType) && !string.IsNullOrEmpty(errorDecla _ when string.IsNullOrEmpty(returnTypeString) => "{", // no leading space in this case _ => " {", }; - writer.WriteLine($"{funcPrefix}{associatedTypePrefix}{methodName}({parameters}) {returnTypeString}{openingBracket}"); + var firstPart = $"{funcPrefix}{associatedTypePrefix}{methodName}({parameters})"; + var finalString = (returnTypeString, openingBracket) switch + { + _ when string.IsNullOrEmpty(returnTypeString) && string.IsNullOrEmpty(openingBracket) => firstPart, + _ => $"{firstPart} {returnTypeString}{openingBracket}" + }; + writer.WriteLine(finalString); } private void WriteGetterBody(CodeMethod codeElement, LanguageWriter writer, CodeClass parentClass) { diff --git a/src/Kiota.Builder/Writers/Go/CodePropertyWriter.cs b/src/Kiota.Builder/Writers/Go/CodePropertyWriter.cs index 9c51628129..8c740ec5e8 100644 --- a/src/Kiota.Builder/Writers/Go/CodePropertyWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodePropertyWriter.cs @@ -28,7 +28,7 @@ public override void WriteCodeElement(CodeProperty codeElement, LanguageWriter w var returnType = codeElement.Parent is CodeElement parent ? conventions.GetTypeString(codeElement.Type, parent) : string.Empty; conventions.WriteShortDescription(codeElement, writer); conventions.WriteDeprecation(codeElement, writer); - writer.WriteLine($"{propertyName} {returnType}{suffix}"); + writer.WriteLine(string.IsNullOrEmpty(returnType) && string.IsNullOrEmpty(suffix) ? propertyName : $"{propertyName} {returnType}{suffix}"); break; } } From a8804af6982e6ed413c8a6c1c5fae0d2f164aecd Mon Sep 17 00:00:00 2001 From: firefart <105281+firefart@users.noreply.github.com> Date: Fri, 16 May 2025 20:36:14 +0000 Subject: [PATCH 30/35] fix changelog --- CHANGELOG.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1f7ea81d5..30a820e8e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- golang: indent with tabs instead of spaces +- golang: if there is only one return argument, omit the parentheses +- golang: remove trailing spaces on comments +- golang: fix import ordering +- golang: correctly indent case statements inside a switch + ### Changed ## [1.26.1] - 2025-05-15 @@ -18,11 +24,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added support for windows arm64. [#6427](https://github.com/microsoft/kiota/issues/6427) -- golang: indent with tabs instead of spaces -- golang: if there is only one return argument, omit the parentheses -- golang: remove trailing spaces on comments -- golang: fix import ordering -- golang: correctly indent case statements inside a switch ### Changed From a4eac144bffc62ddeb3a1a3b3262c9bcf1f3a296 Mon Sep 17 00:00:00 2001 From: firefart <105281+firefart@users.noreply.github.com> Date: Fri, 16 May 2025 20:46:49 +0000 Subject: [PATCH 31/35] add integration test --- it/exec-cmd.ps1 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/it/exec-cmd.ps1 b/it/exec-cmd.ps1 index 0bd7595493..779c27dc65 100755 --- a/it/exec-cmd.ps1 +++ b/it/exec-cmd.ps1 @@ -146,6 +146,15 @@ elseif ($language -eq "go") { go test } -ErrorAction Stop + Invoke-Call -ScriptBlock { + $fmtStdOut, $fmtStdErr = "", "" + $fmtStdOut = go fmt ./... 2>&1 + if ($fmtStdOut) { + Write-Host "go fmt produced output, so the generated code is not correctly formatted by kiota:`n$fmtStdOut" + exit 1 + } + } -ErrorAction Stop + Pop-Location } else { From 2c45bf9867c9a3b619bc33f6b0a319694b71edb1 Mon Sep 17 00:00:00 2001 From: firefart <105281+firefart@users.noreply.github.com> Date: Fri, 16 May 2025 20:49:06 +0000 Subject: [PATCH 32/35] simplify --- it/exec-cmd.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/it/exec-cmd.ps1 b/it/exec-cmd.ps1 index 779c27dc65..40dd1ea388 100755 --- a/it/exec-cmd.ps1 +++ b/it/exec-cmd.ps1 @@ -147,7 +147,6 @@ elseif ($language -eq "go") { } -ErrorAction Stop Invoke-Call -ScriptBlock { - $fmtStdOut, $fmtStdErr = "", "" $fmtStdOut = go fmt ./... 2>&1 if ($fmtStdOut) { Write-Host "go fmt produced output, so the generated code is not correctly formatted by kiota:`n$fmtStdOut" From e91666ef68c5c71f3619f1a040d56cebb4b68e7e Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Mon, 19 May 2025 21:34:11 +0200 Subject: [PATCH 33/35] Update src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs Co-authored-by: Vincent Biret --- src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs b/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs index e13e3f1528..4eeccbb268 100644 --- a/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs +++ b/src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs @@ -20,7 +20,7 @@ public override void WriteCodeElement(CodeEnum codeElement, LanguageWriter write writer.WriteLine($"package {ns.Name.GetLastNamespaceSegment().Replace("-", string.Empty, StringComparison.OrdinalIgnoreCase)}"); } - var usings = codeElement.Usings.Select(static x => x.Name).OrderBy(static x => x, StringComparer.OrdinalIgnoreCase).ToList(); + var usings = codeElement.Usings.Select(static x => x.Name).Order(StringComparer.OrdinalIgnoreCase).ToList(); if (usings.Count > 0) { writer.StartBlock("import ("); From 91e598093bb14de5480d42236ca046e51a2d68ba Mon Sep 17 00:00:00 2001 From: firefart <105281+firefart@users.noreply.github.com> Date: Mon, 19 May 2025 22:13:47 +0200 Subject: [PATCH 34/35] start fixing unit tests --- .../Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs index e9b5f586fa..5b8304be6b 100644 --- a/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs @@ -12,6 +12,7 @@ using Xunit; namespace Kiota.Builder.Tests.Writers.Go; + public sealed class CodeMethodWriterTests : IDisposable { private const string DefaultPath = "./"; @@ -634,7 +635,7 @@ public void WritesNullableVoidTypeForExecutor() }; writer.Write(method); var result = tw.ToString(); - Assert.Contains("(error)", result); + Assert.Contains(" error {", result); AssertExtensions.CurlyBracesAreClosed(result); } [Fact] @@ -2300,7 +2301,7 @@ public void WritesMessageOverrideOnPrimary() var result = tw.ToString(); // Then - Assert.Contains("Error()(string) {", result); + Assert.Contains("Error() string {", result); Assert.Contains("return *(m.GetProp1()", result); } From 221b1e1e3b7466e46787cbb0a146c1e3e53daddb Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer <105281+firefart@users.noreply.github.com> Date: Tue, 20 May 2025 06:05:02 +0000 Subject: [PATCH 35/35] fix unit tests --- .../Writers/Go/CodeMethodWriterTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs index 5b8304be6b..f896cacc1f 100644 --- a/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs @@ -635,7 +635,7 @@ public void WritesNullableVoidTypeForExecutor() }; writer.Write(method); var result = tw.ToString(); - Assert.Contains(" error {", result); + Assert.Contains("() {", result); AssertExtensions.CurlyBracesAreClosed(result); } [Fact] @@ -986,7 +986,7 @@ public void WritesIndexerWithUuidParam() writer.Write(methodForTest); var result = tw.ToString(); Assert.Contains("m.BaseRequestBuilder.RequestAdapter", result); - Assert.Contains("WithId(id i561e97a8befe7661a44c8f54600992b4207a3a0cf6770e5559949bc276de2e22.UUID)(Somecustomtype)", result); + Assert.Contains("WithId(id i561e97a8befe7661a44c8f54600992b4207a3a0cf6770e5559949bc276de2e22.UUID) Somecustomtype", result); Assert.Contains("m.BaseRequestBuilder.PathParameters", result); Assert.Contains("[\"id\"] = id.String()", result); Assert.Contains("return", result); @@ -1370,7 +1370,7 @@ public async Task WritesRequestExecutorForScalarTypesAsync() method.AcceptedResponseTypes.Add("application/json"); writer.Write(method); var result = tw.ToString(); - Assert.Contains($"func (m *ParentClass) MethodName(ctx context.Context, b []RequestOption, c *RequestConfig)([]i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.DateOnly, error)", result); + Assert.Contains($"func (m *ParentClass) MethodName(ctx context.Context, b []RequestOption, c *RequestConfig) ([]i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.DateOnly, error)", result); Assert.Contains("res, err := m.BaseRequestBuilder.RequestAdapter.SendPrimitiveCollection(ctx, requestInfo, \"dateonly\", nil)", result); Assert.Contains($"val := make([]i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.DateOnly, len(res))", result); Assert.Contains("return val, nil", result); @@ -1673,7 +1673,7 @@ public void WritesReturnType() setup(); writer.Write(method); var result = tw.ToString(); - Assert.Contains($"{MethodName.ToFirstCharacterUpperCase()}()(*{ReturnTypeName}, error)", result);// async default + Assert.Contains($"{MethodName.ToFirstCharacterUpperCase()}() (*{ReturnTypeName}, error)", result);// async default AssertExtensions.CurlyBracesAreClosed(result); } [Fact]