phronCare/phronCare.API/Helpers/FileUploadOperationFilter.cs
Leandro Hernan Rojas 369190695b
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 26m25s
Add Massive Import Products
2025-07-14 16:16:05 -03:00

35 lines
1.0 KiB
C#

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" }
}
}
}
};
}
}