Skip to content

Commit

Permalink
|C# endpoints] required sur returns + gestion string dans les clients
Browse files Browse the repository at this point in the history
  • Loading branch information
JabX committed Nov 24, 2023
1 parent e97e7f0 commit 1994aed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions TopModel.Generator.Csharp/CSharpApiClientGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected override void HandleFile(string filePath, string fileName, string tag,
using var fw = new CSharpWriter(filePath, _logger);

var hasBody = endpoints.Any(e => e.GetJsonBodyParam() != null);
var hasReturn = endpoints.Any(e => e.Returns != null);
var hasReturn = endpoints.Any(e => e.Returns != null && !new[] { "string", "byte[]" }.Contains(Config.GetType(e.Returns)));
var hasJson = hasReturn || hasBody;

var usings = new List<string>();
Expand Down Expand Up @@ -218,7 +218,11 @@ protected override void HandleFile(string filePath, string fileName, string tag,

if (returnType != null)
{
if (returnType == "byte[]")
if (returnType == "string")
{
fw.WriteLine(2, $"return await res.Content.ReadAsStringAsync();");
}
else if (returnType == "byte[]")
{
fw.WriteLine();
fw.WriteLine(2, "using var ms = new MemoryStream();");
Expand Down
2 changes: 1 addition & 1 deletion TopModel.Generator.Csharp/CsharpConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public string GetReturnTypeName(IProperty? prop)
return NoAsyncControllers ? "void" : "async Task";
}

var typeName = GetType(prop, nonNullable: true);
var typeName = GetType(prop, nonNullable: (prop as IFieldProperty)?.Required ?? true);
return typeName.StartsWith("IAsyncEnumerable") || NoAsyncControllers
? typeName
: $"async Task<{typeName}>";
Expand Down

0 comments on commit 1994aed

Please sign in to comment.