标签:action etc schema logs att rip 类型 images opened
[AttributeUsage(AttributeTargets.Parameter)] public class SwaggerFileUploadAttribute : Attribute { public bool Required { get; private set; } public SwaggerFileUploadAttribute(bool Required = true) { this.Required = Required; } }
/// <summary> /// swagger file upload parameter filter /// </summary> public class SwaggerFileUploadFilter : IOperationFilter { public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { var parameters = apiDescription.ActionDescriptor.GetParameters(); foreach (HttpParameterDescriptor parameterDesc in parameters) { var fileUploadAttr = parameterDesc.GetCustomAttributes<SwaggerFileUploadAttribute>().FirstOrDefault(); if (fileUploadAttr != null) { operation.consumes.Add("multipart/form-data"); operation.parameters.Add(new Parameter { name = parameterDesc.ParameterName + "_file", @in = "formData", description = "file to upload", required = fileUploadAttr.Required, type = "file" }); } } } }
标签:action etc schema logs att rip 类型 images opened
原文地址:http://www.cnblogs.com/sessionliang/p/6688065.html