API: clean up error codes
[dokuwiki.git] / lib / exe / openapi.php
blob5a3480cf334d8e17cf20a07c09f83dfc766aee29
1 <?php
3 use dokuwiki\Remote\OpenApiDoc\OpenAPIGenerator;
5 if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../');
6 require_once(DOKU_INC . 'inc/init.php');
7 global $INPUT;
9 if ($INPUT->has('spec')) {
10 header('Content-Type: application/json');
11 $apigen = new OpenAPIGenerator();
12 echo $apigen->generate();
13 exit();
16 <!doctype html>
17 <html lang="en">
18 <head>
19 <meta charset="utf-8">
20 <title>DokuWiki API Explorer</title>
21 <script src="https://unpkg.com/openapi-explorer/dist/browser/openapi-explorer.min.js" type="module"
22 defer=""></script>
23 <style>
24 body {
25 font-family: sans-serif;
27 </style>
28 </head>
29 <body>
30 <openapi-explorer
31 spec-url="<?php echo DOKU_URL ?>lib/exe/openapi.php?spec=1"
32 hide-server-selection="true"
33 use-path-in-nav-bar="true"
35 <div slot="overview-api-description">
36 <p>
37 This is an auto generated description and OpenAPI specification for the
38 <a href="https://www.dokuwiki.org/devel/jsonrpc">DokuWiki JSON-RPC API</a>.
39 It is generated from the source code and the inline documentation.
40 </p>
42 <p>
43 <a href="<?php echo DOKU_BASE ?>/lib/exe/openapi.php?spec=1" download="dokuwiki.json">Download
44 the API Spec</a>
45 </p>
47 <h3>Error Codes</h3>
49 <p>
50 The following error codes are currently used in the core methods. This list may be incomplete
51 or change in the future.
52 </p>
54 <table>
55 <tr><th>Code</th><th>Message</th></tr>
56 <tr><td>0</td><td>Success</td></tr>
57 <?php
58 $apigen = new OpenAPIGenerator();
59 $last = 0;
60 foreach ($apigen->getErrorCodes() as $code) {
61 // duplicate codes are only shown with debug
62 if($code['code'] === $last && !$INPUT->has('debug')) continue;
63 echo '<tr><td>' . $code['code'] . '</td><td>' . hsc($code['message']) . '</td></tr>';
66 </table>
67 </div>
69 <div slot="authentication-footer">
70 <p>
71 <?php
72 if ($INPUT->server->has('REMOTE_USER')) {
73 echo 'You are currently logged in as <strong>' . hsc($INPUT->server->str('REMOTE_USER')) . '</strong>.';
74 echo '<br>API calls in this tool will be automatically executed with your permissions.';
75 } else {
76 echo 'You are currently not logged in.<br>';
77 echo 'You can provide credentials above.';
80 </p>
81 </div>
82 </openapi-explorer>
83 </body>
84 </html>