Created
September 7, 2017 05:48
-
-
Save rvhuang/ce074afe4cd59b05be3af469f2eeb4fa to your computer and use it in GitHub Desktop.
Enable file upload button on Swagger's page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Swashbuckle.Swagger; | |
using System; | |
using System.Web.Http.Description; | |
namespace UploadingFileFromSwagger.Models | |
{ | |
/* How to use: | |
GlobalConfiguration.Configuration | |
.EnableSwagger(c => | |
{ | |
c.OperationFilter<FileUploadOperation>(); | |
}); | |
*/ | |
public class FileUploadOperation : IOperationFilter | |
{ | |
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) | |
{ | |
if (StringComparer.OrdinalIgnoreCase.Equals(operation.operationId, "Values_Post")) // The format is Action_Method. | |
{ | |
operation.parameters.Clear(); | |
operation.parameters.Add(new Parameter | |
{ | |
name = "uploadedFile1", | |
@in = "formData", | |
description = "Upload File 1", | |
required = true, | |
type = "file" | |
}); | |
operation.parameters.Add(new Parameter | |
{ | |
name = "uploadedFile2", | |
@in = "formData", | |
description = "Upload File 2", | |
required = true, | |
type = "file" | |
}); | |
operation.consumes.Add("multipart/form-data"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment