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
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.
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.
Please try v6.0-preview.84 and file bugs as you come across them.
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
.Create(CreateOrganizationModel)'
RefitStubs.g.cs(214, 61): [CS0535] 'AutoGeneratedIOrganizationClientService' does not implement interface member 'IRefitDefaultService.Update(UpdateOrganizationModel)'
RefitStubs.g.cs(214, 61): [CS0535] 'AutoGeneratedIOrganizationClientService' does not implement interface member 'IRefitDefaultService.GetById(Guid)'
RefitStubs.g.cs(214, 61): [CS0535] 'AutoGeneratedIOrganizationClientService' does not implement interface member 'IRefitDefaultService.Disable(Guid)'
RefitStubs.g.cs(214, 61): [CS0535] 'AutoGeneratedIOrganizationClientService' does not implement interface member 'IRefitDefaultService.Enable(Guid)'
RefitStubs.g.cs(214, 61): [CS0535] 'AutoGeneratedIOrganizationClientService' does not implement interface member 'IRefitDefaultService.List(GetOrganizationsListModel)'
Am I doing something wrong?
Something is still using an older refit version as the .g.cs file doesn't exist anymore.
If you can clean/rebuild/ restart VS, it'd be good to confirm this works for you in v6.
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
ProductName: macOS
ProductVersion: 11.2
BuildVersion: 20D64
I created an issue here to track this https://github.com/reactiveui/refit/issues/1061
Most helpful comment
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.