Spring REST API Documentation using Swagger [closed] Spring REST API Documentation using Swagger [closed] spring spring

Spring REST API Documentation using Swagger [closed]


There currently is not a Spring MVC swagger module available (from Wordnik at least) but in general, enabling swagger on a JVM-based REST service is pretty simple.

Swagger server support is divided into two parts--the core server and the integration with the REST service. See the Swagger github repo. Swagger core defines the document that represents the REST service, parameters, allowable values, HTTP operations, etc. The server integration wires this document to the structure of the REST framework. Wordnik uses Jersey via JAX-RS and released swagger-jaxrs to do this integration. There is also a Swagger-Play module which will be released to the Play module repository shortly.

If you want to enable swagger on another REST framework (like Spring MVC), you follow these steps:

1) Generate an API Reader to generate a com.wordnik.swagger.core.Documentation object. See the JAX-RS version as well as the one for play.

2) Create a REST endpoint which returns a JSON/XML version of the Documentation object to the client. Again, JAX-RS and play.

3) Add a filter to intercept requests to enforce resource or object-level access.

So in short, it could be put together pretty easily.


There is a Swagger-SpringMVC implementation in progress here and examples here.

The spec v1.2 is fully implemented and supported (ie., models are generated, with full support for generics), and it's under active development.


Another implementation of Swagger for Spring MVC is swagger4spring-web.

It's similar to Swagger-SpringMVC and supports all Swagger annotations and generates JSON schema for return types and parameters. It also works without swagger annotations.