diff --git a/CHANGELOG.md b/CHANGELOG.md index d27712b3a2..3a1ba56daf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - RequestExecuters call overload methods reducing code generation size for Java. [#3150](https://github.com/microsoft/kiota/issues/3150) - Remove URISyntaxException from Java generated RequestExecutors and RequestGenerators. [#3149](https://github.com/microsoft/kiota/issues/3149) - Adds 'Generated' annotation to generated Enums and Classes for Java. [#3106](https://github.com/microsoft/kiota/issues/3106) +- Fixes uuid conversion to string value in PathParameters in Go. [#3106](https://github.com/microsoft/kiota/issues/3176) ## [1.5.1] - 2023-08-08 diff --git a/src/Kiota.Builder/Refiners/GoRefiner.cs b/src/Kiota.Builder/Refiners/GoRefiner.cs index 0744e62ed9..5bc5075059 100644 --- a/src/Kiota.Builder/Refiners/GoRefiner.cs +++ b/src/Kiota.Builder/Refiners/GoRefiner.cs @@ -489,7 +489,9 @@ private static void AddErrorImportForEnums(CodeElement currentElement) "Duration", "TimeOnly", "DateOnly", - "string" + "string", + "UUID", + "Guid" }; private static readonly AdditionalUsingEvaluator[] defaultUsingEvaluators = { new (static x => x is CodeProperty prop && prop.IsOfKind(CodePropertyKind.RequestAdapter), @@ -501,7 +503,8 @@ private static void AddErrorImportForEnums(CodeElement currentElement) !typeToSkipStrConv.Contains(x.Type.Name)), "strconv", "FormatBool"), new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility) && - method.OriginalIndexer is CodeIndexer indexer && !indexer.IndexParameter.Type.Name.Equals("string", StringComparison.OrdinalIgnoreCase), + method.OriginalIndexer is CodeIndexer indexer && !indexer.IndexParameter.Type.Name.Equals("string", StringComparison.OrdinalIgnoreCase) + && !typeToSkipStrConv.Contains(indexer.IndexParameter.Type.Name), "strconv", "FormatInt"), new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.Serializer), "github.com/microsoft/kiota-abstractions-go/serialization", "SerializationWriter"), diff --git a/src/Kiota.Builder/Writers/Go/GoConventionService.cs b/src/Kiota.Builder/Writers/Go/GoConventionService.cs index 3b7f7c27f0..86b66ba7b3 100644 --- a/src/Kiota.Builder/Writers/Go/GoConventionService.cs +++ b/src/Kiota.Builder/Writers/Go/GoConventionService.cs @@ -238,6 +238,7 @@ private static string GetValueStringConversion(string typeName, string reference "float" or "double" or "decimal" or "float64" or "float32" => $"{StrConvHash}.FormatFloat({reference}, 'E', -1, 64)", "DateTimeOffset" or "Time" => $"({reference}).Format({TimeFormatHash}.RFC3339)", // default to using ISO 8601 "ISODuration" or "TimeSpan" or "TimeOnly" or "DateOnly" => $"({reference}).String()", + "Guid" or "UUID" => $"{reference}.String()", _ => reference, }; } diff --git a/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs index d5b2385bef..0e22281afd 100644 --- a/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs @@ -951,6 +951,42 @@ public void WritesModelFactoryBody() AssertExtensions.CurlyBracesAreClosed(result); } [Fact] + public void WritesIndexerWithUuidParam() + { + + setup(); + AddRequestProperties(); + parentClass.AddIndexer(new CodeIndexer + { + Name = "indx", + ReturnType = new CodeType + { + Name = "Somecustomtype", + }, + IndexParameter = new() + { + Name = "id", + SerializationName = "id", + Type = new CodeType + { + Name = "UUID", + IsNullable = true, + }, + } + }); + if (parentClass.Indexer is null) + throw new InvalidOperationException("Indexer is null"); + var methodForTest = parentClass.AddMethod(CodeMethod.FromIndexer(parentClass.Indexer, static x => $"With{x.ToFirstCharacterUpperCase()}", static x => x.ToFirstCharacterLowerCase(), false)).First(); + writer.Write(methodForTest); + var result = tw.ToString(); + Assert.Contains("m.BaseRequestBuilder.RequestAdapter", 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); + Assert.Contains("NewSomecustomtypeInternal(urlTplParams, m.BaseRequestBuilder.RequestAdapter)", result); // checking the parameter is passed to the constructor + } + [Fact] public void DoesntWriteFactorySwitchOnMissingParameter() { setup();