Open vsfeedback opened 6 months ago
@RicoSuter We received this ticket from some using the client generation integration with NSwg in Visual Studio. We currently set the ClassName
parameter that is passed to NSwag to be based on the project name.
Do you have any thoughts on what the right default should be? Or perhaps, should ASP.NET Core not set one and leave it up to NSwag?
I think as described the right default should be "{controller}Client" and "MultipleClientsFromOperationId" so that for each controller a client class is generated.
This issue has been moved from a ticket on Developer Community.
[severity:It’s more difficult to complete my work]
When defining an
<OpenApiReference CodeGenerator="NSwagCSharp">
in a csproj, one may specify theClassName
of the generated class(es) as well as anOperationGenerationMode
, that determines, how many client classes are generated (Single/Multiple) and how their methods are named.When you leave out the
<ClassName>
tag from the<OpenApiReference>
, that is by default generated to beswaggerClient
. The default/OperationGenerationMode
of NSwag however isMultipleClientsFromOperationId
. So when there are multiple endpoints defined in the swagger.json, the generated methods are all put into a single class namedswaggerClient
and most likely overlap in method names and therefore the class has multiple definitions of the same method and does not compile.If the NSwag code generator does not receive a
/className
option, it is set to"{controller}Client"
and works fine with the default/OperationGenerationMode
. But it’s currently implossible to leave the option from theopenapi2csclient
call, because if you don’t define it, Visual Studio does.So to have a working configuration one must use one of the following settings:
<ClassName>
or no<ClassName>
at all together withOperationGenerationMode
set toSingleClientFromOperationId
orSingleClientFromPathSegments
<ClassName>
like the default"{controller}Client"
with (any?) of the available OperationGenerationMode`In any case, having the className generated by Visual Studio to be swaggerClient probably breaks the generated code.
I’m using NSwag 14.x and this behavior is tested with Visual Studio 17.9.5
My proposed solution is to not have Visual Studio generate a class name, but have NSwag figure it out.
Original Comments
Feedback Bot on 4/16/2024, 07:46 PM:
(private comment, text removed)
Feedback Bot on 4/17/2024, 01:57 AM:
(private comment, text removed)
Bill Hiebert [MSFT] on 5/2/2024, 03:23 PM:
(private comment, text removed)
Original Solutions
(no solutions)