OpenApiReference default className breaks NSwag generated code when using MultipleClients #55556
Labels
area-mvc
Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Author: Migration Bot 🤖
The issue was created by a issue mover bot. The author may not be the actual author.
feature-openapi
Milestone
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)
The text was updated successfully, but these errors were encountered: