NeVeSpl / NTypewriter

File/code generator using Scriban text templates populated with C# code metadata from Roslyn API.
https://nevespl.github.io/NTypewriter/
MIT License
126 stars 24 forks source link

Bug: Action.Url is not using the RoutePrefix attribute of the class to build the Url #16

Closed gregveres closed 3 years ago

gregveres commented 3 years ago

I have the following class:

    [RoutePrefix("api/AdServer/AdImage")]
    public class AdImageController : OurBaseApiController
    {
        [HttpGet]
        [Route("{adId}/image", Name = "AdServerImage")]
        public async Task<HttpResponseMessage> GetImage(int adId, int userId)
        {
        }
    }

When I call Action.Url method for the GetImage method, the return value is: ?adId=${adId}&userId=${userId}

But the real Url should be:

api/AdServer/AdImage/?adId=${adId}&userId=${userId}

The issue is that the RoutePrefix attribute on the class isn't being taken into consideration when building the Url.

gregveres commented 3 years ago

I think you will see this when you look at the code, but I just realized that the bug is deeper than just not looking at the RoutePrefix attribute. In the example I gave above, I was wrong on what the real Url should be because the Route attribute has parameter. So the real Url should be:

api/AdServer/AdImage/{adId}/image/?userId=${userId}

gregveres commented 3 years ago

@NeVeSpl Thank you for this fix. It makes the Action.Url much, much better.

I am going through and comparing a bunch of urls from Typewriter to NTypewriter with this fix. There is one case that has jumped out. I will open a new issue for that case. I want to do more investigation to see if I can figure out what is really triggering it. Oh, it might be the second optional parameter isn't being picked up or something.