Build errors after creating an openapi client via Connected Services

I would like to add an OpenAPI service reference to an existing project. Within the Connected Services view, the next values are used:

enter image description here

Afterwards I click on Finish, build the project and add the PetStoreApiClient.cs to the project.

Finally I try to build the solution again while using the PetStoreApiClient. Visual Studio displays several compile errors, e.g.:

enter image description here

Several items are duplicated, even the baseUrl is generated multiple times:

Ambiguity between 'PetStoreApiClient.BaseUrl' and 'PetStoreApiClient.BaseUrl'   ConsoleApp  C:\..\ConsoleApp\ConsoleApp\obj\openapi1Client.cs

The csproj file contains the next settings, as visualized in the first screenshot:

 <ItemGroup>
<OpenApiReference Include="OpenAPIs\openapi.json" CodeGenerator="NSwagCSharp" ClassName="PetStoreApiClient" OutputPath="PetStoreApiClient.cs">
  <SourceUri>https://petstore3.swagger.io/api/v3/openapi.json</SourceUri>
</OpenApiReference>

Should I use different settings, I am missing a setting within the csproj? A similar issue is described on GitHub, but the provided solutions don't work.


Solution 1:

I had the same issue and a very hard time finding a good answer.

Until I found this: https://github.com/RicoSuter/NSwag/issues/334

“If you have multiple controllers, you have to either choose OperationGenerationMode.SingleClientFromOperationId or use the placeholder {controller} in your controller class name.”

So my issue was solved by simply providing “{controller}Client” as class name.