FluentSwaggerTests — never break your Swagger configuration again

Magnus Stuhr
Compendium
Published in
7 min readFeb 25, 2020

--

Swagger is a great way of dynamically documenting web APIs. However, I have seen a great share of broken Swagger set ups, such as the entire documentation failing to generate due to an invalid attribute annotation, or a public controller method which has not been bootstrapped to an HTTP method.

On top of this, it is easy to forget to update the static Swagger configuration, such as the version, title, description and XML documentation file. However, to ensure that we do not misconfigure the Swagger configuration in either way, we have to automatically test the entire Swagger set up by verifying that our Swagger endpoint is running successfully with the expected configuration.

This blog post will introduce “FluentSwaggerTests” — a way of dynamically verifying a Swagger setup with automated integration tests.

The fragility of Swagger configurations

First, let us take a look at the reasons why it is so important to automatically test any Swagger endpoint.

Swagger is great in the sense that it generates documentation based on the code we write, so that the API documentation always reflect the functionality in our code. However, this auto-generated documentation is a highly fragile operation that easily fails if…

--

--