Guidelines for API documentation » History » Version 11
neels, 06/22/2017 11:55 PM
1 | 1 | neels | h1. Guidelines for API documentation |
---|---|---|---|
2 | |||
3 | We use doxygen for API documentation, following these guidelines: |
||
4 | |||
5 | Use the @/*!@ (Qt-style) doxygen markers. |
||
6 | |||
7 | Since we are using the AUTOBRIEF feature, always end the first sentence with a full-stop "." to mark the end of the short description. |
||
8 | This allows omitting the @\brief@ markers everywhere. |
||
9 | |||
10 | Never rely on line breaks as semantic separation or to end a sentence, always use proper punctuation. The API doc may be rendered with different line breaks than in the source file. |
||
11 | |||
12 | 4 | neels | h2. Locations |
13 | |||
14 | Header files usually contain merely function declarations bare of any API docs. The API doc comment should be in a @.c@ file at the definition of a function. |
||
15 | |||
16 | Structs and enums defined in a header file, though, also have their API doc comments in that @.h@ file. |
||
17 | |||
18 | 10 | neels | Comments for single-line items like enum values or struct members can be placed on the same line using @/*!< Description */@. |
19 | |||
20 | 4 | neels | h2. Grammar |
21 | |||
22 | Always use the imperative form, i.e. omit wording like "This function does", and avoid writing documentation that merely mirrors a function's name. For example: |
||
23 | |||
24 | <pre> |
||
25 | /*! Return a (static) buffer containing a hexdump of the msg. |
||
26 | * \param[in] msg message buffer |
||
27 | * \returns a pointer to a static char array |
||
28 | */ |
||
29 | const char *msgb_hexdump(const struct msgb *msg) |
||
30 | { |
||
31 | ... |
||
32 | </pre> |
||
33 | |||
34 | h2. Parameters |
||
35 | |||
36 | All parameters of a function should be documented. Input params are documented with @\param[in]@, where out-parameters (pointers to which returned data is written) are documented with @\param[out]@. Rarely, a param is both: @\param[inout]@. |
||
37 | |||
38 | <pre> |
||
39 | /*! Apply nifty algorithm. |
||
40 | * \param[in] x0 First factor. |
||
41 | * \param[in] n Amount of values to calculate. |
||
42 | * \param[out] buf Write calculated values to this buffer. |
||
43 | * |
||
44 | * Optional longer function description. */ |
||
45 | 1 | neels | </pre> |
46 | 7 | neels | |
47 | 8 | neels | It is also possible to document parameters without a direction, using merely @\param param_name Description@, however, it is desirable to always indicate @[in]@, @[out]@ or @[inout]@. |
48 | 4 | neels | |
49 | 1 | neels | h2. File comments |
50 | |||
51 | If a file contains a descriptive comment, this comment should be right at the start of the file, as a doxygen @\file@ section. |
||
52 | The first sentence must be ended by a full stop "." to mark the end of the short description. |
||
53 | The copyright notice shall not be part of such API doc file comment. |
||
54 | |||
55 | <pre> |
||
56 | /*! \file foo.c |
||
57 | * Short description. */ |
||
58 | /* |
||
59 | * (C) 2017 ... Copyright not in a doxygen comment |
||
60 | * license information |
||
61 | */ |
||
62 | </pre> |
||
63 | |||
64 | or |
||
65 | |||
66 | <pre> |
||
67 | /*! \file foo.c |
||
68 | * Short description. |
||
69 | * |
||
70 | * More information in multiple lines. |
||
71 | */ |
||
72 | /* |
||
73 | * (C) 2017 ... |
||
74 | */ |
||
75 | </pre> |
||
76 | |||
77 | 11 | neels | If a file needs no description, it is ok to omit the @\file@ tag entirely. Since we are using EXTRACT_ALL = YES, files lacking a @\file@ tag are still listed in the API docs. |
78 | 9 | neels | |
79 | 1 | neels | h2. Groups |
80 | |||
81 | Doxygen allows grouping elements: a group can include code elements and also entire files. |
||
82 | |||
83 | This works by enclosing the items to be grouped between an opening and a closing marker: |
||
84 | |||
85 | * A @\defgroup@ initially defines a group, this shall exist only once. |
||
86 | * More items can be added using an @\addtogroup@ marker. |
||
87 | * Both have to be closed by "@}". |
||
88 | |||
89 | For example: |
||
90 | |||
91 | <pre> |
||
92 | /*! \defgroup groupname Short description of the group. |
||
93 | * @{ |
||
94 | */ |
||
95 | |||
96 | struct type_that_belongs_to_group { |
||
97 | ... |
||
98 | }; |
||
99 | |||
100 | void func_that_belongs_to_group() |
||
101 | { |
||
102 | ... |
||
103 | } |
||
104 | |||
105 | /*! @} */ |
||
106 | </pre> |
||
107 | |||
108 | and |
||
109 | |||
110 | <pre> |
||
111 | /*! \addtogroup groupname |
||
112 | * @{ |
||
113 | */ |
||
114 | |||
115 | 3 | neels | ... |
116 | 1 | neels | |
117 | /*! @} */ |
||
118 | </pre> |
||
119 | |||
120 | 5 | neels | If a *file* should be added to a group, add a (possibly second) short descriptionless @\file@ tag to the group start. To clearly mark that the purpose is to add to the group, do so within the same comment block: |
121 | 1 | neels | |
122 | <pre> |
||
123 | /*! \file foo.c |
||
124 | 2 | neels | * File's description. */ |
125 | 1 | neels | /* |
126 | * (C) ... |
||
127 | */ |
||
128 | |||
129 | /*! \addtogroup groupname |
||
130 | * @{ |
||
131 | * \file foo.c */ |
||
132 | |||
133 | ... |
||
134 | |||
135 | /*! @} */ |
||
136 | </pre> |
||
137 | |||
138 | The point is that we like to have a file's short description near the start of the file, to also serve us well when we're reading only the .h file. But to be included in a group, the doxygen group start must precede the @\file@ tag. Also, the doxygen group should rather not enclose @#include@ directives, to clearly exclude those from the group. Hence, the best way is to keep the file's actual description at the top of the file, and add a second descriptionless @\file@ with the group opening. |
||
139 | |||
140 | A group may contain a short as well as a longer description. We often @\defgroup@ in a @.h@ file but keep the longer description in an @\addtogroup@ in a @.c@ file. Any @\file@ tags must follow *after* such description, or the description will be associated with the file instead of the group: |
||
141 | |||
142 | @.h@ file: |
||
143 | <pre> |
||
144 | /*! \defgroup groupname Short description of the group. |
||
145 | * @{ |
||
146 | */ |
||
147 | |||
148 | ... |
||
149 | |||
150 | /*! @} */ |
||
151 | </pre> |
||
152 | |||
153 | @.c file: |
||
154 | |||
155 | <pre> |
||
156 | /*! \addtogroup groupname |
||
157 | * @{ |
||
158 | * Longer description of the group. |
||
159 | * - contains a |
||
160 | * - bullet list |
||
161 | * |
||
162 | * As well as a |
||
163 | * |
||
164 | * Code example |
||
165 | * block |
||
166 | * |
||
167 | 6 | neels | * All of which must not be below the directive adding this file to the group... |
168 | 1 | neels | * |
169 | * \file foo.c */ |
||
170 | |||
171 | [...] |
||
172 | |||
173 | /*! @} */ |
||
174 | </pre> |
||
175 | |||
176 | Often, a file's description matches or is identical with a group's description. In that case, the file's description header comment can be omitted to avoid duplicating identical descriptions. |
||
177 | |||
178 | <pre> |
||
179 | /* |
||
180 | * (C) 2017 ... |
||
181 | */ |
||
182 | |||
183 | /* \addtogroup group |
||
184 | * @{ |
||
185 | * Description... |
||
186 | * |
||
187 | * \file foo.c */ |
||
188 | |||
189 | ... |
||
190 | |||
191 | /* @} */ |
||
192 | </pre> |