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

Support inheriting from HttpMethodAttribute's children #657

Closed
JarkoDubbeldam opened this issue May 2, 2019 · 3 comments
Closed

Support inheriting from HttpMethodAttribute's children #657

JarkoDubbeldam opened this issue May 2, 2019 · 3 comments
Labels
enhancement semantic-analysis Bug reports/change requests that would require semantic analysis in the stub generator up-for-grabs

Comments

@JarkoDubbeldam
Copy link

Is your feature request related to a problem? Please describe.

I currently have an attribute that inherits from PostAttribute, that does some additional work to set its path property. The problem with that is that the codegeneration tool that implements the interface looks for a PostAttribute (or another of the HttpMethodAttribute-family), and thus skips over the interface altogether. Then at runtime resolving the interface will fail and throw an exception.

Describe the solution you'd like

Preferably, the code generation would use semantic analysis to check whether an interface has attributes that inherit from HttpMethodAttribute, instead of looking for the syntax tokens.

There are currently two places in the code where this would fail:

Describe alternatives you've considered

If the adjustment of the code-generation is not feasible, it would maybe be nice to mark the HttpMethodAttribute's children as sealed, so that it is clear that inheriting from them is not supported by the library.

Describe suggestions on how to achieve the feature

I don't think this feature is possible to achieve with just syntax analysis. I am not experienced enough to know how feasible this is with semantic analysis added.

It appears from debugging that this feature shouldn't affect the Refit project itself. When resolving the interface at runtime, the code works fine up to the point that the generated type is needed, which then fails because the code wasn't generated.

Additional context

  public class LazyPostAttribute : PostAttribute {
    public LazyPostAttribute([CallerMemberName] string methodName = null) : base("/" + methodName) {
    }
  }


  public interface IPostInterface {
    [Post("/SomePostMethod")]
    Task SomePostMethod([Body] object input);
  }

  public interface ILazyPostInterface {
    [LazyPost]
    Task SomePostMethod([Body] object input);
  }

    static void Main(string[] args) {
      var postInterface = RestService.For<IPostInterface>("http://localhost:8080/"); // Works
      var lazyPostInterface = RestService.For<ILazyPostInterface>("http://localhost:8080/"); // Does not work
    }
@bennor bennor added the semantic-analysis Bug reports/change requests that would require semantic analysis in the stub generator label Jun 11, 2019
@clairernovotny
Copy link
Member

Should be implemented in #1029

@clairernovotny
Copy link
Member

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

@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 14, 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

3 participants