Skip to content

Commit af259ad

Browse files
committed
doveadm: Rework response documentation
The old 'fields' entry in data/doveadm.js has been replaced with the 'response' entry. This new entry allows for text description and data type output. Output example JSON server response in the HTTP API block.
1 parent 5cffd98 commit af259ad

File tree

5 files changed

+93
-30
lines changed

5 files changed

+93
-30
lines changed

components/DoveadmComponent.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function httpClick(k) {
4949
<a class="header-anchor" :href="'#' + k"></a>
5050
</h3>
5151

52-
<table v-if="v.man_link || v.fields || v.added || v.changed || v.deprecated || v.removed">
52+
<table v-if="v.man_link || v.response || v.added || v.changed || v.deprecated || v.removed">
5353
<tbody>
5454
<tr v-if="v.man_link">
5555
<th style="text-align: right;">Man Page</th>
@@ -80,20 +80,22 @@ function httpClick(k) {
8080
</td>
8181
</tr>
8282

83-
<tr v-if="v.fields">
84-
<th style="text-align: right;">Return Values</th>
83+
<tr v-if="v.response">
84+
<th style="text-align: right;">Response Values</th>
8585
<td>
8686
<table>
8787
<thead>
8888
<tr>
8989
<th>Key</th>
90-
<th>Value</th>
90+
<th>Type</th>
91+
<th>Description</th>
9192
</tr>
9293
</thead>
9394
<tbody>
94-
<tr v-for="elem in v.fields">
95+
<tr v-for="elem in v.response">
9596
<td><code>{{ elem.key }}</code></td>
96-
<td v-html="elem.value" />
97+
<td v-html="elem.type" />
98+
<td v-html="elem.text" />
9799
</tr>
98100
</tbody>
99101
</table>

components/DoveadmHttpApiComponent.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ const jsonReq =
2020
"tag1"
2121
]
2222
]
23+
24+
const resp = {}
25+
if (d.response) {
26+
for (let elem of d.response) {
27+
resp[elem.key] = elem.example
28+
}
29+
}
30+
31+
const jsonResp =
32+
[
33+
[
34+
"doveadmResponse",
35+
[ resp ],
36+
"tag1"
37+
]
38+
]
2339
</script>
2440

2541
<template>
@@ -88,5 +104,15 @@ const jsonReq =
88104
<span class="lang"></span>
89105
<pre><code>wget --header="Content-Type: application/json" --user=doveadm --password=password --auth-no-challenge --post-data='{{ JSON.stringify(jsonReq) }}' --output-document - http://example.com:8080/doveadm/v1</code></pre>
90106
</div>
107+
108+
<template v-if="d.response?.length">
109+
<p class="custom-block-title">Example Server Response</p>
110+
111+
<div class="language- vp-adaptive-theme">
112+
<button class="copy" title="Copy" />
113+
<span class="lang"></span>
114+
<pre><code>{{ JSON.stringify(jsonResp, null, 4) }}</code></pre>
115+
</div>
116+
</template>
91117
</div>
92118
</template>

data/doveadm.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import { doveadm_arg_types,
33
doveadm_args_query,
44
doveadm_args_usermask,
5-
doveadm_flag_types } from '../lib/doveadm.js'
5+
doveadm_flag_types,
6+
doveadm_response_types } from '../lib/doveadm.js'
67

