AV0020: Remove unnecessary API explorer
| Value | |
|---|---|
| Rule ID | AV0020 |
| Category | Style |
| Fix is | Non-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.