我正在使用 .NetCore 3 和 Swagger 5.0.0-rc4。我正在尝试使用 Swagger 上传文件(图像)但它不起作用,因为 IOperationFilter 甚至 Swashbuckle.AspNetCore.Swagger 中的 apply 方法缺少一些属性。例如 NonBodyParameter 和 Consumes 不会在 Swagger 5.0 中退出
有没有人使用面临同样的问题或试图解决它?
public class FileOperationFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
if (operation.OperationId.ToLower() == "apivaluesuploadpost")
{
operation.Parameters.Clear();
operation.Parameters.Add(new **NonBodyParameter**
{
Name = "uploadedFile",
In = "formData",
Description = "Upload File",
Required = true,
Type = "file"
});
operation.**Consumes**.Add("multipart/form-data");
}
}
}
Run Code Online (Sandbox Code Playgroud)