File: usage.rst

package info (click to toggle)
python-os-api-ref 0.3.0%2Bdfsg1-3~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 340 kB
  • sloc: python: 611; makefile: 8
file content (233 lines) | stat: -rw-r--r-- 7,674 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
Usage
=====

``os-api-ref`` is designed to be used inside of a sphinx tree that is
devoted solely to the documentation of the API.

Modify your ``source/conf.py`` file to include ``os_api_ref`` in the
list of sphinx extensions. This extension assumes you are also using
``oslosphinx`` for some of the styling, and may not fully work if you
are not.

.. code-block:: python

   # Add any Sphinx extension module names here, as strings. They can be
   # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.

   extensions = [
       'os_api_ref',
       'oslosphinx',
   ]


Stanzas
=======

rest_method
-----------

The ``rest_method`` stanza is a way to declare that a section is about
a particular REST method. It takes the form of:

.. code-block:: rst

   .. rest_method:: <METHODNAME> <url>

``METHODNAME`` should be one of the commonly used REST methods or HTTP verbs.
This stanza should be the first element in a ``section`` that has some
descriptive title about the method. An example from the Nova
documentation is:

.. code-block:: rst

   List Servers
   ============

   .. rest_method:: GET /v2.1/{tenant_id}/servers

   Lists IDs, names, and links for all servers.


   Servers contain a status attribute that indicates the current server
   state. You can filter on the server status when you complete a list
   servers request. The server status is returned in the response
   body. The possible server status values are:

   ...

This is going to do a slightly unexpected transform where the
``rest_method`` is pivoted up and into the section title to produce an
HTML line of the form: <METHOD> <URL> <SECTIONTITLE> <SHOW/HIDE
BUTTON>.

The entire contents of the ``List Servers`` section will then be
hidden by default, with a button to open it on demand.

rest_parameters
---------------

The ``rest_parameters`` stanza is a solution to the problem of tables
in ``rst``.

A REST API that uses JSON has a large number of structured parameters
that include type, location (i.e. is this in the query, the header,
the path, the body), whether or not this parameter is required, as well as
the desire to provide a long description about each parameter. And, assuming
some consistent modeling, that parameter will show up in multiple calls. A
``server_id`` used in the path is always going to have the same
meaning.

It is natural to want to display this data in a tabular way to show
all these dimensions. However, tables in ``rst`` are quite cumbersome, and
repeating the same data over and over again is error prone.

The ``rest_parameters`` stanza solves this by having the inline markup
be a yaml list of ``name: value`` pairs. ``name`` is the name of the
parameter. ``value`` is the key to lookup the rest of the details for
this parameter in a parameters file.  In each method,
there should be one ``rest_parameters`` stanza for the request, and
another ``rest_parameters`` stanza for the response.

.. code-block:: rst

   .. rest_parameters:: parameters.yaml

      - tenant_id: tenant_id
      - changes-since: changes-since
      - image: image_query
      - flavor: flavor_query
      - name: server_name_query
      - status: server_status_query
      - host: host_query
      - limit: limit
      - marker: marker

And corresponding entries in ``parameters.yaml``:

.. code-block:: yaml

   tenant_id:
     description: |
       The UUID of the tenant in a multi-tenancy cloud.
     in: path
     required: true
     type: string
   ...
   changes-since:
     description: |
       Filters the response by a date and time when the image last changed status.
       Use this query parameter to check for changes since a previous request rather
       than re-downloading and re-parsing the full status at each polling interval.
       If data has changed, the call returns only the items changed since the ``changes-since``
       time. If data has not changed since the ``changes-since`` time, the call returns an
       empty list.\nTo enable you to keep track of changes, this filter also displays images
       that were deleted if the ``changes-since`` value specifies a date in the last 30 days.
       Items deleted more than 30 days ago might be returned, but it is not guaranteed.
       The date and time stamp format is `ISO 8601 <https://en.wikipedia.org/wiki/ISO_8601>`_:

       ::

          CCYY-MM-DDThh:mm:ss±hh:mm

       The ``±hh:mm`` value, if included, returns the time zone as an offset from UTC.
       For example, ``2015-08-27T09:49:58-05:00``.
       If you omit the time zone, the UTC time zone is assumed.
     in: query
     required: false
     type: string
   server_status_query:
     description: |
       Filters the response by a server status, as a string. For example, ``ACTIVE``.
     in: query
     required: false
     type: string

Every ``rest_parameters`` stanza specifies the lookup file it will
use. This gives you the freedom to decide how you would like to split
up your parameters, ranging from a single global file, to a dedicated
file for every stanza, or anywhere in between.

parameters file format
----------------------

The parameters file is inspired by the OpenAPI (aka: Swagger)
specification.  The OpenAPI specification provides a property object
which categorizes the parameters by type and describes how the parameter is used.
The following fields exist for every entry:

in
  where this parameter exists. One of ``header``, ``path``,
  ``query``, ``body``.

description
  a free form description of the parameter. This can be
  multiline (if using the | or > tags in yaml), and supports ``rst``
  format syntax.

required
  whether this parameter is required or not. If ``required:
  false`` the parameter name will be rendered with an (Optional)
  keyword next to it

type
  the javascript/json type of the field. one of ``boolean``, ``int``,
  ``float``, ``string``, ``array``, ``object``.

min_version
  the microversion that this parameter was introduced at. Will render
  a *new in $version* stanza in the html output.

max_version
  the last version that includes this parameter. Will render
  a *Deprecated in $version* stanza in the html output.


rest_expand_all
---------------

The ``rest_expand_all`` stanza is used to place a control in the
document that will be a global Show / Hide for all sections. There are
times when this is extremely nice to have.


Including Sample Files
======================

To refer to a sample file in a ``rst`` file, use the
``rst`` directive, ``literalinclude``. Typically, the content sent
or received is of type JSON, so the language role is set to javascript.
The example immediately follows the parameter listing in the ``rst`` file.
An example of an included Nova response sample file:

.. code-block:: rst

   .. literalinclude:: ../../doc/api_samples/os-evacuate/server-evacuate-resp.json
      :language: javascript


Runtime Warnings
================

The extension tries to help when it can by pointing out that something isn't
matching up correctly. The following warnings are generated when
issues are found:

* parameters file is not found
* parameters file is not valid yaml, i.e.
  missing colon after the name
* a lookup value in the ``rst`` file is not found in the parameters file
* the parameters file is not sorted as outlined in the rules below

The sorting rules for parameters file is that first elements should be
sorted by ``in``, going from earliest to latest processed.

#. header
#. path
#. query
#. body

After that, the parameters should be sorted by name, lower case alpha
numerically.

The sort enforcement is because in large parameters files it helps
prevent unintended duplicates.