42
votes

Spring REST Docs was released recently and the documentation says:

This approach frees you from the limitations imposed by tools like Swagger

So, I wanted to ask when Spring REST Docs is preferable to use comparing to Swagger and which limitations it frees.

5
This is largely opinion based so I don't think it belongs on Stack Overflow. That said, you might find this Q&A on DZone to be of interest.Andy Wilkinson

5 Answers

29
votes

I just saw a presentation here that touches on your question among other topics:

https://www.youtube.com/watch?v=k5ncCJBarRI&t=26m58s

  • Swagger doesn't support hypermedia at all / it's URI centric

  • Swagger's method of inspecting your code can lag behind your code. It's possible make a change in your code that Swagger fails to understand and won't process properly until Swagger gets updated.

  • Swagger requires lot of annotation, and it's painful to include the descriptive text you want in an api document in annotations.

  • There are just some things that Swagger can't figure out from inspecting your code.

In any case, these are just a couple of points. The presenter does a much better job discussing it than I could.

13
votes

I thought I would chime in to give a little bit more context surrounding Swagger, what it is, and what it is not. I believe this might help answer your question.

Swagger 2.0 is being adopted by a lot of big names and big platforms like Microsoft Azure, Paypal, SwaggerHub.com, DynamicApis.com, etc... Something to keep in mind is that Swagger is very simply a specification. It is not a framework. There are a lot of frameworks out there built to generate Swagger output that crawl through your code looking at your API information in order to build the Swagger 2.0 JSON file that represents your API. The Swagger UI that you see your APIs on is driven directly from this Swagger 2.0 JSON file. fiddler it to check it out

It is important to note that a framework that was created to allow you to "use swagger" is not how Swagger has to work (i.e. it is completely up to the implementation of the 3rd party framework). If the framework you are using to generate your Swagger 2.0 documents and UI is not working for you then you should be able to go find another framework that generates the Swagger artifacts and swap the technologies out.

Hope this helps.

8
votes

From Spring REST docs:

The aim of Spring REST Docs is to help you to produce documentation for your RESTful services that is accurate and readable

This test-driven approach helps to guarantee the accuracy of your service’s documentation. If a snippet is incorrect the test that produces it will fail.

Spring REST docs advantages:

  • Documentation is written in the test code so it does not overload main code with lots of annotations and descriptions
  • Generated docs and examples are accurate because related test must pass
  • Docs can provide more specific and descriptive snippets
  • Format is suitable for publishing

Spring REST docs disadvantages:

  • Requires more work
  • Documentation provides request/response examples but don't provide interactive tools to modify and try out requests

Swagger advantages:

  • Quick, automated generation from a code
  • Interactive request execution - can be used for acceptance testing
  • Built around the OpenAPI Specification

Swagger disadvantages:

  • For more descriptive documentation it will require a lot of annotations
  • Tests are not related to the documentation so sometimes documention may deviate from reality
6
votes

There is some limitation with swagger and the specific spring stack.

For example : with "param" in your Request Mapping you can define more than one method with the same url ans so simplify your code. But swagger show you just one method

0
votes

One disadvantage with Swagger is: it cannot handle models which have cyclical dependencies. If a model has cyclical dependency and if swagger is enabled, then spring boot server crashes.