78
export const doveadm = {
89

@@ -51,8 +52,21 @@ export const doveadm = {
5152
// deprecated: {},
5253
// removed: {},
5354

54-
// Fields/Values returned. Values are rendered w/Markdown.
55-
// fields: {},
55+
// Response data.
56+
// KEY = identifier
57+
// response: {
58+
// key: {
59+
// // An example value to be used in documentation.
60+
// example: 0,
61+
//
62+
// // The description of the response data type.
63+
// // Rendered w/Markdown.
64+
// text: `Description`,
65+
//
66+
// // The response data type
67+
// type: doveadm_response_types.INTEGER,
68+
// }
69+
// },
5670

5771
// What doveadm flags does this command support (bit field)
5872
// Arguments are automatically added for each flag set
@@ -237,8 +251,11 @@ Applicable to [[link,mdbox]] and [[link,sdbox]] mailbox formats only.
237251
text: `UID of user to apply operation to.`,
238252
},
239253
},
240-
fields: {
241-
'entries': 0
254+
response: {
255+
entries: {
256+
type: doveadm_response_types.INTEGER,
257+
text: `The number of cache entries flushed.`
258+
},
242259
},
243260
man: 'doveadm-auth',
244261
text: `Flush authentication cache.`,
@@ -1355,7 +1372,7 @@ to secure it.
13551372
text: `Mailbox mask.`
13561373
},
13571374
},
1358-
fields: {},
1375+
response: {},
13591376
flags: doveadm_flag_types.USER,
13601377
plugin: 'mail-crypt',
13611378
man: 'doveadm-mailbox-cryptokey',
@@ -1375,7 +1392,7 @@ to secure it.
13751392
text: `Mailbox mask.`
13761393
},
13771394
},
1378-
fields: {},
1395+
response: {},
13791396
flags: doveadm_flag_types.USER,
13801397
plugin: 'mail-crypt',
13811398
man: 'doveadm-mailbox-cryptokey',
@@ -1410,7 +1427,7 @@ to secure it.
14101427
text: `Old password.`
14111428
},
14121429
},
1413-
fields: {},
1430+
response: {},
14141431
flags: doveadm_flag_types.USER,
14151432
plugin: 'mail-crypt',
14161433
man: 'doveadm-mailbox-cryptokey',

lib/data/doveadm.data.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { doveadm_arg_types, doveadm_flag_types, getDoveadmCmdLine } from '../doveadm.js'
1+
import { doveadm_arg_types, doveadm_flag_types, doveadm_response_types, getDoveadmCmdLine } from '../doveadm.js'
22
import { getVitepressMd } from '../markdown.js'
33
import { addWatchPaths, loadData, normalizeArrayData } from '../utility.js'
44
import camelCase from 'camelcase'
@@ -39,17 +39,26 @@ const doveadm_userfileargs = {
3939
function typeToString(type) {
4040
switch (type) {
4141
case doveadm_arg_types.ARRAY:
42-
return 'array';
42+
return 'array'
4343
case doveadm_arg_types.BOOL:
44-
return 'boolean';
44+
return 'boolean'
4545
case doveadm_arg_types.INTEGER:
46-
return 'integer';
46+
return 'integer'
4747
case doveadm_arg_types.STRING:
48-
return 'string';
48+
return 'string'
4949
case doveadm_arg_types.SEARCH_QUERY:
50-
return 'search_query';
50+
return 'search_query'
5151
case doveadm_arg_types.ISTREAM:
52-
return 'istream';
52+
return 'istream'
53+
}
54+
}
55+
56+
function responseTypeLookup(type) {
57+
switch (type) {
58+
case doveadm_response_types.INTEGER:
59+
return [ 'integer', 1 ]
60+
case doveadm_response_types.STRING:
61+
return [ 'string', 'example' ]
5362
}
5463
}
5564

@@ -97,19 +106,22 @@ async function normalizeDoveadm(doveadm) {
97106
}
98107
}
99108

100-
/* Return values. */
101-
if (v.fields) {
102-
const fields = []
103-
for (const [k2, v2] of Object.entries(v.fields)) {
104-
fields.push({
109+
/* Response values. */
110+
if (v.response) {
111+
const response = []
112+
for (const [k2, v2] of Object.entries(v.response)) {
113+
var rtl = responseTypeLookup(v2.type)
114+
response.push({
115+
example: v2.example ?? rtl[1],
105116
key: k2,
106-
value: v2 ? md.renderInline(String(v2)) : null
117+
type: rtl[0],
118+
text: v2.text ? md.renderInline(String(v2.text)) : null
107119
})
108120
}
109-
v.fields = fields
121+
v.response = response
110122
}
111-
if (!v.fields || !v.fields.length) {
112-
delete v['fields']
123+
if (!v.response || !v.response.length) {
124+
delete v['response']
113125
}
114126

115127
/* Text Description. */

lib/doveadm.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ export const doveadm_flag_types = {
1616
USERMASK: 4,
1717
}
1818

19+
/* List of Doveadm response value types. */
20+
export const doveadm_response_types = {
21+
INTEGER: 1,
22+
STRING: 2,
23+
}
24+
1925
export const doveadm_args_query = {
2026
//example: ['mailbox', 'INBOX/myfoldertoo', 'savedbefore', 'since', '30d'],
2127
positional: true,

0 commit comments

Comments
 (0)