Skip to content
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 interfaces do not implement base interface non refit methods #1801

Closed
TimothyMakkison opened this issue Sep 3, 2024 · 4 comments · Fixed by #1875
Closed

[Bug]: Refit interfaces do not implement base interface non refit methods #1801

TimothyMakkison opened this issue Sep 3, 2024 · 4 comments · Fixed by #1875
Labels

Comments

@TimothyMakkison
Copy link
Contributor

TimothyMakkison commented Sep 3, 2024

Describe the bug 🐞

Generated refit interfaces are invalid if the base interface has a non refit method.

Step to reproduce

// 'Generated.IGeneratedInterface' does not implement interface member 'IBaseInterface.NonRefitMethod()'
var gitHubApi = RestService.For<IGeneratedInterface>("https://api.github.com");

public interface IGeneratedInterface : IBaseInterface
{
    [Get("/users")]
    Task<string> Get();
}

public interface IBaseInterface
{
    void NonRefitMethod();
}

Reproduction repository

https://github.com/reactiveui/refit

Expected behavior

Refit should generate stub implementations which throw an error when called to satisfy the interface. Similar to how non refit methods are handled in non derived refit interfaces.

IDE

Rider Windows

@TimothyMakkison TimothyMakkison changed the title [Bug]: Refit tnterface do not implemt base interface non refit methods [Bug]: Refit interfaces do not implement base interface non refit methods Sep 3, 2024
@TimothyMakkison
Copy link
Contributor Author

Related #1687

@TimothyMakkison
Copy link
Contributor Author

TimothyMakkison commented Oct 10, 2024

This is a pretty easy fix as all the required code is present, just an intentional???/bug prevents it from functioning, see here. derivedMethods.Except(derivedMethods will always return an empty set.

The problem arises when we consider interface inheritance and manual casting. For instance Refit.Tests\RestService.InheritedInterfaceWithoutRefitInBaseMethodsTest fails as it relies upon Refit only generating the method for a "more derived" refit method and not generating an explicit implementation for the base, defaulting to the only implementation.

interface IBase {
   Task Do(); // Not a refit method, refit will not generate a method for this.
}

interface IDerived {
    [get("/")]
    Task Do(); // This refit method will hide member IBase.Do()
}

IDerived derived = RestService.For<IDerived>();
derived.Do() // calls the IDerived implementation for Do()

var base = (IBase)derived;
base.Do(); // still calls the IDerived implementation for Do()
// with my fix this would call `IBase.Do()` and throw an exception. A breaking change

Because of this, my fix would be a breaking change (likely minor, I doubt many people rely on this) unless I take measures to circumvent this. I can either keep this behaviour or change it. I'm not sure what would be expected by the user and what is considered "correct".

@ChrisPulman
Copy link
Member

@TimothyMakkison
From a technical perspective, I would expect IBase.Do() to be executed when cast to IBase, if it's currently looking for the first Refit layer to execute then this is breaking inheritance and in my opinion should be corrected. At this point in time the next Release will be a breaking Release anyway so should be expected to have changes to the operation.

Copy link

github-actions bot commented Nov 4, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants