All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 26m25s
35 lines
1.0 KiB
C#
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" }
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|