diff options
Diffstat (limited to 'Jellyfin.Server/Filters/ParameterObsoleteFilter.cs')
| -rw-r--r-- | Jellyfin.Server/Filters/ParameterObsoleteFilter.cs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Jellyfin.Server/Filters/ParameterObsoleteFilter.cs b/Jellyfin.Server/Filters/ParameterObsoleteFilter.cs new file mode 100644 index 000000000..b9ce221f5 --- /dev/null +++ b/Jellyfin.Server/Filters/ParameterObsoleteFilter.cs @@ -0,0 +1,36 @@ +using System; +using System.Linq; +using Jellyfin.Api.Attributes; +using Microsoft.OpenApi.Models; +using Swashbuckle.AspNetCore.SwaggerGen; + +namespace Jellyfin.Server.Filters +{ + /// <summary> + /// Mark parameter as deprecated if it has the <see cref="ParameterObsoleteAttribute"/>. + /// </summary> + public class ParameterObsoleteFilter : IOperationFilter + { + /// <inheritdoc /> + public void Apply(OpenApiOperation operation, OperationFilterContext context) + { + foreach (var parameterDescription in context.ApiDescription.ParameterDescriptions) + { + if (parameterDescription + .CustomAttributes() + .OfType<ParameterObsoleteAttribute>() + .Any()) + { + foreach (var parameter in operation.Parameters) + { + if (parameter.Name.Equals(parameterDescription.Name, StringComparison.Ordinal)) + { + parameter.Deprecated = true; + break; + } + } + } + } + } + } +} |
