Runtime documentation of REST APIs

Runtime documentation of REST APIs based on the Spring and JAXB annotations.

License

License

GroupId

GroupId

com.apporiented
ArtifactId

ArtifactId

spring-rest-doc
Last Version

Last Version

1.6.1
Release Date

Release Date

Type

Type

jar
Description

Description

Runtime documentation of REST APIs
Runtime documentation of REST APIs based on the Spring and JAXB annotations.
Project URL

Project URL

https://github.com/lbehnke/spring-rest-doc
Project Organization

Project Organization

Lars Behnke
Source Code Management

Source Code Management

https://github.com/lbehnke/spring-rest-doc

Download spring-rest-doc

How to add to project

<!-- https://jarcasting.com/artifacts/com.apporiented/spring-rest-doc/ -->
<dependency>
    <groupId>com.apporiented</groupId>
    <artifactId>spring-rest-doc</artifactId>
    <version>1.6.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.apporiented/spring-rest-doc/
implementation 'com.apporiented:spring-rest-doc:1.6.1'
// https://jarcasting.com/artifacts/com.apporiented/spring-rest-doc/
implementation ("com.apporiented:spring-rest-doc:1.6.1")
'com.apporiented:spring-rest-doc:jar:1.6.1'
<dependency org="com.apporiented" name="spring-rest-doc" rev="1.6.1">
  <artifact name="spring-rest-doc" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.apporiented', module='spring-rest-doc', version='1.6.1')
)
libraryDependencies += "com.apporiented" % "spring-rest-doc" % "1.6.1"
[com.apporiented/spring-rest-doc "1.6.1"]

Dependencies

compile (8)

Group / Artifact Type Version
com.google.guava : guava jar 18.0
org.reflections : reflections jar 0.9.8
org.javassist : javassist jar 3.18.1-GA
org.springframework : spring-core jar 4.1.4.RELEASE
org.springframework : spring-web jar 4.1.4.RELEASE
ch.qos.logback : logback-classic jar 1.1.2
org.slf4j : log4j-over-slf4j jar 1.7.6
org.slf4j : jcl-over-slf4j jar 1.7.6

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-all jar 1.10.19
org.springframework : spring-test jar 4.1.4.RELEASE

Project Modules

There are no modules declared in this project.

Spring REST Doc

This is a simple runtime REST API documentation generator based on JSONDoc 1.0.1. It reads Spring MVC, JAXB annotations, and a set of own annotations.

Example data transfer object returned by the REST controller:

@ApiModelDoc("Data transfer object that represents an user account.")
@XmlType(namespace = Namespaces.NS_DTO)
@XmlRootElement(name="siteUser")
public class AppUserDTO {

    @XmlAttribute(required = true)
    private String loginName;
    
    private String name;
    
    @XmlElement(required = true)
    private String email;

    [...]
    
}

Example REST Controller:

@ApiDoc(name="User resource", description="REST resource for administrating user accounts. Only acessible for users with administrator privilege.")
@RestController
@RequestMapping(value="/users")
public class UserResource {

    @ApiMethodDoc("Returns a list of user accounts. Operation is available for administrators only.")
    @ApiErrorsDoc({
            @ApiErrorDoc(
                    code = 401,
                    description="Insufficient user privileges to access this operation."),
    })
	@RequestMapping(method=RequestMethod.GET)
	public AppUserListDTO findUsers(
            @RequestParam(value = "filter", required = false) @ApiParamDoc("Optional parameter that limits the result list to users with names containing the filter term as substring.") String filter,
            @RequestParam(value = "pageno", required = false) @ApiParamDoc("Page to be returned") Integer pageNo,
            @RequestParam(value = "pagesize", required = false) @ApiParamDoc("Page size") Integer pageSize,
            HttpServletRequest request) throws Exception
    {
        return userService.findAppUsers(filter, new PagingInfoDTO(pageNo, pageSize));
	}
	
	[...]
	
}

Here is how the documentation is returned as XML or JSON object:

private static  String[] PKG_NAMES = new String[]{
        "example.web.rest",
        "example.common.dto",
};

private DocumentationFactory documentationFactory = new DefaultDocumentationFactory();

@ApiMethodDoc("Returns the API documentation as JSON or XML document.")
@RequestMapping(value="/doc",method=RequestMethod.GET)
public Documentation getDocumentation() {
    return documentationFactory.createDocumentation("1.0", "http://www.mydomain.org/api", PKG_NAMES);
}

Versions

Version
1.6.1
1.6
1.5
1.4
1.3
1.2
1.1