diff options
| author | Bond-009 <bond.009@outlook.com> | 2021-02-11 17:42:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-11 17:42:28 +0100 |
| commit | 76d66e0dee62998a211c4f720e8f2800458d7f23 (patch) | |
| tree | 8e3d3f85ba0c5812027c3796c3cbf4517ec69e9a /Jellyfin.Server/Filters/FileRequestFilter.cs | |
| parent | a2ac4d3dd77623ada99d76a2bdccbd076246253a (diff) | |
| parent | d5f0b046bb21dea0c120aa27f68fabc5947a8f1d (diff) | |
Merge pull request #5208 from crobibero/api-post-image
Add image file accept to openapi
Diffstat (limited to 'Jellyfin.Server/Filters/FileRequestFilter.cs')
| -rw-r--r-- | Jellyfin.Server/Filters/FileRequestFilter.cs | 43 |
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; + } + } +} |
