34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using Swashbuckle.AspNetCore.Swagger;
|
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace TTSW.Common
|
|
{
|
|
public class SwaggerFileUploadOperation : IOperationFilter
|
|
{
|
|
// Add options for web api needed upload file controls
|
|
// http://www.talkingdotnet.com/how-to-upload-file-via-swagger-in-asp-net-core-web-api/
|
|
|
|
public void Apply(Operation operation, OperationFilterContext context)
|
|
{
|
|
// Map to HttpPost api/Attachment/UploadMultipleFiles
|
|
if (operation.OperationId.ToLower() == "upload" && operation.Tags[0].ToLower() == "attach_file")
|
|
{
|
|
operation.Parameters.Clear();
|
|
operation.Parameters.Add(new NonBodyParameter
|
|
{
|
|
Name = "file",
|
|
In = "formData",
|
|
Description = "Upload File",
|
|
Required = true,
|
|
Type = "file"
|
|
});
|
|
operation.Consumes.Add("multipart/form-data");
|
|
}
|
|
}
|
|
}
|
|
}
|