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

Different behavior when using fluent api versus attributes - reporting deprecated apis - Asp.Net Core #47

Closed
AdamDotNet opened this issue Nov 4, 2016 · 2 comments
Assignees
Labels

Comments

@AdamDotNet
Copy link

Given the ASP.NET Core controller class

[ApiVersion("1.0", Deprecated = true)]
[ApiVersion("2.0")]
[Route("api/v{version:apiVersion}/[controller]")]
public class ValuesController : Controller
{
    [HttpGet]
    [MapToApiVersion("1.0")]
    public IActionResult Version1Method()
    {
        return Json(new { ApiVersion = HttpContext.GetRequestedApiVersion().ToString("v"), Hey = 1, Look = 2 });
    }

    [HttpGet]
    [MapToApiVersion("2.0")]
    public IActionResult Version2Method()
    {
        return Json(new { ApiVersion = HttpContext.GetRequestedApiVersion().ToString("v"), Hey = 2, Look = 4 });
    }
}

and Startup includes

services.AddApiVersioning(options => options.ReportApiVersions = true);

The response headers include the supported and deprecated versions

api-deprecated-versions: 1.0
api-supported-versions: 2.0

But with the following controller class

[Route("api/v{version:apiVersion}/[controller]")]
public class ValuesController : Controller
{
    [HttpGet]
    public IActionResult Version1Method()
    {
        return Json(new { ApiVersion = HttpContext.GetRequestedApiVersion().ToString("v"), Hey = 1, Look = 2 });
    }

    [HttpGet]
    public IActionResult Version2Method()
    {
        return Json(new { ApiVersion = HttpContext.GetRequestedApiVersion().ToString("v"), Hey = 2, Look = 4 });
    }
}

And Startup includes

services.AddApiVersioning(options =>
{
    options.ReportApiVersions = true;
    options.Conventions.Controller<ValuesController>()
        .HasDeprecatedApiVersion(1, 0)
        .HasApiVersion(2, 0)
        .Action(c => c.Version1Method()).MapToApiVersion(1, 0)
        .Action(c => c.Version2Method()).MapToApiVersion(2, 0);
});

The response headers only include the supported versions

api-supported-versions: 2.0

Expectation was that by ReportingApiVersions being set to true that the headers would be the same whether I used the fluent api or attributes. Either the attributes are erroneously advertising deprecated versions, or the fluent api are erroneously not advertising the deprecated versions. My assumption is the attributes are doing the right thing, advertising both the supported and deprecated versions.

@commonsensesoftware
Copy link
Collaborator

This appears to be a bug. I'm not sure how this scenario was missed in the test cases. I will investigate.

@commonsensesoftware
Copy link
Collaborator

It's a confirmed bug. The deprecated API versions (only) are not properly aggregated in the API version model. I have found and fixed the issue. Expect a new version of the package within a day.

commonsensesoftware pushed a commit that referenced this issue Nov 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants