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

Viewed 882

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?

2 Answers

I had the same issue, it turns out the code generation didn't like enpoints with an underscore in its operationId. Lucky for me, the service I was consuming was also part of our code, so I could just go to the Swagger configuration in the API side and change the CustomOperationIds setting.

Related