The existing C# generators produce clients that rely on the RestSharp library instead of the built-in System.Net.Http.HttpClient. This is particularly annoying if you're building apps using the ASP.NET Typed HttpClient pattern. In addition because the generated clients don't use System.Net.Http.HttpClient, it's impossible (or not very obvious) where you would add delegating handlers to handle cross-cutting concerns that span across all requests. Examples of cross-cutting concerns might be request logging, trace header propagation and retry logic.
What I would like to see is an alternative C# generator that would generate code to support developers in using the Typed HttpClient pattern.
For information about the System.Net.Http.HttpClient API.
https://docs.microsoft.com/dotnet/api/system.net.http.httpclient
For information about making requests with System.Net.Http.HttpClient.
https://docs.microsoft.com/aspnet/core/fundamentals/http-requests
For a quick guide to System.Net.Http.HttpClient and Delegating Handlers, I highly recommend the first half of this talk.
https://youtu.be/ojDxK_-I-To
cc @mandrean (2017/08), @jimschubert (2017/09) @frankyjuang (2019/09) @shibayan (2020/02)
I was thinking of implementing a client that uses HttpClient in the branch I'm personally working on.
https://github.com/OpenAPITools/openapi-generator/issues/5375#issuecomment-589087692
This branch is aimed at a simple client that follows the modern C# language specification (I'm not too far along as I have work to do)
It's going to be a busy time, but lately I've had a little time to work on the csharp-experimental generator.
https://github.com/OpenAPITools/openapi-generator/compare/master...shibayan:csharp-experimental
The goal of this generator is to generate code according to the latest C# specification.
The implementation of this generator is an investment in the future of .NET Core / C#.
I'm busy working, but I'll continue to work on it as best I can.
this is a real pain when integrating APIs with Unity as restsharp doesn't have a unity package and including extra DLLs is a pretty bad practice for mobile games, any ETA on this, is there anything I can do to help?
I've been thinking about this as well can came across this recently. I've been meaning to get around to trying it out. Maybe some here can give it ago and investigate.
https://devblogs.microsoft.com/azure-sdk/code-generation-with-autorest/
I've also been wondering if a C# generator for OpenAPI would be better if it was a dotnet tool.
Most helpful comment
It's going to be a busy time, but lately I've had a little time to work on the csharp-experimental generator.
https://github.com/OpenAPITools/openapi-generator/compare/master...shibayan:csharp-experimental
The goal of this generator is to generate code according to the latest C# specification.
The implementation of this generator is an investment in the future of .NET Core / C#.
I'm busy working, but I'll continue to work on it as best I can.