|
| 1 | +Documenting the API |
| 2 | +=================== |
| 3 | + |
| 4 | +This document contains general guidelines for describing the Tarantool API, |
| 5 | +as well as examples and templates. |
| 6 | + |
| 7 | +Style |
| 8 | +----- |
| 9 | + |
| 10 | +Please write as simply as possible. Describe functionality using short sentences in the present simple tense. |
| 11 | +A short sentence consists of no more than two clauses. |
| 12 | +Consider using `LanguageTool <https://languagetool.org/>`_ or `Grammarly <https://www.grammarly.com/>`_ |
| 13 | +to check your English. |
| 14 | +For more style-related specifics, consult the :doc:`Language and style </contributing/docs/style>` section. |
| 15 | + |
| 16 | +.. _contributing-docs-api_version: |
| 17 | + |
| 18 | +Indicating the version |
| 19 | +---------------------- |
| 20 | + |
| 21 | +For every new module, function, or method, specify the version it first appears in. |
| 22 | + |
| 23 | +For a new parameter, specify the version it first appears in if this parameter is a "feature" |
| 24 | +and the version it's been introduced in differs from |
| 25 | +the version introducing the function/method and all other parameters. |
| 26 | + |
| 27 | +To specify the version, use the following Sphinx directive: |
| 28 | + |
| 29 | +.. code-block:: rst |
| 30 | +
|
| 31 | + Since :doc:`2.10.0 </release/2.10.0>`. |
| 32 | + This is a link to the release notes on the Tarantool documentation website. |
| 33 | +
|
| 34 | +The result looks like this: |
| 35 | + |
| 36 | + Since Tarantool :doc:`2.10.0 </release/2.10.0>`. |
| 37 | + This is a link to the release notes on the Tarantool documentation website. |
| 38 | + |
| 39 | +.. _contributing-api-docs_general-description: |
| 40 | + |
| 41 | +Language of the general description |
| 42 | +----------------------------------- |
| 43 | + |
| 44 | +Use one of the two options: |
| 45 | + |
| 46 | +* Start with a verb in the imperative mood. Example: *Create a fiber.* |
| 47 | +* Start with a noun. Example: *The directory where memtx stores snapshot files.* |
| 48 | + |
| 49 | +Checklist |
| 50 | +--------- |
| 51 | + |
| 52 | +Each list item is a characteristic to be described. Some items can be optional. |
| 53 | + |
| 54 | +Function or method |
| 55 | +^^^^^^^^^^^^^^^^^^ |
| 56 | + |
| 57 | +* :ref:`Since which Tarantool version <contributing-docs-api_version>` |
| 58 | +* :ref:`General description <contributing-api-docs_general-description>` |
| 59 | +* :ref:`Parameters <documenting_parameters>` |
| 60 | +* What this function returns (if nothing, write 'none') |
| 61 | +* Return type (if exists) |
| 62 | +* :ref:`Possible errors <contributing-docs-possible_errors>` (if exist) |
| 63 | +* :ref:`Complexity factors <index-box_complexity-factors>` |
| 64 | + (for :doc:`CRUD operations </reference/reference_lua/box_space>` and |
| 65 | + :doc:`index access functions </reference/reference_lua/box_index/>`) |
| 66 | +* Usage with memtx and vinyl (if differs) |
| 67 | +* Example(s) |
| 68 | +* Extra information (if needed) |
| 69 | + |
| 70 | +See :ref:`module function example <contributing-api-docs_function-example>`, |
| 71 | +:ref:`class method example <contributing-api-docs_class-example>`. |
| 72 | + |
| 73 | +Data |
| 74 | +^^^^ |
| 75 | + |
| 76 | +* :ref:`Since which Tarantool version <contributing-docs-api_version>` |
| 77 | +* :ref:`General description <contributing-api-docs_general-description>` |
| 78 | +* Return type |
| 79 | +* Example |
| 80 | + |
| 81 | +See :ref:`class data example <contributing-api-docs_class-example>`. |
| 82 | + |
| 83 | +.. _documenting_parameters: |
| 84 | + |
| 85 | +Function and method parameters |
| 86 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 87 | + |
| 88 | +* :ref:`Since which Tarantool version <contributing-docs-api_version>` |
| 89 | + (if added later) |
| 90 | +* :ref:`General description <contributing-api-docs_general-description>` |
| 91 | +* Type |
| 92 | +* Default value (if optional), possible values |
| 93 | + |
| 94 | +If the parameter is optional, make sure it is enclosed in square brackets |
| 95 | +in the function declaration (in the "heading"). |
| 96 | +Do not mark parameters additionaly as "optional" or "required": |
| 97 | + |
| 98 | +.. code-block:: rst |
| 99 | +
|
| 100 | + .. function:: format(URI-components-table[, include-password]) |
| 101 | +
|
| 102 | + Construct a URI from components. |
| 103 | +
|
| 104 | + :param URI-components-table: a series of ``name:value`` pairs, one for each component |
| 105 | + :param include-password: boolean. If this is supplied and is ``true``, then |
| 106 | + the password component is rendered in clear text, |
| 107 | + otherwise it is omitted. |
| 108 | +
|
| 109 | +.. _documenting_confvals: |
| 110 | + |
| 111 | +Configuration parameters |
| 112 | +^^^^^^^^^^^^^^^^^^^^^^^^ |
| 113 | + |
| 114 | +Configuration parameters are not to be confused with class and method parameters. |
| 115 | +Configuration parameters are passed to Tarantool via the command line or in an initialization file. |
| 116 | +You can find a list of Tarantool configuration parameters in the :doc:`configuration reference </reference/configuration/index>`. |
| 117 | + |
| 118 | +* :ref:`Since which Tarantool version <contributing-docs-api_version>` |
| 119 | +* :ref:`General description <contributing-api-docs_general-description>` |
| 120 | +* Type |
| 121 | +* Corresponding environment variable (if applicable) |
| 122 | +* Default value |
| 123 | +* Possible values (can be included in the general description, for example, as a list) |
| 124 | +* Dynamic (yes or no) |
| 125 | + |
| 126 | +See :ref:`configuration parameter example <contributing-api-docs_confval-example>`. |
| 127 | + |
| 128 | +.. _contributing-docs-possible_errors: |
| 129 | + |
| 130 | +Documenting possible errors |
| 131 | +--------------------------- |
| 132 | + |
| 133 | +In the "Possible errors" section of a function or class method, |
| 134 | +consider explaining what happens if any parameter hasn't been defined or has the wrong value. |
| 135 | + |
| 136 | +Examples and templates |
| 137 | +---------------------- |
| 138 | + |
| 139 | +.. _contributing-api-docs_function-example: |
| 140 | + |
| 141 | +Module functions |
| 142 | +^^^^^^^^^^^^^^^^ |
| 143 | + |
| 144 | +We use the Sphinx directives ``.. module::`` |
| 145 | +and ``.. function::`` to describe functions of Tarantool modules: |
| 146 | + |
| 147 | +.. literalinclude:: ./_includes/function_template.rst |
| 148 | + :language: rst |
| 149 | + |
| 150 | +The resulting output looks like this: |
| 151 | + |
| 152 | +.. include:: ./_includes/function_template.rst |
| 153 | + |
| 154 | + |
| 155 | +.. _contributing-api-docs_class-example: |
| 156 | + |
| 157 | +Class methods and data |
| 158 | +^^^^^^^^^^^^^^^^^^^^^^ |
| 159 | + |
| 160 | +Methods are described similarly to functions, but the ``.. class::`` |
| 161 | +directive, unlike ``.. module::``, requires nesting. |
| 162 | + |
| 163 | +As for data, it's enough to write the description, the return type, and an example. |
| 164 | + |
| 165 | +Here is the example documentation describing |
| 166 | +the method and data of the ``index_object`` class: |
| 167 | + |
| 168 | +.. literalinclude:: ./_includes/class_template.rst |
| 169 | + :language: rst |
| 170 | + |
| 171 | +And the resulting output looks like this: |
| 172 | + |
| 173 | +.. include:: ./_includes/class_template.rst |
| 174 | + |
| 175 | +.. _contributing-api-docs_confval-example: |
| 176 | + |
| 177 | +Configuration parameters |
| 178 | +^^^^^^^^^^^^^^^^^^^^^^^^ |
| 179 | + |
| 180 | +Example: |
| 181 | + |
| 182 | +.. literalinclude:: ./_includes/confval_template.rst |
| 183 | + :language: rst |
| 184 | + |
| 185 | +Result: |
| 186 | + |
| 187 | +.. include:: ./_includes/confval_template.rst |
0 commit comments