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

AV0001: Invalid API version

Value
Rule IDAV0001
CategoryUsage
Fix isBreaking

Cause

An API version expressed as literal text is invalid.

Rule Description

Some call sites allow specifying an API version as a string. If the format of the API version is invalid, it is not uncovered until runtime when the text is parsed.

Consider the following code:

[ApiController]
[ApiVersion("abc")]
[Route("[controller]")]
public class ExampleController : ControllerBase
{
    [HttpGet]
    public IActionResult Get() => Ok();
}

The text "abc" is not a valid API version. This would not detected until runtime.

How to Fix Violations

Update the API version to be well-formed. In addition, consider using one of the typed value forms that allow specifying literal numerics to avoid common mistakes.

[ApiController]
[ApiVersion("1.0")]
[Route("[controller]")]
public class ExampleController : ControllerBase
{
    [HttpGet]
    public IActionResult Get() => Ok();
}

When to Suppress Warnings

It is never safe to suppress this rule because a runtime exception will be thrown when the text is parsed.