RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.78k stars 1.29k forks source link

Cannot pass options to NSwag code generation when added through Visual Studio Connected Services #4780

Open lukasf opened 9 months ago

lukasf commented 9 months ago

When I add an OpenAPI service reference in a .NET Core project in Visual Studio via "Connected Services", NSwag is used to generate the C# client. In the Connected Services dialog, there is a field "Additional code generation options". According to this page, it should be possible to set command line options here, to customize the NSwag code generation.

I need to use DateOnly as DateType, and I tried lots of things: /DateType:System.DateOnly /DateType:"System.DateOnly" /DateType:"DateOnly" /dateType:System.DateOnly /dateType System.DateOnly /dateType=System.DateOnly

But none of these worked. I also did not find any information in the Wiki. I also tried other options, but none of them seemed to have any effect.

Can anyone tell me how to customize the code generation using VS Connected Services? This should be documented in the Wiki in a prominent way.

Alschy commented 1 week ago

Hi, I had the same issue with the Visual Studio Connected Services. So I played a little bit with the generator options and found a solution: Add to the code generation options the string /DateType:DateOnly The "System" namespace is imported by default for the generated client class so an additional definition of the namespace isn't required.