weekly release 5.0dev
[moodle.git] / admin / swaggerui.php
blob45a66d1470daa25d4798f6ffec8440e4ba27e587
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * Swagger UI for Moodle
20 * @package core_admin
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(
40 tagname: 'script',
41 contents: '',
42 attributes: [
43 'src' => new moodle_url("https://unpkg.com/swagger-ui-dist@{$swaggerversion}/swagger-ui-bundle.js"),
44 'crossorigin' => 'crossorigin',
47 echo html_writer::tag(
48 tagname: 'script',
49 contents: '',
50 attributes: [
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();
57 $swaggerinit = <<<JS
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,
68 deepLinking: true,
70 plugins: [
71 HierarchicalTagsPlugin,
74 hierarchicalTagSeparator: /[_]/
75 });
76 JS;
78 $PAGE->requires->js_init_code(
79 jscode: $swaggerinit,
80 ondomready: true,
83 echo html_writer::div('', '', [
84 'id' => 'swagger-ui',
85 ]);
87 echo $OUTPUT->footer();