Skip to content

Commit dc4a854

Browse files
author
Andrew Schuster
committed
Add ability to hide text boxes in header
1 parent 97b79cf commit dc4a854

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

app/views/grape_swagger_rails/application/index.html.erb

+16-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
key = "Bearer " + key
5252
}
5353
window.swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization(options.api_key_name, key, options.api_key_type));
54-
}
54+
}
5555
}
5656

5757
$('#input_apiKey').change(addApiKeyAuthorization);
@@ -60,6 +60,19 @@
6060

6161
});
6262
</script>
63+
<style>
64+
input#input_baseUrl, a#explore.exploreBtn {
65+
<% if GrapeSwaggerRails.options.hide_url_input %>
66+
display: none;
67+
<% end %>
68+
}
69+
70+
input#input_apiKey {
71+
<% if GrapeSwaggerRails.options.hide_api_key_input %>
72+
display: none;
73+
<% end %>
74+
}
75+
</style>
6376
</head>
6477

6578
<body class="swagger-section">
@@ -69,8 +82,8 @@
6982

7083
<form id='api_selector'>
7184
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
72-
<div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
73-
<div class='input'><a id="explore" href="#">Explore</a></div>
85+
<div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text" value="<%= GrapeSwaggerRails.options.api_key_default_value %>"/></div>
86+
<div class='input'><a id="explore" class="exploreBtn" href="#">Explore</a></div>
7487
</form>
7588
</div>
7689
</div>

lib/grape-swagger-rails.rb

+13-9
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@ def before_filter(&block)
1515

1616
self.options = Options.new(
1717

18-
url: '/swagger_doc',
19-
app_name: 'Swagger',
20-
app_url: 'http://swagger.wordnik.com',
18+
url: '/swagger_doc',
19+
app_name: 'Swagger',
20+
app_url: 'http://swagger.wordnik.com',
2121

22-
headers: {},
22+
headers: {},
2323

24-
api_auth: '', # 'basic' or 'bearer'
25-
api_key_name: 'api_key', # 'Authorization'
26-
api_key_type: 'query', # 'header'
24+
api_auth: '', # 'basic' or 'bearer'
25+
api_key_name: 'api_key', # 'Authorization'
26+
api_key_type: 'query', # 'header'
27+
api_key_default_value: '', # Auto populates api_key, override in proc
2728

28-
doc_expansion: 'none',
29+
doc_expansion: 'none',
2930

30-
before_filter_proc: nil # Proc used as a controller before filter
31+
before_filter_proc: nil, # Proc used as a controller before filter
32+
33+
hide_url_input: false,
34+
hide_api_key_input: false
3135
)
3236
end

0 commit comments

Comments
 (0)