Closed
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Request with any api-version
is handled by controller and there are no api-supported-versions
header in response despite ReportApiVersions
is set to true
.
I used the Basic example with slight changes to reproduce the issue.
A successful status code is returned no matter which version is sent:
✔️ v1.0
❌ v2.0
❌ v9999
Expected Behavior
Request with unsupported version should return 4xx status code
Steps To Reproduce
.csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Asp.Versioning.Mvc" Version="6.2.1" />
</ItemGroup>
</Project>
Program.cs
var builder = WebApplication.CreateBuilder( args );
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddApiVersioning(
options =>
{
// reporting api versions will return the headers
// "api-supported-versions" and "api-deprecated-versions"
options.ReportApiVersions = true;
} )
.AddMvc();
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
TestController.cs
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
namespace ApiVersioningTest;
[ApiVersion("1.0")]
[Route( "api/v{version:apiVersion}/test" )]
public class TestController : ControllerBase
{
[HttpGet("version")]
public IActionResult Versioned(ApiVersion apiVersion)
{
return Ok(apiVersion);
}
}
Exceptions (if any)
No response
.NET Version
6.0.301
Anything else?
No response