curl hack to showcase curl output in the swagger-ui
This commit is contained in:
21
dist/css/style.css
vendored
Normal file
21
dist/css/style.css
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
.curl {
|
||||
padding: 10px;
|
||||
font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace;
|
||||
font-size: 0.9em;
|
||||
max-height: 400px;
|
||||
margin-top: 5px;
|
||||
overflow-y: auto;
|
||||
background-color: #fcf6db;
|
||||
border: 1px solid #e5e0c6;
|
||||
border-radius: 4px;
|
||||
|
||||
}
|
||||
|
||||
.curl_title {
|
||||
font-size: 1.1em;
|
||||
margin: 0;
|
||||
padding: 15px 0 5px;
|
||||
font-family: 'Open Sans','Helvetica Neue',Arial,sans-serif;
|
||||
font-weight: 500;
|
||||
line-height: 1.1;
|
||||
}
|
||||
98
dist/index.html
vendored
98
dist/index.html
vendored
@@ -9,6 +9,8 @@
|
||||
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
|
||||
<link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/>
|
||||
<link href='css/print.css' media='print' rel='stylesheet' type='text/css'/>
|
||||
<link href='css/style.css' media='screen' rel='stylesheet' type='text/css' />
|
||||
|
||||
<script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
|
||||
<script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
|
||||
<script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
|
||||
@@ -97,5 +99,101 @@
|
||||
|
||||
<div id="message-bar" class="swagger-ui-wrap"> </div>
|
||||
<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
|
||||
|
||||
<!-- Curl Script -->
|
||||
|
||||
<script type="text/javascript">
|
||||
$('body.swagger-section').on('click', '.sandbox_header', function(){
|
||||
setTimeout(function(){
|
||||
var parent = $(this).closest('.content');
|
||||
var nearest = parent.find('.response');
|
||||
|
||||
//create a way to input specific username and password variables
|
||||
//to generate base 64 bits. (i.e. a sign in menu)
|
||||
var username = $("#user").val();
|
||||
var password = $("#password").val();
|
||||
|
||||
|
||||
var authcode = btoa(username + ":" + password);
|
||||
|
||||
parent.find('.response .curl').remove();
|
||||
parent.find('.response .curl_title').remove();
|
||||
|
||||
authcode = "Basic " + authcode;
|
||||
|
||||
|
||||
var url = $(this).closest('.endpoint').find('.block.request_url pre').html();
|
||||
var method = $(this).closest('.endpoint').find('.http_method .toggleOperation').html().toUpperCase();
|
||||
var parameters = $(this).closest('.endpoint').find('.body-textarea.required').val();
|
||||
|
||||
var text2;
|
||||
|
||||
if (username == "" || password == ""){
|
||||
authcode = '<Please Sign in>'
|
||||
}
|
||||
|
||||
if (method == 'GET'){
|
||||
text2 = method + ' -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Authorization: ' + authcode + '" ' ;
|
||||
}
|
||||
|
||||
if (method == 'POST'){
|
||||
text2 = method + ' -H "Content-Type: application/json" -H "Authorization: ' + authcode +'" ' + '-H "Cache-Control: no-cache" -d \'' + parameters + '\' ';
|
||||
}
|
||||
|
||||
if (method == 'DELETE') {
|
||||
text2 = method + ' -H "Content-Type: application/json" -H "Authorization: ' + authcode + '" ';
|
||||
}
|
||||
|
||||
if (method == 'PUT') {
|
||||
text2 = method + ' -H "Content-Type: application/json" -H "Authorization: ' + authcode + '" ';
|
||||
}
|
||||
|
||||
|
||||
$('<div/>', {
|
||||
class: 'curl',
|
||||
text:'curl -X ' + text2 + url,
|
||||
}).prependTo(nearest);
|
||||
|
||||
$('<h4>', {
|
||||
class: 'curl_title',
|
||||
text: 'Curl',
|
||||
}).prependTo(nearest);
|
||||
|
||||
|
||||
|
||||
}.bind(this), 500)});
|
||||
|
||||
</script>
|
||||
|
||||
<!--Double click to highlight all Curl -->
|
||||
<script type="text/javascript">
|
||||
|
||||
function SelectText(element) {
|
||||
var doc = document,
|
||||
text = element,
|
||||
range,
|
||||
selection;
|
||||
if (doc.body.createTextRange) {
|
||||
range = document.body.createTextRange();
|
||||
range.moveToElementText(text);
|
||||
range.select();
|
||||
} else if (window.getSelection) {
|
||||
selection = window.getSelection();
|
||||
range = document.createRange();
|
||||
range.selectNodeContents(text);
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$('body.swagger-section').on('dblclick', '.curl', function(){
|
||||
SelectText($(this)[0].childNodes[0]);
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
6
lib/bootstrap.min.js
vendored
Normal file
6
lib/bootstrap.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user