-
-
Notifications
You must be signed in to change notification settings - Fork 746
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
Stub anything that looks like a Refit interface #67
Conversation
// find any Refit interfaces | ||
// NB: This falls down in the tests unless we add an explicit "using Refit;", | ||
// but we can rely on this being there in any other file | ||
if (nodes.OfType<UsingDirectiveSyntax>().All(u => u.Name.ToFullString() != "Refit")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing this check here instead of in HasRefitHttpMethodAttribute
means that the method could return true
for something that's doesn't actually have a Refit attribute (i.e. one with a different "Get" or "Post" attribute). I'm pretty sure it doesn't matter as long as we have the check here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could roll down the "using" lists to make sure they reference Refit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean? I think that's what I'm doing here - my point was just that I'm doing it here and not in the method that looks for Refit attributes.
I could take the rolled up list all usings here and pass it in as a parameter, then it's not going to be traversing the whole tree each time the method is called. I'm conscious of the fact that this runs as part of the build so we need to make it as fast as possible. Maybe it's still micro-optimising though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm dumb, I just read the comment and not the code, disregard :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
One more thing I've noticed: because we're looking for interfaces where any method has a Refit attribute and not all methods have Refit attributes, we could be stubbing methods cannot possibly work. Do you think it's worth:
|
Throw a `NotImplementedException` when someone calls a method that we won't have an implementation for.
@paulcbetts I think this is ready to go.
|
Looks great! Thanks @bennor! |
@paulcbetts could you perhaps push this to nuget? |
Awesome! 👍 |
This should resolve #65.
InterfaceStubGenerator
now looks for any interface in a file withusing Refit;
that has at least one method with a[Get|Head|Post|Put|Delete(.*)]
attribute on it.I have a couple of concerns about the approach, but I'll comment in-line so it makes more sense.