【发布时间】:2017-01-02 07:38:49
【问题描述】:
我一直试图让 Swashbuckle 5 使用 multipart/form-data 参数为带有 Post 请求的 ApiController 生成完整的帮助页面。该操作的帮助页面出现在浏览器中,但没有包含有关表单中传递的参数的信息。我创建了一个操作过滤器并在 SwaggerConfig 中启用它,包含 URI 参数、返回类型和其他从 XML cmets 派生的信息的网页显示在浏览器帮助页面中;但是,操作过滤器中没有指定任何有关参数的信息,并且帮助页面不包含有关参数的信息。
我一定错过了什么。对我可能错过的内容有什么建议吗?
操作过滤代码:
public class AddFormDataUploadParamTypes : IOperationFilter
{
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) {
if (operation.operationId == "Documents_Upload")
{
operation.consumes.Add("multipart/form-data");
operation.parameters = new[]
{
new Parameter
{
name = "anotherid",
@in = "formData",
description = "Optional identifier associated with the document.",
required = false,
type = "string",
format = "uuid"
},
new Parameter
{
name = "documentid",
@in = "formData",
description = "The document identifier of the slot reserved for the document.",
required = false,
type = "string",
format = "uuid"
},
new Parameter
{
name = "documenttype",
@in = "formData",
description = "Specifies the kind of document being uploaded. This is not a file name extension.",
required = true,
type = "string"
},
new Parameter
{
name = "emailfrom",
@in = "formData",
description = "A optional email origination address used in association with the document if it is emailed to a receiver.",
required = false,
type = "string"
},
new Parameter
{
name = "emailsubject",
@in = "formData",
description = "An optional email subject line used in association with the document if it is emailed to a receiver.",
required = false,
type = "string"
},
new Parameter
{
name = "file",
@in = "formData",
description = "File to upload.",
required = true,
type = "file"
}
};
}
}
}
【问题讨论】:
-
能把控制器的方法的代码加到问题里吗?
-
希望您在 swagger 配置中附加了操作过滤器..
标签: asp.net-web-api2 multipartform-data swashbuckle