8000 Adding in special case for byte[] · surgicalcoder/ApiClientGenerator@c80e11a · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit c80e11a

Browse files
author
Monty
committed
Adding in special case for byte[]
1 parent d4c64f3 commit c80e11a

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>1.2.0</Version>
3+
<Version>1.3.0</Version>
44
</PropertyGroup>
55
</Project>

GoLive.Generator.ApiClientGenerator.Tests.WebApi/Controllers/WeatherForecastController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public async Task<ActionResult> SecretUrl()
3636
return Ok();
3737
}
3838

39+
40+
public async Task<ActionResult<byte[]>> GetBytes()
41+
{
42+
return new ActionResult<byte[]>(new byte[1]);
43+
}
44+
3945
public WeatherForecast GetSingle(int Id)
4046
{
4147
return null;

GoLive.Generator.ApiClientGenerator.Tests.WebApi/GeneratedApiClient.cs

Lines changed: 6 additions & 0 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public WeatherForecastClient(HttpClient client)
3333
return await result.Content.ReadFromJsonAsync<global::System.Collections.Generic.IEnumerable<global::GoLive.Generator.ApiClientGenerator.Tests.WebApi.WeatherForecast>>();
3434
}
3535

36+
public async Task<byte[]> GetBytes()
37+
{
38+
var result = await _client.GetAsync($"/WeatherForecast/GetBytes");
39+
return await result.Content.ReadAsByteArrayAsync();
40+
}
41+
3642
public async Task<global::GoLive.Generator.ApiClientGenerator.Tests.WebApi.WeatherForecast> GetSingle(int Id)
3743
{
3844
var result = await _client.GetAsync($"/WeatherForecast/GetSingle/{Id}");

GoLive.Generator.ApiClientGenerator/ApiClientGenerator.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ private void SetUpSingleApi(RouteGeneratorSettings config, ControllerRoute contr
159159
var returnType = action.ReturnTypeName != null
160160
? $"Task<{action.ReturnTypeName}>"
161161
: "Task";
162+
163+
bool byteReturnType = false || action.ReturnTypeName == "byte[]";
164+
Console.WriteLine(action.ReturnTypeName);
162165

163166
var parameterList = string.Join(", ", action.Mapping.Select(m => $"{m.Parameter.FullTypeName} {m.Key} {GetDefaultValue(m.Parameter)}"));
164167

@@ -279,7 +282,11 @@ private void SetUpSingleApi(RouteGeneratorSettings config, ControllerRoute contr
279282
{
280283
source.AppendLine($"var result = {callStatement}");
281284

282-
if (string.IsNullOrWhiteSpace(useCustomFormatter))
285+
if (byteReturnType)
286+
{
287+
source.AppendLine("return await result.Content.ReadAsByteArrayAsync();");
288+
}
289+
else if (string.IsNullOrWhiteSpace(useCustomFormatter))
283290
{
284291
source.AppendLine($"return await result.Content.ReadFromJsonAsync<{action.ReturnTypeName}>();");
285292 3983
}

0 commit comments

Comments
 (0)
0