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

AV0011: Remove unnecessary default API version

Value
Rule IDAV0011
CategoryStyle
Fix isNon-breaking

Cause

The default API version is assigned the value it already has.

Rule Description

The default API version is 1.0 unless it is configured otherwise. Assigning that same version restates what the options were already given.

Consider the following code:

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

ApiVersion.Default is 1.0, which is what the options start with. Writing new ApiVersion( 1, 0 ) or new ApiVersion( 1.0 ) states the same version a different way and is equally unnecessary.

How to Fix Violations

Remove the assignment.

builder.Services.AddApiVersioning();

When to Suppress Warnings

It is safe to suppress this rule if you prefer the default API version to be stated explicitly so that a future change to it is deliberate rather than inherited.