在使用Swashbuckle上传文件的时候,在接口文档中希望看到上传控件,但是C#中,没有FromBodyAttribute这个特性,所以需要在运行时,修改参数的swagger属性。
 
首先看下,最终效果:
Abp中SwaggerUI的接口文档添加上传文件参数类型
 
 
下面介绍实现。
 
实现原理,通过swagger提供的filter,找到action中带有SwaggerFileUpload特性的参数,然后给swagger operaion.parameters添加一个自定义的参数,即文件类型参数即可。
 
(1)定义SwaggerFileUploadAttribute。
[AttributeUsage(AttributeTargets.Parameter)]
public class SwaggerFileUploadAttribute : Attribute
{
public bool Required { get; private set; }
 
public SwaggerFileUploadAttribute(bool Required = true)
{
this.Required = Required;
}
}
View Code

 

相关文章:

  • 2022-12-23
  • 2021-12-18
  • 2022-02-07
  • 2021-12-03
  • 2021-12-06
  • 2021-08-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-03
  • 2021-07-14
  • 2021-12-08
  • 2021-05-20
  • 2021-11-26
  • 2021-12-14
相关资源
相似解决方案