Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2019 - Connected Service Reference - OpenAPI is generating duplicate types

I am trying to generate an OpenApi service reference in Visual Studio 2019. .Net 5.0.

Right clicking project >Add>Connected Services>+ Service References

I am using NetDocs api "https://api.vault.netvoyage.com/v2/swagger/docs/v2".

Result: I get generated c# client code but it is duplicating the types with the errors below.

Severity    Code    Description Project File    Line    Suppression State
Error   CS0102  The type 'v2Client' already contains a definition for '_settings'   OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs    4941    Active
Error   CS0579  Duplicate 'System.CodeDom.Compiler.GeneratedCode' attribute OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs    4936    Active
Error   CS0102  The type 'v2Client' already contains a definition for '_baseUrl'    OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs    4939    Active
Error   CS0102  The type 'v2Client' already contains a definition for '_httpClient' OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs    4940    Active

Is there a way I can get this to work with the connector way without the duplicates? Or even cli? Any suggestions on why it is creating the duplicates?

like image 838
Eric Avatar asked Jun 12 '26 22:06

Eric


1 Answers

It is actually caused by this option

OperationGenerationMode:MultipleClientsFromOperationId

  • MultipleClientsFromOperationId : Multiple clients from the Swagger operation ID in the form '{controller}_{action}'

However, if your classname is set as a static name, it will cause an error like you have.

The correct solution should be change the classname to something like

ClassName="{controller}ServiceClient"

So it will generate different classes.

like image 150
maxisam Avatar answered Jun 14 '26 12:06

maxisam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!