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] Constant strings in attributes not treated like regular strings #743

Closed
lobster2012-user opened this issue Sep 12, 2019 · 1 comment

Comments

@lobster2012-user
Copy link

Describe the bug

build - OK
runtime - OK

public interface IClient
{
     [Get("/path")]
     void Get();
}

compile - OK
runtime - FAILED:doesn't look like a Refit interface

public static class Paths
{
      public const string Path = "/path";
}
public interface IClient
{
     [Get(Paths.Path)]
     void Get();
}

It seems the problem is here.

 public bool HasRefitHttpMethodAttribute(MethodDeclarationSyntax method)
        {
            // We could also verify that the single argument is a string, 
            // but what if somebody is dumb and uses a constant?
            // Could be turtles all the way down.
            return method.AttributeLists.SelectMany(a => a.Attributes)
                         .Any(a => HttpMethodAttributeNames.Contains(a.Name.ToString().Split('.').Last()) &&
                                   a.ArgumentList.Arguments.Count == 1 &&
                                   a.ArgumentList.Arguments[0].Expression.Kind() == **SyntaxKind.StringLiteralExpression**);
        }

Is it possible to fix it?

@bennor
Copy link
Contributor

bennor commented Sep 12, 2019

Duplicate of #263

@bennor bennor marked this as a duplicate of #263 Sep 12, 2019
@bennor bennor closed this as completed Sep 12, 2019
@lock lock bot added the outdated label Dec 11, 2019
@lock lock bot locked and limited conversation to collaborators Dec 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants