Wednesday, January 5, 2022

Swashbuckle - Free form query parameters

I’m creating an api where an arbitrary number of query parameters can be added.

The API looks something like this:

GET /api/example?param1=value1&param2=value2&param3=value3

By default when Swashbuckle generates the Swagger UI it only includes parameters that are explicitly defined at the action method level.

Luckily the Open API spec supports this starting from version 3 through ‘free form query parameters’.

At the spec level this looks like this:

To achieve this using Swashbuckle you can use an operation filter:

This will generate the following UI: