Skip to content

Commit b9a46e6

Browse files
theblindfrogAlex Powell
andauthored
Make the page CSP compatible (#38)
Co-authored-by: Alex Powell <alexanderp@agilitycis.com>
1 parent 5508065 commit b9a46e6

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/index.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use light\swagger\SwaggerUIAsset;
44
use yii\helpers\Json;
5+
use yii\web\View;
56

67
$bundle = SwaggerUIAsset::register($this);
78

@@ -79,15 +80,17 @@
7980

8081
<div id="swagger-ui"></div>
8182
<?php $this->endBody() ?>
82-
<script>
83+
<?php
84+
$oauthConfiguration = ($oauthConfiguration) ? Json::encode($oauthConfiguration) : 'null';
85+
$this->registerJs(<<<JS
8386
window.onload = function() {
8487
// Build a system
85-
window.ui = SwaggerUIBundle(<?= $configurations ?>);
86-
<?php if ($oauthConfiguration) :?>
87-
window.ui.initOAuth(<?= Json::encode($oauthConfiguration) ?>);
88-
<?php endif; ?>
88+
window.ui = SwaggerUIBundle($configurations);
89+
if ($oauthConfiguration !== null) {
90+
window.ui.initOAuth($oauthConfiguration);
91+
}
8992
}
90-
</script>
93+
JS, View::POS_END); ?>
9194
</body>
9295

9396
</html>

0 commit comments

Comments
 (0)