jellyfin/Jellyfin.Server/Filters/ParameterObsoleteFilter.cs
Joshua M. Boniface ed333dec43 Merge pull request #5069 from crobibero/obsolete-param
(cherry picked from commit 4b6b90e0b14743581c5606a37249d86e291afc95)
Signed-off-by: Joshua M. Boniface <joshua@boniface.me>
2021-01-23 15:39:35 -05:00

38 lines
1.2 KiB
C#

using System;
using System.Linq;
using Jellyfin.Api.Attributes;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
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;
}
}
}
}
}
}
}