Take this for example:
[Obsolete("Please use /Auth/Register instead")]
Swaggers UI shows its Obsolte but doesnt show the message, so is it possible to have the message inside the attribute show in the Swagger UI? (Without having to change library like this post says) Im using Swashbuckle.AspNetCore (Default with ASP.NET) v6.3 (OpenAPI / Swagger v2.0, v3.0)
This could be done in Swashbuckle with operation filter:
internal class ObsoleteOperationFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
operation.Description = operation.Deprecated ? context.MethodInfo.GetCustomAttribute<ObsoleteAttribute>()?.Message : operation.Description;
}
}
Then add the filter in the SwaggerGen configuration:
builder.Services.AddSwaggerGen(options =>
{
options.OperationFilter<ObsoleteOperationFilter>();
...
});
Now description of the operation would be replaced with a message from Obsolete attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With