Thursday, March 22, 2018

Swashbuckle : Allow file import through the Swagger UI

One of the API’s I’m building allows you to import files to a database.

To simplify testing I wanted to allow the consumers of my API to test the API directly through the Swagger UI. Problem is that out of the box Swashbuckle(the Swagger implementation for .NET) has no clue how to interprete the IFormFile.

Let’s fix that by introducing an IOperationFilter:

And let’s not forget to register that IOperationFilter in our Startup.cs file:

Now if we run our application and browse to the swagger endpoint(/swagger), when we try to execute our Upload operation, we get a nice Import button:

image

No comments: