Search code examples
visual-studioswaggeropenapiconnectorasp.net-core-5.0

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?


Solution

  • I downloaded and use NSwagStudio to generate the client code and did not have the same issue that the Visual Studio connector had when generating the code.

    https://github.com/RicoSuter/NSwag/wiki/NSwagStudio