Search code examples
restspring-mvcswaggerspringfoxenunciate

Generating Swagger JSON for Spring MVC: Springfox or Enunciate


If you want to generate Swagger UI documantation for your Spring MVC project, basically you have two options: Enunciate and SpringFox.

I dived into the subject but did not find a single opinion which one is better.

From my perspective Enunciate looks preferable since it is completely external to your project. No need to add a special Bean with configuration, no need to reference additional package with annotations and annotate your controllers with them. You simple use JavaDoc with custom tags and it does the job.

Are there any other considerations to take into account?

Thanks.


Solution

  • After using both, I find the following key differences:

    • Enunciate evaluates annotations at build time, Springfox reads the Spring MVC configuration from the application context (build time vs. runtime)
    • Enunciate can use Javadocs as part of the documentation (build vs. runtime)
    • Springfox requires a test to generate a swagger configuration file that can be used for further code generation which does not fit nicely into a standard maven lifecycle. I prefer to use generate-sources / generate-resources for code / doc generation. With springfox I'm stuck with generating after running tests.
    • Springfox with springfox-swagger-ui is a really simple way to bolt a swagger UI on top of your existing Spring Boot / MVC application. OTOH, using something like ReDoc along with the generated Swagger Spec is nearly as simple but more flexible.
    • Springfox requires quite some configuration within your application, so your app will have a runtime dependency on Springfox.