Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #871 from romainneutron/csp-compatibility
Make swagger UI compatible in a CSP environment
- Loading branch information
Showing
5 changed files
with
118 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/Bridge/Symfony/Bundle/Resources/public/init-swagger-ui.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
$(function () { | ||
var data = JSON.parse($('#swagger-data').html()); | ||
window.swaggerUi = new SwaggerUi({ | ||
url: data.url, | ||
spec: data.spec, | ||
dom_id: 'swagger-ui-container', | ||
supportedSubmitMethods: ['get', 'post', 'put', 'delete'], | ||
onComplete: function() { | ||
$('pre code').each(function(i, e) { | ||
hljs.highlightBlock(e) | ||
}); | ||
|
||
if (data.operationId !== undefined) { | ||
var queryParameters = data.queryParameters; | ||
var domSelector = '#' + data.shortName+'_'+data.operationId; | ||
|
||
$(domSelector + ' form.sandbox input.parameter').each(function (i, e) { | ||
var $e = $(e); | ||
var name = $e.attr('name'); | ||
|
||
if (name in queryParameters) { | ||
$e.val(queryParameters[name]); | ||
} | ||
}); | ||
|
||
if (data.id) { | ||
$(domSelector + ' form.sandbox input[name="id"]').val(data.id); | ||
} | ||
|
||
$(domSelector + ' form.sandbox').submit(); | ||
document.location.hash = '#!/' + data.shortName + '/' + data.operationId; | ||
} | ||
}, | ||
onFailure: function() { | ||
log('Unable to Load SwaggerUI'); | ||
}, | ||
docExpansion: 'list', | ||
jsonEditor: false, | ||
defaultModelRendering: 'schema', | ||
showRequestHeaders: true | ||
}); | ||
|
||
window.swaggerUi.load(); | ||
|
||
function log() { | ||
if ('console' in window) { | ||
console.log.apply(console, arguments); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters