aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Filters/FileRequestFilter.cs
diff options
context:
space:
mode:
authorBond-009 <bond.009@outlook.com>2021-02-11 17:42:28 +0100
committerJoshua M. Boniface <joshua@boniface.me>2021-02-21 13:30:31 -0500
commitd53120602cadb57431bed8f7e74c1874179ac1f1 (patch)
tree13ddd27edcba48f3ca2830cb8bc799ccecba96e9 /Jellyfin.Server/Filters/FileRequestFilter.cs
parentda09257d58c33dce24aafb05dfdadad05e642059 (diff)
Merge pull request #5208 from crobibero/api-post-image
Add image file accept to openapi (cherry picked from commit 76d66e0dee62998a211c4f720e8f2800458d7f23) Signed-off-by: Joshua M. Boniface <joshua@boniface.me>
Diffstat (limited to 'Jellyfin.Server/Filters/FileRequestFilter.cs')
-rw-r--r--Jellyfin.Server/Filters/FileRequestFilter.cs43
1 files changed, 43 insertions, 0 deletions
diff --git a/Jellyfin.Server/Filters/FileRequestFilter.cs b/Jellyfin.Server/Filters/FileRequestFilter.cs
new file mode 100644
index 000000000..69e10994f
--- /dev/null
+++ b/Jellyfin.Server/Filters/FileRequestFilter.cs
@@ -0,0 +1,43 @@
+using System.Collections.Generic;
+using Jellyfin.Api.Attributes;
+using Microsoft.OpenApi.Models;
+using Swashbuckle.AspNetCore.SwaggerGen;
+
+namespace Jellyfin.Server.Filters
+{
+ /// <inheritdoc />
+ public class FileRequestFilter : IOperationFilter
+ {
+ /// <inheritdoc />
+ public void Apply(OpenApiOperation operation, OperationFilterContext context)
+ {
+ foreach (var attribute in context.ApiDescription.ActionDescriptor.EndpointMetadata)
+ {
+ if (attribute is AcceptsFileAttribute acceptsFileAttribute)
+ {
+ operation.RequestBody = GetRequestBody(acceptsFileAttribute.GetContentTypes());
+ break;
+ }
+ }
+ }
+
+ private static OpenApiRequestBody GetRequestBody(IEnumerable<string> contentTypes)
+ {
+ var body = new OpenApiRequestBody();
+ var mediaType = new OpenApiMediaType
+ {
+ Schema = new OpenApiSchema
+ {
+ Type = "string",
+ Format = "binary"
+ }
+ };
+ foreach (var contentType in contentTypes)
+ {
+ body.Content.Add(contentType, mediaType);
+ }
+
+ return body;
+ }
+ }
+}