diff options
| author | crobibero <cody@robibe.ro> | 2021-01-20 16:24:15 -0700 |
|---|---|---|
| committer | crobibero <cody@robibe.ro> | 2021-01-20 16:24:15 -0700 |
| commit | 59ff2c5b4b26a435751f1bbdecd8dc309f14e7da (patch) | |
| tree | 45fcd977891882a8e956f2ff6d5f3dd581edce25 /Jellyfin.Server/Filters | |
| parent | 215554bb4111cabae8ba1deacb534b947732b5e3 (diff) | |
Add ability to mark query parameter as obsolete.
Diffstat (limited to 'Jellyfin.Server/Filters')
| -rw-r--r-- | Jellyfin.Server/Filters/ParameterObsoleteFilter.cs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Jellyfin.Server/Filters/ParameterObsoleteFilter.cs b/Jellyfin.Server/Filters/ParameterObsoleteFilter.cs new file mode 100644 index 000000000..7e81070c5 --- /dev/null +++ b/Jellyfin.Server/Filters/ParameterObsoleteFilter.cs @@ -0,0 +1,37 @@ +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; + } + } + } + } + } + } +}
\ No newline at end of file |
