-
Notifications
You must be signed in to change notification settings - Fork 196
/
index.html.erb
115 lines (98 loc) · 3.89 KB
/
index.html.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<html data-swagger-options="<%= GrapeSwaggerRails.options.marshal_dump.to_json %>">
<head>
<title><%= GrapeSwaggerRails.options.app_name || 'Swagger UI' %></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
<%= stylesheet_link_tag 'grape_swagger_rails/application.css' %>
<%= javascript_include_tag 'grape_swagger_rails/application.js' %>
<script type="text/javascript">
$(function () {
var options = $("html").data('swagger-options');
var headers = {};
<% GrapeSwaggerRails.options.headers.each_with_index do |(key, value), index| %>
<%=raw "headers.header_#{index} = new SwaggerClient.ApiKeyAuthorization('#{CGI.escapeHTML(key)}', '#{CGI.escapeHTML(value)}', 'header');" %>
<% end %>
<% if GrapeSwaggerRails.options.api_key_default_value.try(:strip).present? &&
GrapeSwaggerRails.options.headers['Authorization'].blank? %>
<% headers_count = GrapeSwaggerRails.options.headers.count %>
<%= raw "headers.header_#{headers_count} = getApiKeyAuthorization();" %>
<% end %>
window.swaggerUi = new SwaggerUi({
url: options.app_url + options.url,
dom_id: "swagger-ui-container",
supportHeaderParams: true,
supportedSubmitMethods: options.supported_submit_methods || [],
authorizations: headers,
onComplete: function(swaggerApi, swaggerUi){
if('console' in window) {
console.log("Loaded SwaggerUI")
console.log(swaggerApi);
console.log(swaggerUi);
}
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
},
onFailure: function(data) {
if('console' in window) {
console.log("Unable to Load SwaggerUI");
console.log(data);
}
},
docExpansion: options.doc_expansion,
validatorUrl: options.validator_url,
apisSorter: "alpha"
});
function getApiKeyAuthorization() {
var key = $('#input_apiKey')[0].value;
if (key && key.trim() != "") {
if (options.api_auth == 'basic') {
key = "Basic " + Base64.encode(key);
} else if (options.api_auth == 'bearer') {
key = "Bearer " + key;
} else if (options.api_auth == 'token') {
key = 'Token token="' + key + '"';
}
return new SwaggerClient.ApiKeyAuthorization(options.api_key_name, key, options.api_key_type);
}
}
function addApiKeyAuthorization() {
var apiKeyAuthorization = getApiKeyAuthorization();
if (apiKeyAuthorization) {
window.swaggerUi.api.clientAuthorizations.add("key", apiKeyAuthorization);
}
}
$('#input_apiKey').change(addApiKeyAuthorization);
window.swaggerUi.load();
});
</script>
<style>
input#input_baseUrl, a#explore.exploreBtn {
<% if GrapeSwaggerRails.options.hide_url_input %>
display: none;
<% end %>
}
input#input_apiKey {
<% if GrapeSwaggerRails.options.hide_api_key_input %>
display: none;
<% end %>
}
</style>
</head>
<body class="swagger-section">
<div id='header'>
<div class="swagger-ui-wrap">
<a id="logo" href="<%= GrapeSwaggerRails.options.app_url %>"><%= GrapeSwaggerRails.options.app_name %></a>
<form id='api_selector'>
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
<div class='input'><input placeholder="<%= GrapeSwaggerRails.options.api_key_placeholder %>" id="input_apiKey" name="apiKey" type="text" value="<%= GrapeSwaggerRails.options.api_key_default_value %>"/></div>
<div class='input'><a id="explore" class="exploreBtn" href="#">Explore</a></div>
</form>
</div>
</div>
<div id="message-bar" class="swagger-ui-wrap">
</div>
<div id="swagger-ui-container" class="swagger-ui-wrap">
</div>
</body>
</html>