RestDoc is a utility for generating REST API documentation from RESTful resource scripts in Zero applications. Given a set of Zero-style scripts, it will generate an HTML page with a REST table ("Gregorio table") for each resource type; the tables include such information as the HTTP methods, URIs, data formats, applicable status codes, and descriptions of each type of operation.
To use RESTdoc, you must first include RESTdoc-style comments in your Zero scripts. RESTdoc comments are just like JavaDoc comments, with the following new tags: @success, @error, and @format. The new tags are used to list the HTTP status codes for success and errors, as well as the expected data format in the request or response body for each method. RESTdoc will ignore any method that is not a Zero REST method (onList(), etc.) or that does not have RESTdoc-style documentation preceding its definition. Like Zero itself, RESTdoc only supports Groovy and PHP scripts, but it is possible to add other languages in the future.
To run RESTdoc from your Zero application's directory, just type:
- Code: Select all
$ restdoc
By default, RESTdoc will look in ./app/resources for Zero REST scripts and it will save the generated HTML page in ./docs/rest. If you want to run RESTdoc from a script that is not in your application's directory, you can use the input and output flags to override the defaults:
- Code: Select all
$ restdoc -input /my-app/app/resources -output /my-docs
Finally, RESTdoc does not produce any output if all goes well. You can turn on console logging using the verbose flag if you're having trouble debugging a problem:
- Code: Select all
$ restdoc -verbose
As an example, comments like this:
- Code: Select all
/**
*
* Returns all contact lists from a user's profile. The response content is a
* JSON object with one field for each list; the keys are the list names, the
* values are lists of user IDs.
*
* @format JSON
* @success 200
* @error 403, 404
*
*/
create tables like the one in the attached screenshot.
The code currently works with Groovy or PHP resources and produces HTML that can standalone or be copied into a wiki page. Any feedback would be appreciated - the code and sample applications can be found in SVN under /branches/p_dj_restdoc. The tool can be run by executing RestDoc's main() or by using the RESTdoc Ant task; the latter is demonstrated in the build.xml files of each sample application - just run 'ant docs'. I will try to incorporate any feedback before submitting an enhancement request and patch for zero.tools.
TODOs: incorporate .bnd files when generating a resource's URI patterns.

Posts