Skip to content

MapToApiVersion on a controller action prevents other actions from executing #884

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

Closed
overdunne opened this issue Oct 3, 2022 · 1 comment · Fixed by #879
Closed

MapToApiVersion on a controller action prevents other actions from executing #884

overdunne opened this issue Oct 3, 2022 · 1 comment · Fixed by #879
Assignees

Comments

@overdunne
Copy link

If I have an action [HttpGet("{id}")], and [MapToApiVersion("1.5")], then that method will be invoked instead of another method with a different route.

For the controller below, if I invoke http://localhost:5167/v1.5/Message/Test, then the Id method instead is run. If I remove the MapToApiVersion attribute, then it behaves as expected.

[Route("v{version:apiVersion}/[controller]")]
[ApiController]
[ApiVersion("1.5")]
[ApiVersion("1.6")]
public class MessageController
{
    [HttpGet("Test")]
    public string Get()
    {
        return "Test";
    }

    [HttpGet("{id}")]
    [MapToApiVersion("1.5")]
    public string Id(string id)
    {
        return "You asked for: " + id;
    }
}
@commonsensesoftware
Copy link
Collaborator

Confirmed; this is a bug. The issue is that explicit version matches are considered over implicit versions (match or map) without considering the score of the match. The Id route overlaps with Get, but Get has a lower score (e.g. it's a better match). Get isn't being resolved because it is an implicit version match (e.g. no explicit mapping).

This will be fixed in 6.1 which should be this week. You can work around the issue by explicitly mapping versions to Get.

[HttpGet("Test")]
[MapToApiVersion("1.5")]
[MapToApiVersion("1.6")]
public string Get() => "Test";

commonsensesoftware added a commit that referenced this issue Oct 3, 2022
@commonsensesoftware commonsensesoftware mentioned this issue Oct 3, 2022
4 tasks
commonsensesoftware added a commit that referenced this issue Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants