Skip to content

Commit

Permalink
feat: generate code for derived non refit methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMakkison committed Oct 10, 2024
1 parent 26cfb28 commit ed55fc9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion InterfaceStubGenerator.Shared/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ bool nullableEnabled
.Where(m => IsRefitMethod(m, httpMethodBaseAttributeSymbol))
.ToArray();
var derivedNonRefitMethods = derivedMethods
.Except(derivedMethods, SymbolEqualityComparer.Default)
.Except(derivedRefitMethods, SymbolEqualityComparer.Default)
.Cast<IMethodSymbol>()
.ToArray();

Expand Down
3 changes: 1 addition & 2 deletions Refit.GeneratorTests/Incremental/InheritanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public interface IGitHubApi : IDisposable
[Fact]
public void InheritFromInterfaceDoesRegenerate()
{
// TODO: this currently generates invalid code see issue #1801 for more information
var syntaxTree = CSharpSyntaxTree.ParseText(TwoInterface, CSharpParseOptions.Default);
var compilation1 = Fixture.CreateLibrary(syntaxTree);

Expand All @@ -94,6 +93,6 @@ public interface IGitHubApi : IBaseInterface
"""
);
var driver2 = driver1.RunGenerators(compilation2);
TestHelper.AssertRunReasons(driver2, IncrementalGeneratorRunReasons.Cached);
TestHelper.AssertRunReasons(driver2, IncrementalGeneratorRunReasons.Modified);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public RefitGeneratorTestIGeneratedInterface(global::System.Net.Http.HttpClient

return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
}

/// <inheritdoc />
void global::RefitGeneratorTest.IBaseInterface.NonRefitMethod()
{
throw new global::System.NotImplementedException("Either this method has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument.");
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
Diagnostics: [
{
Id: RF001,
Title: Refit types must have Refit HTTP method attributes,
Severity: Warning,
WarningLevel: 1,
Location: : (19,9)-(19,23),
MessageFormat: Method {0}.{1} either has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument,
Message: Method IBaseInterface.NonRefitMethod either has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument,
Category: Refit
}
]
}

0 comments on commit ed55fc9

Please sign in to comment.