AV0028: Sunset policy takes effect before deprecation
| Value | |
|---|---|
| Rule ID | AV0028 |
| Category | Usage |
| Fix is | Non-breaking |
Cause
An API is sunset before it is deprecated.
Rule Description
Deprecation announces that an API is going away and sunset is when it does, so the two are only in order when deprecation comes first. Taking effect on the same day is allowed.
Consider the following code:
builder.Services.AddApiVersioning(
options =>
{
options.Policies.Deprecate( 0.9 ).Effective( 2024, 6, 1 );
options.Policies.Sunset( 0.9 ).Effective( 2024, 1, 1 );
} );
The API is retired five months before its clients are told it is going away.
Only policies that some API reaches together are compared and only when both state a date that can be read as written. A date that comes from somewhere else is left alone because what it will be is not decided here.
How to Fix Violations
Move the sunset date on or after the deprecation date.
builder.Services.AddApiVersioning(
options =>
{
options.Policies.Deprecate( 0.9 ).Effective( 2024, 1, 1 );
options.Policies.Sunset( 0.9 ).Effective( 2024, 6, 1 );
} );
See version policies for how the dates are advertised to clients.
When to Suppress Warnings
It is safe to suppress this rule if the ordering is deliberate; for example, when an API is being retired without the usual notice and the deprecation is recorded after the fact.