Skip to content

MapToApiVersion not descovered but still able to hit the route #735

Closed
@schadowfax

Description

@schadowfax

Please consider the following case.

Because version 1.0 is not defined on the controller in a ApiVersionAttribute it is not discovered a not declare an API version. Just like i want because from this moment on i don't want to support this version any longer. My swagger documentation that is dependen on the IApiVersionDescriptionProvider works correctly and is no longer generating documentation for version1. When i make a api call to version 2.1 and check the returned version headers there is also only the supported version 2.1 & the deprecated version 2.0. Just as I excpected.

But when i make a call to version 1.0 i still hit the endpoint and the apiversion still doesn't return 1.0 as a supported version. I was hoping this would return a 400 bad request with the "UnsupportedApiVersion" error message and with the headers descriping the versions 2.0&2.1.

The reason i was exploring this behavior is that we want to make it possible to upgrade our microservice versions through adding the ApiVersionAttribute for certain version at runtime through some configuration. So we don't need to make a new build because the Getdefault route will be mapped for those higher apiversions.

// 👇 Declare both versions
[ApiVersion("2.0", Deprecated = true)]
[ApiVersion("2.1")]
[Route("v{version:apiVersion}/HelloWorld")] // Support path versioning
[ApiController]
public class HelloWorldController : ControllerBase
{

    // 👇 Map to v1.0
    [MapToApiVersion("1.0")]
    public string Get1() => "v1.0";

    // 👇 Map to v2.0
    [MapToApiVersion("2.0")]
    public string Get2() => "v2.0";

    // 👇 Map to all versions defined on the controller that not already have a mapping
    [MapToApiVersion("2.1")]
    public string Getdefault() => $"{forExamplePerposeHereIsVersionReturned}";
}

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions