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] Interface inheritance only works in same project #650

Closed
BenjaminAbt opened this issue Apr 14, 2019 · 9 comments
Closed

[BUG] Interface inheritance only works in same project #650

BenjaminAbt opened this issue Apr 14, 2019 · 9 comments
Labels
enhancement semantic-analysis Bug reports/change requests that would require semantic analysis in the stub generator up-for-grabs

Comments

@BenjaminAbt
Copy link

Describe the bug

The goal is to use interface inheritance from refit interfaces.
https://github.com/reactiveui/refit#interface-inheritance

This only works if all interfaces are in one project.
However, the following error occurs if the interfaces are not in the same project:

'AutoGeneratedITestRestClient' does not implement interface member 'IBaseRestClient.GetVersion()' Base.UnitTests

Project Base

public interface IBaseRestClient
{
    HttpClient Client { get; }

    [Get("/version")]
    Task<string> GetVersion();
}

Project Base.UnitTests

public interface ITestRestClient : IBaseRestClient
{
    [Get("/test")]
    Task<string> Test();
}

Generate Stubs:
GetVersion is missing here, but will be generated if in the same project.

/// <inheritdoc />
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.Diagnostics.DebuggerNonUserCode]
[Preserve]
[global::System.Reflection.Obfuscation(Exclude=true)]
partial class AutoGeneratedITestRestClient : ITestRestClient
{
    /// <inheritdoc />
    public HttpClient Client { get; protected set; }
    readonly IRequestBuilder requestBuilder;

    /// <inheritdoc />
    public AutoGeneratedITestRestClient(HttpClient client, IRequestBuilder requestBuilder)
    {
        Client = client;
        this.requestBuilder = requestBuilder;
    }

    /// <inheritdoc />
    Task<string> ITestRestClient.Test()
    {
        var arguments = new object[] {  };
        var func = requestBuilder.BuildRestResultFuncForMethod("Test", new Type[] {  });
        return (Task<string>)func(Client, arguments);
    }
}

Expected behavior
Stub should have all methods, even if inherited interfaces are located in different projects.

Sample Project
https://github.com/BenjaminAbt/RefitInheritance

@BenjaminAbt BenjaminAbt added the bug Something isn't working label Apr 14, 2019
@clairernovotny clairernovotny added bug enhancement up-for-grabs and removed bug Something isn't working bug labels May 7, 2019
@bennor bennor added the semantic-analysis Bug reports/change requests that would require semantic analysis in the stub generator label Jun 11, 2019
@Cantaria
Copy link

Cantaria commented Jul 19, 2019

Hi,
the same problem occurs when you use different namespaces.

I've uploaded the test project from my company here https://github.com/Cantaria/refitInheritanceTest

The project can't be build, because the ReFit interfaces (IDerivedServiceA) in the test-project are in different namespaces. If you put the interfaces into the same namespace, everything will work.

GitHub
Contribute to Cantaria/refitInheritanceTest development by creating an account on GitHub.

@steffencrespo
Copy link

steffencrespo commented Feb 24, 2020

I am having the same problem even though both the parent and the child interface belong to the same project under the same namespace.

Had to redefine all the methods from parent interface as new in the child interface in order to get it to work.

Right now I am using Refit 4.6.48; This issue is still open but I am going to upgrade my refit version and let y'all know if that makes a difference.

@clairernovotny
Copy link
Member

Please try v6.0-preview.84 and file bugs as you come across them.

@joaovieirabr
Copy link

joaovieirabr commented Feb 5, 2021

Hi,

I tried using refit with a generic interface, and got the same message, even with the most recent preview - 6.0.0-preview.128

Here is my case:

Generic Interface:

public interface IRefitDefaultService<TCreate, TUpdate, TDetail, TListQuery>
    {
        public Task<OperationResult<Guid>> Create([Body] TCreate command);
        public Task<OperationResult> Update(TUpdate command);
        public Task<OperationResult<TDetail>> GetById(Guid id);
        public Task<OperationResult> Disable(Guid id);
        public Task<OperationResult> Enable(Guid id);
        public Task<OperationResult<ListQueryResult<TDetail>>> List(TListQuery query);
    }

Refit Interface:

public interface IOrganizationClientService   : IRefitDefaultService<CreateOrganizationModel,UpdateOrganizationModel,OrganizationDetailModel, GetOrganizationsListModel>
    {
        [Post("/api/v1.0/rack/organizations/create")]
        public Task<OperationResult<Guid>> Create([Body] CreateOrganizationModel command);
        
        [Put("/api/v1.0/rack/organizations/update")]
        public Task<OperationResult> Update([Body] UpdateOrganizationModel command);
        
        [Get("/api/v1.0/rack/organizations/get?id={id}")]
        public Task<OperationResult<OrganizationDetailModel>> GetById(Guid id);
        
        [Delete("/api/v1.0/rack/organizations/disable")]
        public Task<OperationResult> Disable([Body] Guid id);
        
        [Put("/api/v1.0/rack/organizations/enable")]
        public Task<OperationResult> Enable([Body] Guid id);

        [Get("/api/v1.0/rack/organizations/list?Name={query.Name}&FilterValue={query.FilterValue}&PageNum={query.PageNum}&PageSize={query.PageSize}&SortByField={query.SortByField}&IsDescending={query.IsDescending}&IsActive={query.IsActive}")]
        public Task<OperationResult<ListQueryResult<OrganizationDetailModel>>> List(GetOrganizationsListModel query);
    }

and got the same error message:

RefitStubs.g.cs(214, 61): [CS0535] 'AutoGeneratedIOrganizationClientService' does not implement interface member 'IRefitDefaultService<CreateOrganizationModel, UpdateOrganizationModel, OrganizationDetailModel, GetOrganizationsListModel>.Create(CreateOrganizationModel)'
RefitStubs.g.cs(214, 61): [CS0535] 'AutoGeneratedIOrganizationClientService' does not implement interface member 'IRefitDefaultService<CreateOrganizationModel, UpdateOrganizationModel, OrganizationDetailModel, GetOrganizationsListModel>.Update(UpdateOrganizationModel)'
RefitStubs.g.cs(214, 61): [CS0535] 'AutoGeneratedIOrganizationClientService' does not implement interface member 'IRefitDefaultService<CreateOrganizationModel, UpdateOrganizationModel, OrganizationDetailModel, GetOrganizationsListModel>.GetById(Guid)'
RefitStubs.g.cs(214, 61): [CS0535] 'AutoGeneratedIOrganizationClientService' does not implement interface member 'IRefitDefaultService<CreateOrganizationModel, UpdateOrganizationModel, OrganizationDetailModel, GetOrganizationsListModel>.Disable(Guid)'
RefitStubs.g.cs(214, 61): [CS0535] 'AutoGeneratedIOrganizationClientService' does not implement interface member 'IRefitDefaultService<CreateOrganizationModel, UpdateOrganizationModel, OrganizationDetailModel, GetOrganizationsListModel>.Enable(Guid)'
RefitStubs.g.cs(214, 61): [CS0535] 'AutoGeneratedIOrganizationClientService' does not implement interface member 'IRefitDefaultService<CreateOrganizationModel, UpdateOrganizationModel, OrganizationDetailModel, GetOrganizationsListModel>.List(GetOrganizationsListModel)'

Am I doing something wrong?

@clairernovotny
Copy link
Member

Something is still using an older refit version as the .g.cs file doesn't exist anymore.

@clairernovotny
Copy link
Member

If you can clean/rebuild/ restart VS, it'd be good to confirm this works for you in v6.

@joaovieirabr
Copy link

joaovieirabr commented Feb 5, 2021

Hi,

I'm using MacOs, and already tried all the steps with Rider, VSCode and command line: same results :(

<PackageReference Include="Refit.HttpClientFactory" Version="6.0.0-preview.128" />

/Users/joaovieirabr/Projects/systemware/src/Shared/WebApiClient/InterfaceStubGenerator.Core/Refit.Generator.InterfaceStubGenerator/IOrganizationClientService_refit.cs(16,11): error CS0535: 'Generated.SystemwareWebApiClientRackIOrganizationClientService' does not implement interface member 'IRefitDefaultService<CreateOrganizationModel, UpdateOrganizationModel, OrganizationDetailModel, GetOrganizationsListModel>.Create(CreateOrganizationModel)' [/Users/joaovieirabr/Projects/systemware/src/Shared/WebApiClient/WebApiClient.csproj]
/Users/joaovieirabr/Projects/systemware/src/Shared/WebApiClient/InterfaceStubGenerator.Core/Refit.Generator.InterfaceStubGenerator/IOrganizationClientService_refit.cs(16,11): error CS0535: 'Generated.SystemwareWebApiClientRackIOrganizationClientService' does not implement interface member 'IRefitDefaultService<CreateOrganizationModel, UpdateOrganizationModel, OrganizationDetailModel, GetOrganizationsListModel>.Update(UpdateOrganizationModel)' [/Users/joaovieirabr/Projects/systemware/src/Shared/WebApiClient/WebApiClient.csproj]
/Users/joaovieirabr/Projects/systemware/src/Shared/WebApiClient/InterfaceStubGenerator.Core/Refit.Generator.InterfaceStubGenerator/IOrganizationClientService_refit.cs(16,11): error CS0535: 'Generated.SystemwareWebApiClientRackIOrganizationClientService' does not implement interface member 'IRefitDefaultService<CreateOrganizationModel, UpdateOrganizationModel, OrganizationDetailModel, GetOrganizationsListModel>.GetById(Guid)' [/Users/joaovieirabr/Projects/systemware/src/Shared/WebApiClient/WebApiClient.csproj]
/Users/joaovieirabr/Projects/systemware/src/Shared/WebApiClient/InterfaceStubGenerator.Core/Refit.Generator.InterfaceStubGenerator/IOrganizationClientService_refit.cs(16,11): error CS0535: 'Generated.SystemwareWebApiClientRackIOrganizationClientService' does not implement interface member 'IRefitDefaultService<CreateOrganizationModel, UpdateOrganizationModel, OrganizationDetailModel, GetOrganizationsListModel>.Disable(Guid)' [/Users/joaovieirabr/Projects/systemware/src/Shared/WebApiClient/WebApiClient.csproj]
/Users/joaovieirabr/Projects/systemware/src/Shared/WebApiClient/InterfaceStubGenerator.Core/Refit.Generator.InterfaceStubGenerator/IOrganizationClientService_refit.cs(16,11): error CS0535: 'Generated.SystemwareWebApiClientRackIOrganizationClientService' does not implement interface member 'IRefitDefaultService<CreateOrganizationModel, UpdateOrganizationModel, OrganizationDetailModel, GetOrganizationsListModel>.Enable(Guid)' [/Users/joaovieirabr/Projects/systemware/src/Shared/WebApiClient/WebApiClient.csproj]
/Users/joaovieirabr/Projects/systemware/src/Shared/WebApiClient/InterfaceStubGenerator.Core/Refit.Generator.InterfaceStubGenerator/IOrganizationClientService_refit.cs(16,11): error CS0535: 'Generated.SystemwareWebApiClientRackIOrganizationClientService' does not implement interface member 'IRefitDefaultService<CreateOrganizationModel, UpdateOrganizationModel, OrganizationDetailModel, GetOrganizationsListModel>.List(GetOrganizationsListModel)' [/Users/joaovieirabr/Projects/systemware/src/Shared/WebApiClient/WebApiClient.csproj]
    0 Warning(s)
    6 Error(s)
dotnet --version
5.0.102

sw_vers
ProductName:	macOS
ProductVersion:	11.2
BuildVersion:	20D64

@clairernovotny
Copy link
Member

I created an issue here to track this #1061

@github-actions
Copy link

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 Apr 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement semantic-analysis Bug reports/change requests that would require semantic analysis in the stub generator up-for-grabs
Projects
None yet
Development

No branches or pull requests

6 participants