reactiveui / refit

The automatic type-safe REST library for .NET Core, Xamarin and .NET. Heavily inspired by Square's Retrofit library, Refit turns your REST API into a live interface.
https://reactiveui.github.io/refit/
MIT License
8.56k stars 746 forks source link

[Bug]: Refit fails to generate if more than two types have the same name #1519

Closed yoelhalb-hitech closed 2 weeks ago

yoelhalb-hitech commented 1 year ago

Describe the bug šŸž

When having more than two Refit interfaces with the same name in the same project (but different namespaces or different enclosing type) the generator will fail to generate the classes.

The warning at compile time is:

CSC : warning CS8785: Generator 'InterfaceStubGeneratorV2' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentException' with message 'The hintName 'ITest1.g.cs' of the added source file must be unique within a generator.

While at runtime it fails with:

System.InvalidOperationException : ITest doesn't look like a Refit interface. Make sure it has at least one method with a Refit HTTP method attribute and Refit is installed in the project.

Step to reproduce

namespace A
{
    public interface ITest
    {
        [Post("/")]
        public Task<object> Test1(object test);
    }
}

namespace B
{
    public interface ITest
    {
        [Post("/")]
        Task<object> Test2(object test);
    }
}

namespace C
{
    public interface ITest
    {
        [Post("/")]
        Task<object> Test3(object test);
    }
}

Reproduction repository

No response

Expected behavior

Screenshots šŸ–¼ļø

No response

IDE

Visual Studio 2022

Operating system

Windows 10

Version

No response

Device

No response

Refit Version

6.3.2

Additional information ā„¹ļø

No response

anaisbetts commented 1 year ago

Can you contribute a PR that adds this as a test case?

chrstophr-wltrs commented 10 months ago

It actually looks like there are several test cases which check for something similar to this.

Should these tests be modified in some way so that they accurately check for 3 interfaces of the same name, instead of just 2?

ChrisPulman commented 2 weeks ago

V7.2.1 should resolve this issue, thank you for your feedback. If you identify anything that didn't get resolved please raise a new issue with the updated information, thank you.

github-actions[bot] commented 2 days ago

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.