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 uuid for indexer params #3181

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions src/Kiota.Builder/Refiners/GoRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions src/Kiota.Builder/Writers/Go/GoConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
Expand Down
36 changes: 36 additions & 0 deletions tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading