AV0018: All endpoints are version-neutral
| Value | |
|---|---|
| Rule ID | AV0018 |
| Category | Usage |
| Fix is | Breaking |
Cause
Every endpoint in the application is version-neutral, so no API version is ever defined.
Rule Description
A version-neutral endpoint belongs to every API version that has been defined. Requests still route when nothing else is defined, which is why this can go unnoticed, but the API explorer describes an endpoint once per explicitly defined version. With none defined, it describes nothing at all and the generated documentation is empty.
Consider the following code:
var builder = WebApplication.CreateBuilder( args );
builder.Services.AddApiVersioning().AddApiExplorer();
var app = builder.Build();
app.MapGet( "/order", () => Results.Ok() ).IsApiVersionNeutral();
app.MapGet( "/customer", () => Results.Ok() ).IsApiVersionNeutral();
app.Run();
Neither endpoint defines an API version, so there is no version for the neutral endpoints to belong to.
An endpoint that declares nothing at all is a separate problem and is not reported here.
How to Fix Violations
Declare an explicit API version on at least one endpoint.
var app = builder.Build();
app.MapGet( "/order", () => Results.Ok() ).HasApiVersion( 1.0 );
app.MapGet( "/customer", () => Results.Ok() ).IsApiVersionNeutral();
app.Run();
When to Suppress Warnings
It is safe to suppress this rule if the endpoints that define the API versions are declared outside the compilation, such as in a referenced library. See version neutrality for what neutrality means and when it applies.