wsme/doc/document.rst
2012-04-17 15:17:12 +02:00

4.2 KiB

Document your API

Web services without a proper documentation are usually useless.

To make it easy to document your own API, WSME provides a Sphinx extension.

Install the extension

Here we consider that you already quick-started a sphinx project.

  1. In your conf.py file, add 'wsme.sphinxext' to you extensions, and optionally set the enabled protocols.

    extensions = ['wsme.sphinxext']
    
    wsme_protocols = ['restjson', 'restxml', 'extdirect']
  2. Copy toggle.js <_static/toggle.js> and toggle.css <_static/toggle.css> in your _static directory.

The wsme domain

The extension will add a new Sphinx domain providing a few directives.

Config values

wsme_protocols

A list of strings that are WSME protocol names. If provided by an additionnal package (for example WSME-Soap or WSME-ExtDirect), it must be installed.

The types and services generated documentation will include code samples for each of these protocols.

wsme_root

A string that is the full name of the service root controller. It will be used to determinate the relative path of the other controllers when they are autodocumented, and calculate the complete webpath of the other controllers.

wsme_webpath

A string that is the webpath where the wsme_root is mounted.

Directives

Allow to define the service root controller in one documentation source file. To set it globally, see wsme_root.

A webpath option allow to override wsme_webpath.

Example:

.. wsme:root:: myapp.controllers.MyWSRoot
    :webpath: /api

Declare a service.

Equivalent to the :rstpy:class directive to document a complex type

Equivalent to the :rstpy:attribute directive to document a complex type attribute. It takes an additionnal :type: field.

Example

Source Result
.. wsme:root:: wsme.sphinxext.SampleService
    :webpath: /api

.. wsme:type:: MyType

    .. wsme:attribute:: test

        :type: int

.. wsme:service:: name/space/SampleService

    .. wsme:function:: doit
type

int

Returns a :wsmeMyType <MyType>

Autodoc directives

Theses directives scan your code to generate the documentation from the docstrings and your API types and controllers.

Generate the myapp.MyType documentation.

Generate the myapp.MyType.aname documentation.

Generate the myapp.MyService documentation.

Generate the myapp.MyService.myfunction documentation.

Full Example

Python source

../wsme/sphinxext.py

Documentation source

.. default-domain:: wsme

.. autotype:: wsme.sphinxext.SampleType
    :members:

.. autoservice:: wsme.sphinxext.SampleService
    :members:

Result

wsme

int

An integer

wsme.sphinxext.SampleType

wsme.sphinxext.SampleService