Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

AV0012: Invalid default API version

Value
Rule IDAV0012
CategoryUsage
Fix isBreaking

Cause

The default API version is version-neutral.

Rule Description

The default API version is the version applied to a request that did not ask for one. Version-neutral is not a version; it is the absence of one. A request cannot be resolved to it, so it can never serve as a default.

Consider the following code:

builder.Services.AddApiVersioning(
    options =>
    {
        options.DefaultApiVersion = ApiVersion.Neutral;
    } );

ApiVersion.Neutral cannot be the default for either the API versioning options or the API explorer options.

How to Fix Violations

Assign a real API version, or remove the assignment and let the default of 1.0 stand.

builder.Services.AddApiVersioning(
    options =>
    {
        options.DefaultApiVersion = new ApiVersion( 2.0 );
    } );

If the intent was for endpoints to be reachable without naming a version, declare those endpoints version-neutral instead of making the default neutral.

When to Suppress Warnings

It is never safe to suppress this rule. No request can ever resolve to a version-neutral default.