easily generate docs and playground for your RESTful API
If your web application already uses Spring MVC, then it's easy: the project jsondoc-springmvc
already does it for you, so you need to include both jsondoc-core
and jsondoc-springmvc
dependencies.
<dependency>
<groupId>org.jsondoc</groupId>
<artifactId>jsondoc-springmvc</artifactId>
<version>1.2.23</version>
</dependency>
The only thing to do on your side is to declare the jsondoc controller in your spring context.xml file:
<bean id="documentationController" class="org.jsondoc.springmvc.controller.JSONDocController">
<constructor-arg name="version" value="1.0" />
<constructor-arg name="basePath" value="http://localhost:8080/api" />
<constructor-arg name="packages">
<list>
<value>org.jsondoc.sample.controller</value> <!-- packages in which you have your spring controllers -->
<value>org.jsondoc.sample.pojo</value> <!-- packages in which you have your objects -->
<value>com.sample.external.pojo</value> <!-- they can also belong to external jars -->
</list>
</constructor-arg>
<property name="playgroundEnabled" value="true" /> <!-- optional -->
<property name="displayMethodAs" value="URI" /> <!-- optional -->
</bean>
In this case the documentation will be generated at http://localhost:8080/api/jsondoc
. You only have to specify the api version and the base path to give you readers a better information.
See Configuration for more information about how to configure the JSONDoc controller.
You can include the jsondoc-ui
project in your web application. This provides an interface to browse the generated documentation and a playground to test methods. It is built on Twitter Bootstrap and can be easily customized for you needs. To do this you need to get the jsondoc-ui
jar, extract it and copy css, js, font, jsondoc-ui.html
to your project's webapp folder. Check out the live demo here or the sample applications code. Here is the dependency to the jsondoc-ui
:
<dependency>
<groupId>org.jsondoc</groupId>
<artifactId>jsondoc-ui</artifactId>
<version>1.2.23</version>
</dependency>
If you are not satisfied with the standard interface, you can use the generated JSON documentation in a fully customized interface!