Skip to content

Commit c303fd2

Browse files
committed
Bug where Transform to a Primitive Type wasn't being removed from body
1 parent 326b8d8 commit c303fd2

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

GoLive.Generator.ApiClientGenerator/ApiClientGenerator.cs

+20-3
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,14 @@ private static RouteGeneratorSettings LoadConfig(IEnumerable<AdditionalText> con
241241

242242
return config;
243243
}
244-
244+
private static bool IsPrimitiveType(string typeName)
245+
{
246+
return typeName switch
247+
{
248+
"bool" or "Boolean" or "System.Boolean" or "byte" or "Byte" or "System.Byte" or "sbyte" or "SByte" or "System.SByte" or "char" or "Char" or "System.Char" or "decimal" or "Decimal" or "System.Decimal" or "double" or "Double" or "System.Double" or "float" or "Single" or "System.Single" or "int" or "Int32" or "System.Int32" or "uint" or "UInt32" or "System.UInt32" or "long" or "Int64" or "System.Int64" or "ulong" or "UInt64" or "System.UInt64" or "short" or "Int16" or "System.Int16" or "ushort" or "UInt16" or "System.UInt16" or "string" or "String" or "System.String" => true,
249+
_ => false,
250+
};
251+
}
245252
private static void SetUpSingleApi(RouteGeneratorSettings config, ControllerRoute controllerRoute, SourceStringBuilder source)
246253
{
247254
source.AppendLine();
@@ -310,23 +317,33 @@ private static void SetUpSingleApi(RouteGeneratorSettings config, ControllerRout
310317
if (config.Properties.TransformType.FirstOrDefault(tt =>
311318
(string.Equals(tt.SourceType, parameter.FullTypeName, StringComparison.InvariantCultureIgnoreCase) || tt.SourceType == "*") &&
312319
(string.IsNullOrEmpty(tt.ContainsAttribute) || (parameter.Attributes.Count > 0 && parameter.Attributes.Contains(tt.ContainsAttribute)))) is {} tt)
313-
314320
{
315321
parameter.FullTypeName = tt.DestinationType;
316322
}
317323
}
318324

325+
List<string> actionBodyItemsToRemove = [];
326+
319327
foreach (var (key, parameter) in action.Body)
320328
{
329+
var originalType = parameter.FullTypeName;
321330
if (config.Properties.TransformType.FirstOrDefault(tt =>
322331
(string.Equals(tt.SourceType, parameter.FullTypeName, StringComparison.InvariantCultureIgnoreCase) || tt.SourceType == "*") &&
323332
(string.IsNullOrEmpty(tt.ContainsAttribute) || (parameter.Attributes?.Count > 0 && parameter.Attributes.Contains(tt.ContainsAttribute)))) is {} tt)
324333
{
325334
parameter.FullTypeName = tt.DestinationType;
335+
if (!IsPrimitiveType(originalType) && IsPrimitiveType(parameter.FullTypeName))
336+
{
337+
actionBodyItemsToRemove.Add(key);
338+
}
326339
}
327340
}
341+
342+
if (actionBodyItemsToRemove.Count > 0)
343+
{
344+
action.Body.RemoveAll(e => actionBodyItemsToRemove.Contains(e.Key));
345+
}
328346
}
329-
330347
}
331348

332349
var parameterList = string.Join(", ", action.Mapping.Select(m =>

0 commit comments

Comments
 (0)