-
-
Notifications
You must be signed in to change notification settings - Fork 746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Refit Does Not Generate Implementations if 3+ Interfaces Share a Name #1654
Comments
WorkaroundsThere are, of course, a number of workarounds. Separate ProjectsThe interfaces for each "API" could be made their own project, with a separate
This could be less convenient, depending on the size of each API, and managing all the cross-project references could become pretty complicated pretty quickly. Partial InterfacesInstead of each file being its own interface, the endpoints are all combined onto a single interface.
/* /Foo/User.cs */
public partial interface IFoo
{
[Get("/user")]
Task<IApiResponse<List<UserDetails>>> ViewAllUsers();
} Each other "controller" follows this same pattern, where the endpoints are separated into different files based on related functionality, but they're all put onto the interface of Unique NamesOf course, one can always just rename the interfaces in question, so that they no longer have the same name. The scheme my team opted for looked something like this:
Each API interface is suffixed with the name of the API to which it belongs. Everything is kept in the same project so there's only one reference to track, and the namespace isn't as cluttered as partial interfaces, but speaking subjectively, this solution looks a little "ugly". |
Looks like this was fixed with #1542 |
Thank you for confirming this, I will now close this. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Describe the bug 🐞
Hi all 👋
I'm working on integration tests for a handful of distinct-yet-related APIs. These are ASP.NET applications, and they group endpoints into "controllers" based on their related functionality. Some of these APIs have controllers with conflicting names, even though they are in different namespaces (ex "Two APIs each have a
UserController
").As I'm working on different APIs, sometimes I run into the following scenario, where I have different namespaces with the same Refit interface:
Foo
,Bar
, andBaz
being different ASP.NET applications in this case. The interfaces are different, they just all have to do with managing users.If I try to use any of these interfaces, for example with the following code
I get an exception:
The interesting thing is, if you drill down to look at the generated types, the class name includes the full namespace:
Because of this, I would think that name collisions wouldn't be an issue, since the implementing class uses the full namespace of the interface as its name.
The easiest way I've found to track whether the types are being generated is a small annotation that's provided by my IDE, in this case JetBrains Rider:
Visual Studio has a similar feature, where you can view the implementations of an interface after building a project. If the annotation is there, then I know Refit is working. If it's absent, I know that something is broken.
Step to reproduce
Follow these steps within a single C# project.
var api = RestService.For<IApi>(baseUrl);
)Reproduction repository
https://github.com/reactiveui/refit
Expected behavior
Each interface should be auto-generated without issue, and accessed by specifying a namespace.
IDE
Visual Studio 2022, Rider Windows
Version
.NET 7, .NET 6
Refit Version
7.0.0
The text was updated successfully, but these errors were encountered: