Skip to content

Commit

Permalink
Add fallback to HttpResponseMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
vmachacek committed Aug 12, 2022
1 parent 67803be commit 16d1a0d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions GenerateAspNetCoreClient.Command/ClientModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ internal Client GetClientModel(
if (options.AddCancellationTokenParameters)
namespaces = namespaces.Append("System.Threading");

namespaces = namespaces.Append("System.Net.Http");

namespaces = namespaces
.OrderByDescending(ns => ns.StartsWith("System"))
.ThenBy(ns => ns);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

namespace GenerateAspNetCoreClient.Command.Extensions
Expand Down Expand Up @@ -86,7 +87,7 @@ public static string GetName(this Type @this, HashSet<Type> ambiguousTypes)
public static Type WrapInTask(this Type @this)
{
if (@this == typeof(void))
return typeof(Task);
return typeof(Task<HttpResponseMessage>);

return typeof(Task<>).MakeGenericType(@this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//<auto-generated />

using System;
using System.Net.Http;
using System.Threading.Tasks;
using Refit;

Expand All @@ -9,9 +10,9 @@ namespace Test.Name.Space
public interface IAnotherTestApi
{
[Get("/AnotherTest/with-query-model")]
Task WithQueryModel(string param1 = null, Guid? param2 = null, int? param3 = null);
Task<HttpResponseMessage> WithQueryModel(string param1 = null, Guid? param2 = null, int? param3 = null);

[Get("/AnotherTest/with-query-name")]
Task WithQueryParameterName([AliasAs("currency")] string currencyName = null);
Task<HttpResponseMessage> WithQueryParameterName([AliasAs("currency")] string currencyName = null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Refit;
using TestWebApi.Models;
Expand All @@ -22,7 +23,7 @@ namespace Test.Name.Space

[Multipart]
[Post("/WeatherForecast/upload")]
Task Upload(MultipartItem uploadedFile);
Task<HttpResponseMessage> Upload(MultipartItem uploadedFile);

[Get("/WeatherForecast/download")]
Task<Stream> Download();
Expand All @@ -34,10 +35,10 @@ namespace Test.Name.Space
Task<WeatherForecast> SomethingWithQueryParams(int id, string par2, int par1 = 2, string par3 = null, string par4 = "1");

[Patch("/WeatherForecast/headerParams")]
Task WithHeaderParams([Header("x-header-name")] string headerParam = null);
Task<HttpResponseMessage> WithHeaderParams([Header("x-header-name")] string headerParam = null);

[Post("/WeatherForecast/form")]
Task WithFormParam([Body(BodySerializationMethod.UrlEncoded)] SomeQueryModel formParam = null);
Task<HttpResponseMessage> WithFormParam([Body(BodySerializationMethod.UrlEncoded)] SomeQueryModel formParam = null);

[Get("/WeatherForecast/record")]
Task<RecordModel> WithRecordModels(Guid? id = null, string name = null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//<auto-generated />

using System.Net.Http;
using System.Threading.Tasks;
using Refit;

Expand All @@ -9,14 +10,14 @@ namespace Test.Name.Space
{
[Headers("Api-Version: 2.0")]
[Get("/api/Version")]
Task Get();
Task<HttpResponseMessage> Get();

[Headers("Api-Version: 3.0")]
[Get("/api/Version")]
Task Get3();
Task<HttpResponseMessage> Get3();

[Headers("Api-Version: 4.0")]
[Get("/api/Version")]
Task Get4();
Task<HttpResponseMessage> Get4();
}
}

0 comments on commit 16d1a0d

Please sign in to comment.