Yardoc RESTful Web Service Plugin

A plugin for Yardoc that generates documentation for RESTful web services.

Previous authors: vWorkApp, rknLA, lsegal, spape, DerNalia

Main features

Plugin provides custom tags to describe resources (controllers) and resulting objects (models).

If you use an object name in description of resource parameters, it will be linked to the object description.

Install

Bundler will reduce your headaches:

    gem 'yard-restful' # in your gemfile

You may need to include the following dependencies as well:

    gem 'redcarpet'
    gem 'yard'

It also requires the Jeweler gem if you plan to use the rake build tasks.

You'll probably want to add these to your .gitignore as well

    .yardoc
    public/api

So you'll have to re-genenarte your API on every machine. This should encourage more up to dateness

Execution

It is recommended that you use a .yardopts file. The sample below assumes you are using Markdown in your YARD, as does the sample documentation.

    --title "My API Documentation"
    --plugin restful
    --markup markdown
    --readme API_README
    --output-dir ./public/api
    app/models/**/*.rb
    app/controllers/**/*.rb

So that way, whenever you want to generate your API docs, you simply need to run only

    bundle exec yardoc

Samples

Full rails 3 application with documentation

Example documentation, also with frames

Sample controller and sample model

Writing Comments

The following tags are provided:

Specifies the resource (controller) or object (model). This tag is compulsory, only classes and methods that include this in their comments are included in the API documentation.

Specifies the URL which someone should use to access that resource.

Specifies the http action (GET, POST, PUT etc.).

Specifies an argument that must be passed to the service. You can specify as many of these as you need.

Specifies an optional argument that may be passed to the service. You can specify as many of these as you need.

Specifies type of the response. Usually just a link to an object.

Further specifies the fields that are returned within the response.

A property (attribute) of an object.

Examples

Examples should always be together in the following order: example_request, example_request_description, example_response, example_response_description (as soon as you write an example_request you need a following example_response and the other way around).

Markdown rendering for the text is activated if a tags text contains a newline (see example).

An example of the request that is send to the service.

The description text for the example request.

An example of the response that is returned from the service.

The description text for the example response.

Example of an object.

Ignored Documentation

This plugin only documents classes and methods with @restful_api tag. It does not support module documentation.

Development

As always, you can see what tasks are available by running:

rake -T

You can run the template locally over the included sample code by using the following rake tasks:

rake example:generate
rake example:clean