Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring REST API Documentation using Swagger [closed]

I am looking for a tool which could help me generate RESTful API documentation. My server is written in Java and uses Spring MVC framework. I do not have VIEWS in my server. It's a 100% RESTful service and all it does is consumes JSON and spits out JSON.

I was wondering if Swagger is compatible with Spring annotations?

like image 789
jsf Avatar asked Feb 08 '12 05:02

jsf


People also ask

Is Swagger used for API documentation?

Swagger Inspector is integrated with SwaggerHub, the API design and documentation platform for teams. The integration allows developers to automatically host and visualize their API documentation on SwaggerHub to enable API discovery and consumption by internal and external stakeholders.

Is REST API documentation template available on Swagger?

The open source Swagger framework helps remedy these issues for API consumers and developers. The framework provides the OpenAPI Specification (formerly known as the Swagger specification) for creating RESTful API documentation formatted in JSON or YAML, a human-friendly superset of JSON.


2 Answers

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.

like image 128
fehguy Avatar answered Sep 29 '22 20:09

fehguy


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.

like image 22
Marty Pitt Avatar answered Sep 29 '22 21:09

Marty Pitt