- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用 NSwag 设置 Controller 方法,我可以在其中上传多部分/表单数据文件
[HttpPost]
[Route("{number:long}")]
[ValidateMimeMultipartContentFilter]
[SwaggerResponse(500, typeof(string), Description = "Error")]
public async Task<IHttpActionResult> Upload(long number)
{
//My backend code for file upload
}
但是我无法通过 NSwag 网络界面上传文件。我认为在 ASP.NET Core 中你有一个针对这个问题的属性,但我怎样才能在 Web Api 2 中获得这种支持
最佳答案
NSwag 不支持开箱即用的 Web API 2 文件上传,您需要创建一个操作处理器来创建文件上传参数。
我已经创建了自己的操作处理器
public class SwaggerFilChunkUploadOperationProcessor : IOperationProcessor
{
public Task<bool> ProcessAsync(OperationProcessorContext context)
{
var data = context.OperationDescription.Operation.Parameters;
//File upload
data.Add(new SwaggerParameter()
{
IsRequired = true,
Name = "file",
Description = "filechunk",
Type = JsonObjectType.File,
Kind = SwaggerParameterKind.FormData
});
//custom formdata (not needed for the file upload)
data.Add(new SwaggerParameter()
{
IsRequired = true,
Name = "file-name",
Description = "the original file name",
Type = JsonObjectType.String,
Kind = SwaggerParameterKind.FormData
});
return Task.FromResult(true);
}
//defined as Attribute Usage, so you can use the attribute in your Controller
public class SwaggerFileChunkUploadAttribute : SwaggerOperationProcessorAttribute
{
public SwaggerFileChunkUploadAttribute() : base(typeof(SwaggerFilChunkUploadOperationProcessor))
{
}
}
在你的 Controller 中你现在可以使用
[ValidateMimeMultipartContentFilter]
[SwaggerFileChunkUpload]
public async Task<IHttpActionResult> Upload(long ordernumber)
{
//process your file here!
}
关于c# - NSwag Wep Api 2 multipart/form-data 属性/文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54348470/
我正在尝试从 .yaml 文件生成 .NET Core Web API Controller 。 有一个运行此命令的示例: dotnet "/.../dotnet-nswag.dll" openapi
我正在尝试从 .yaml 文件生成 .NET Core Web API Controller 。 有一个运行此命令的示例: dotnet "/.../dotnet-nswag.dll" openapi
我想对源自程序集的所有 API 调用进行分组,以便一起显示在 Swagger UI 上,但看到分组默认发生在 Controller 上。有什么方法可以强制分组处于装配级别?我正在使用 NSwag 生成
我正在使用 NSwag SwaggerToCSharpClientGenerator 生成请求和响应类以及枚举。 我有一些 Web API 方法共享相同的枚举作为参数或作为请求对象的一部分。当我运行
是否可以像 swashbuckle 那样拥有多个文档端点? options.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1"); options
是否可以生成客户端代码,以便模型的类名具有完整的命名空间作为前缀? 这应该避免相同的类名冲突。 例子 com.foo.MyClass 和 it.foo.MyClass 到现在我得到的是MyClass和
我正在使用 NSwag 生成我的 TypeScript 客户端(Angular 格式),但由于循环依赖关系,我在实现 Bearer token 身份验证时遇到了问题。 我的用户服务需要导入 TS 客户
将 VS 连接服务 (NSwag) 注入(inject)到类/ Controller 中的首选方法是什么。我在网上找到了很多使用这种表格的建议: services.AddHttpClient((pro
我有一个项目,它使用 NSwag 从 swagger 文件生成客户端和契约(Contract)。我不希望 git 跟踪这些生成的文件,因此当项目在构建服务器上构建时,它会将它们作为构建的一部分生成。
我将 NSwag 用于 .NET Core 3.1。一切正常。 我无法确定如何将“我的标题”(即信息标题)更改为其他内容。 这是招摇页面: 这是我的注册码: app.UseOpenApi(); app
我从供应商处获得了 (OpenApi 3.0.1) 中的对象规范: "ExampleTO" : { "codeValidFrom" : { "type" : "string", "
我有一个多态模型: public class CreateOrderRequest { public List OrderItems { get; set; } } /// /// Iden
我在一个 ASP.Net WebAPI 项目中使用 NSwag 来生成一个 swagger 接口(interface)——效果很好。 假设我有一个方法我想添加一些解释 - 我该怎么做? 评论是指 AP
我有这样设置的自定义授权方案: services.AddAuthentication("ClientApp") .AddScheme("ClientApp", null
我有一个类: class Test { public IPAddress Ip {get; set; } } 默认情况下,Nswag(Nswag.AspNetCore 包)位于 http://lo
我使用 NSwag 为单个 Controller 生成客户端;我需要它作为自己独立的客户端。我希望将来生成 Swagger 规范时忽略它。 我试着在 Controller 的顶部添加这个属性,但它仍然
我有一个如下所示的 API 方法: [HttpGet("top/{max}", Name = "GetTopLocations")] public ActionResult> GetTop(int m
在我的项目中无法使用 JsonIgnore,并且 [OpenApiIgnore] 不起作用。在 swashbuckle 中可以通过它自己的属性来制作过滤器,但是在 NSwag 中我没有找到类似的机制。
我们正在使用 swagger/nswag 来记录 webapi 项目。 作为 ActionMethods 的 BodyParameters,我们使用带有后缀 Command 的类,其中包含例如参数。创
当我使用 NSwag 为 API 生成 C# 客户端时,其中 API 包含可用于多种 Http 请求类型(例如 POST、GET)的端点客户端为每个具有相同基本名称的请求生成一个方法,外加一个数字。
我是一名优秀的程序员,十分优秀!