Replies: 2 comments 4 replies
-
There's a few things going on here. You are correct that there is no way to indicate that the When you say Swagger, I presume you mean Swashbuckle. There is no official mechanism that connects the API Explorer with the concept of deprecation. Swashbuckle and API Versioning support these concepts, but you are required to stitch them together (unfortunately). The simplest way to do that in Swashbuckle is to use an public class SwaggerDefaultValues : IOperationFilter
{
public void Apply( OpenApiOperation operation, OperationFilterContext context )
{
// Swashbuckle ↓ API Versioning extension method ↓
operation.Deprecated |= context.ApiDescription.IsDeprecated();
}
} That isn't the only information that doesn't get picked up automatically by Swashbuckle, but it might be the only thing you need. For a full end-to-end solution, see the OpenAPI example project. |
Beta Was this translation helpful? Give feedback.
-
The swagger filter was already custom, so this feels like a good place. Of course i could have hard coded it in the filter already, but this feels cleaner. Still, it might be nice to have some way of marking versions deprecated inside AddApiVersioning(), like having a delegate member in it that allows you to determine if a version is deprecated. That also would allow you to centrally manage deprecation, instead of in each controller |
Beta Was this translation helpful? Give feedback.
-
I am trying to add versioning to an existing project and part of it is that all code should move to a new route, the old routes have been declared version x, which is deprecated, however, I am unable to get the apiversiondescription in swagger to be declared deprecated.
I assume because the object is initialized from the DefaultApiVersion, which has no deprecated support, and not from the ApiVersionAttribute on my controllers, which do have it.
Any idea how I can still get my version be seen as deprecated?
Below the relevant snippets....
Remco
Beta Was this translation helpful? Give feedback.
All reactions