2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Swagger UI for Moodle
21 * @copyright Andrew Lyons <andrew@nicols.co.uk>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require('../config.php');
26 require_once($CFG->libdir
. '/adminlib.php');
28 $swaggerversion = '5.17.14';
30 $PAGE->set_url('/admin/swaggerui.php');
32 admin_externalpage_setup('swaggerui');
34 $PAGE->requires
->css(new moodle_url("https://unpkg.com/swagger-ui-dist@{$swaggerversion}/swagger-ui.css"));
36 echo $OUTPUT->header();
38 // These have to be manually added for now because they must be made cross-origin. The `js` method does not yet support this.
39 echo html_writer
::tag(
43 'src' => new moodle_url("https://unpkg.com/swagger-ui-dist@{$swaggerversion}/swagger-ui-bundle.js"),
44 'crossorigin' => 'crossorigin',
47 echo html_writer
::tag(
51 'src' => new moodle_url("https://unpkg.com/swagger-ui-plugin-hierarchical-tags"),
52 'crossorigin' => 'crossorigin',
56 $openapipath = moodle_url
::routed_path('/api/rest/v2/openapi.json')->out();
58 window.ui = SwaggerUIBundle({
59 url: "{$openapipath}",
60 dom_id: '#swagger-ui',
62 // Enable the "Try it out" button by default.
63 tryItOutEnabled: true,
65 // Show snippets different OS options.
66 requestSnippetsEnabled: true,
71 HierarchicalTagsPlugin,
74 hierarchicalTagSeparator: /[_]/
78 $PAGE->requires
->js_init_code(
83 echo html_writer
::div('', '', [
87 echo $OUTPUT->footer();