aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Filters
diff options
context:
space:
mode:
authorcrobibero <cody@robibe.ro>2021-02-10 16:12:52 -0700
committercrobibero <cody@robibe.ro>2021-02-10 16:12:52 -0700
commitd5f0b046bb21dea0c120aa27f68fabc5947a8f1d (patch)
treebc2c31e2967416858765f0b1a8be6ca1081ac245 /Jellyfin.Server/Filters
parentbd8c269ea2769a9684c7755633417e1e78d84a57 (diff)
Add image file accept to openapi
Diffstat (limited to 'Jellyfin.Server/Filters')
-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;
+ }
+ }
+}