Adding a FileOperationFilter with the latest Swashbuckle
See original GitHub issueHi,
We have a FileOperationFilter we were using on 1.2.0 that I’m having trouble upgrading to the latest version of Swashbuckle.
What do I need to change to be compatible?
public class FileOperationFilter : IOperationFilter
{
private HashSet<string> _remove = new HashSet<string>(){ "contentType", "contentDisposition", "headers", "length", "name", "fileName" };
public void Apply(Operation operation, OperationFilterContext context)
{
if (context.ApiDescription.ParameterDescriptions.Any(x => x.ModelMetadata.ContainerType == typeof(IFormFile)))
{
var temp = new List<IParameter>();
foreach (var operationParameter in operation.Parameters)
{
if (_remove.Contains(operationParameter.Name))
{
temp.Add(operationParameter);
}
}
temp.ForEach(t => operation.Parameters.Remove(t));
operation.Parameters.Add(new NonBodyParameter
{
Name = "file", // must match parameter name from controller method
In = "formData",
Description = "Upload file.",
Required = true,
Type = "file"
});
operation.Consumes.Add("application/form-data");
}
}
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7
Top Results From Across the Web
Get started with Swashbuckle and ASP.NET Core
AspNetCore" in the search box; Select the latest "Swashbuckle.AspNetCore" package from the Browse tab and click Install.
Read more >Adding a File Upload Field to Your Swagger UI ... - Alex Dunn
Let's first look at a simple swagger setup as our baseline before we add everything for our HTTP Header Field. ... config.SwaggerDoc( "v1"...
Read more >Exception when adding swagger with .NET Core 3.0
I am trying to integrate swagger into a ASP NET Core 3.0 project and it throws exception right in the ConfigureServices method: I...
Read more >Swashbuckle.AspNetCore.Filters 7.0.8
This package replaces Swashbuckle.AspNetCore.Examples.
Read more >Swagger in ASP.Net Core (Using Swashbuckle.AspNetCore ...
Which will use the Swagger NuGet package ( Swashbuckle.AspNetCore). ... How to add OpenAPI and Swagger to ASP.NET Core Minimal APIs.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah, I see what I’ve done. My bad, and apologies. I’ll move my issue across to the right repo.
I have the same issue on 5.0.0-rc5. @jinek Your solution doesn’t apply.