What is the benefit of using Spring REST Docs comparing to Swagger
Asked Answered
A

5

48

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.

Abode answered 24/12, 2015 at 20:40 Comment(1)
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.Frolick
C
30

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.

Collative answered 16/1, 2016 at 11:7 Comment(0)
P
13

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.

Placement answered 25/1, 2016 at 16:45 Comment(3)
Welcome to SO and thank you for posting an answer. Do you have citations that could be included as part of your answer?Wartburg
Thanks. I've actually been using SO for years and years but just recently started contributing. Here is the specification guide on swaggers site. swagger.io/specification. Check out the first couple of paragraphs. There are a lot of githb projects out there that can be used to generate your Swagger too. I use Swashbuckle because I am a .Net guy. These are a good example of how a framework actually works to generate the Swagger specification.Placement
The "Specification" part of Swagger was renamed to "OpenAPI" in 2015. From their site: OpenAPI = Specification, Swagger = Tools for implementing the specification. Seem to directly contradict this answer =-DCupboard
F
10

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
Francklin answered 30/10, 2018 at 21:6 Comment(0)
L
6

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

Lody answered 15/1, 2016 at 20:31 Comment(1)
Perhaps the question is too broad, but I think this answer is too short for such a complex question.Mulloy
R
1

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.

Rheta answered 13/6, 2019 at 5:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.