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

AV0020: Remove unnecessary API explorer

Value
Rule IDAV0020
CategoryStyle
Fix isNon-breaking

Cause

The endpoints API explorer is added alongside the versioned API explorer, which already adds it.

Rule Description

AddApiExplorer() adds the endpoints API explorer itself, as do the OData and OpenAPI variants on their way to their own. Calling AddEndpointsApiExplorer() next to any of them repeats a registration that has already been made.

Consider the following code:

var builder = WebApplication.CreateBuilder( args );

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddApiVersioning().AddApiExplorer();

AddApiExplorer() covers the call above it.

How to Fix Violations

Remove the call to AddEndpointsApiExplorer().

var builder = WebApplication.CreateBuilder( args );

builder.Services.AddApiVersioning().AddApiExplorer();

When to Suppress Warnings

It is safe to suppress this rule. The extra call is redundant rather than wrong.