Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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.
13
//
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/>.
16
 
17
/**
18
 * Swagger UI for Moodle
19
 *
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
23
 */
24
 
25
require('../config.php');
26
require_once($CFG->libdir . '/adminlib.php');
27
 
28
$swaggerversion = '5.17.14';
29
 
30
$PAGE->set_url('/admin/swaggerui.php');
31
 
32
admin_externalpage_setup('swaggerui');
33
 
34
$PAGE->requires->css(new moodle_url("https://unpkg.com/swagger-ui-dist@{$swaggerversion}/swagger-ui.css"));
35
 
36
echo $OUTPUT->header();
37
 
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',
45
    ],
46
);
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',
53
    ],
54
);
55
 
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',
61
 
62
        // Enable the "Try it out" button by default.
63
        tryItOutEnabled: true,
64
 
65
        // Show snippets different OS options.
66
        requestSnippetsEnabled: true,
67
 
68
        deepLinking: true,
69
 
70
        plugins: [
71
            HierarchicalTagsPlugin,
72
        ],
73
 
74
        hierarchicalTagSeparator: /[_]/
75
    });
76
JS;
77
 
78
$PAGE->requires->js_init_code(
79
    jscode: $swaggerinit,
80
    ondomready: true,
81
);
82
 
83
echo html_writer::div('', '', [
84
    'id' => 'swagger-ui',
85
]);
86
 
87
echo $OUTPUT->footer();