You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Refit interfaces do not implement base interface non refit methods #1801
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()'vargitHubApi=RestService.For<IGeneratedInterface>("https://api.github.com");publicinterfaceIGeneratedInterface:IBaseInterface{[Get("/users")]Task<string>Get();}publicinterfaceIBaseInterface{voidNonRefitMethod();}
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.
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[/+]on Sep 3, 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.
interfaceIBase{TaskDo();// Not a refit method, refit will not generate a method for this.}interfaceIDerived{[get("/")]TaskDo();// This refit method will hide member IBase.Do()}IDerivedderived=RestService.For<IDerived>();derived.Do()// calls the IDerived implementation for Do()varbase=(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".
@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.
Activity
[-][Bug]: Refit tnterface do not implemt base interface non refit methods[/-][+][Bug]: Refit interfaces do not implement base interface non refit methods[/+]TimothyMakkison commentedon Sep 4, 2024
Related #1687
TimothyMakkison commentedon 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(derivedMethodswill always return an empty set.The problem arises when we consider interface inheritance and manual casting. For instance
Refit.Tests\RestService.InheritedInterfaceWithoutRefitInBaseMethodsTestfails 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.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 commentedon Oct 20, 2024
@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.
github-actions commentedon 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.