phronCare/phronCare.API/Helpers/FileUploadOperationFilter.cs

35 lines
1.0 KiB
C#
Raw Normal View History

2025-07-14 16:16:05 -03:00
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
public class FileUploadOperationFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
var hasFormFile = context.MethodInfo.GetParameters()
.Any(p => p.ParameterType == typeof(IFormFile));
if (!hasFormFile) return;
operation.RequestBody = new OpenApiRequestBody
{
Content = {
["multipart/form-data"] = new OpenApiMediaType
{
Schema = new OpenApiSchema
{
Type = "object",
Properties = {
["file"] = new OpenApiSchema
{
Type = "string",
Format = "binary"
}
},
Required = { "file" }
}
}
}
};
}
}