Skip to content

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

Closed

Description

@TimothyMakkison

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

Activity

  1. 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
  2. TimothyMakkison commented on Sep 4, 2024

    @TimothyMakkison
    CollaboratorAuthor

    Related #1687

  3. TimothyMakkison commented on Oct 10, 2024

    @TimothyMakkison
    CollaboratorAuthor

    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".

  4. ChrisPulman commented on Oct 20, 2024

    @ChrisPulman
    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.

  5. github-actions commented on Nov 4, 2024

    @github-actions

    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.

  6. locked as resolved and limited conversation to collaborators on Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions