. /** * Swagger UI for Moodle * * @package core_admin * @copyright Andrew Lyons * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require('../config.php'); require_once($CFG->libdir . '/adminlib.php'); $swaggerversion = '5.17.14'; $PAGE->set_url('/admin/swaggerui.php'); admin_externalpage_setup('swaggerui'); $PAGE->requires->css(new moodle_url("https://unpkg.com/swagger-ui-dist@{$swaggerversion}/swagger-ui.css")); echo $OUTPUT->header(); // These have to be manually added for now because they must be made cross-origin. The `js` method does not yet support this. echo html_writer::tag( tagname: 'script', contents: '', attributes: [ 'src' => new moodle_url("https://unpkg.com/swagger-ui-dist@{$swaggerversion}/swagger-ui-bundle.js"), 'crossorigin' => 'crossorigin', ], ); echo html_writer::tag( tagname: 'script', contents: '', attributes: [ 'src' => new moodle_url("https://unpkg.com/swagger-ui-plugin-hierarchical-tags"), 'crossorigin' => 'crossorigin', ], ); $openapipath = moodle_url::routed_path('/api/rest/v2/openapi.json')->out(); $swaggerinit = <<requires->js_init_code( jscode: $swaggerinit, ondomready: true, ); echo html_writer::div('', '', [ 'id' => 'swagger-ui', ]); echo $OUTPUT->footer();