Skip to content

[BUG] [csharp][generichost] Duplicit HTTP client registrations in factory #22082

@McMlok

Description

@McMlok
Description

In our organization two teams provide API to work with comments. Both add tag Comment to endpoint. They both generate csharp client. When another team need to integrate to both APIs an application is unable to start with error

The HttpClient factory already has a registered client with the name 'ICommentApi', bound to the type 'Test1.Client.Api.ICommentApi'. Client names are computed based on the type name without considering the namespace ('ICommentApi'). Use an overload of AddHttpClient that accepts a string and provide a unique name to resolve the conflict.

openapi-generator version

7.16.0

OpenAPI declaration file content or url

Two API definitions are here

Generation Details
Steps to reproduce
  • Create project for Test1 definition
  • Create project for Test2 definition
  • Create another project and reference projects generated from Test1 and Test2
  • Add both AddApi method to service collection.
  • Run the application
Suggest a fix

Add name when AddHttpClient called in .\main\resources\csharp\libraries\generichost\HostConfiguration.mustache for example

{{#apiInfo}}{{#apis}}builders.Add(_services.AddHttpClient<{{interfacePrefix}}{{classname}}, {{classname}}>("{{packageName}}.{{apiPackage}}.{{interfacePrefix}}{{classname}}", client));
            {{/apis}}{{/apiInfo}}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions