question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding a FileOperationFilter with the latest Swashbuckle

See original GitHub issue

Hi,

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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
arrkayecommented, Jan 15, 2020

Ah, I see what I’ve done. My bad, and apologies. I’ll move my issue across to the right repo.

1reaction
inbarbarkaicommented, Jan 15, 2020

I have the same issue on 5.0.0-rc5. @jinek Your solution doesn’t apply.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found