Skip to content

Commit cffa0ce

Browse files
authored
Add api_key_placeholder option (#114)
* Update grape-swagger-rails.rb * Update index.html.erb * Update swagger_spec.rb * Update README.md * Update .rubocop_todo.yml * Update CHANGELOG.md
1 parent 5799fa2 commit cffa0ce

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-4
lines changed

.rubocop_todo.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-03-30 00:44:45 UTC using RuboCop version 1.48.1.
3+
# on 2024-02-22 14:55:40 UTC using RuboCop version 1.60.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -29,7 +29,7 @@ Lint/MixedRegexpCaptureTypes:
2929
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
3030
# AllowedMethods: refine
3131
Metrics/BlockLength:
32-
Max: 282
32+
Max: 291
3333

3434
# Offense count: 2
3535
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Your contribution here.
44
* [#110](https://github.com/ruby-grape/grape-swagger-rails/pull/110): Update dummy app to current rails conventions - [@duffn](https://github.com/duffn).
55
* [#112](https://github.com/ruby-grape/grape-swagger-rails/pull/112): Add Rubocop Action & autocorrect violations - [@duffn](https://github.com/duffn).
6+
* [#114](https://github.com/ruby-grape/grape-swagger-rails/pull/114): Add `api_key_placeholder` option - [@SofiaSousa](https://github.com/SofiaSousa).
67

78
### 0.4.0 (2023/03/28)
89

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,10 @@ by specify:
158158
GrapeSwaggerRails.options.api_auth = 'token'
159159
GrapeSwaggerRails.options.api_key_name = 'Authorization'
160160
GrapeSwaggerRails.options.api_key_type = 'header'
161+
GrapeSwaggerRails.options.api_key_placeholder = 'authorization_token'
161162
```
162163

163-
You can use the ```api_key``` input box to fill in your API token.
164+
You can use the ```authorization_token``` input box to fill in your API token.
164165
### Swagger UI Authorization
165166

166167
You may want to authenticate users before displaying the Swagger UI, particularly when the API is protected by Basic Authentication.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696

9797
<form id='api_selector'>
9898
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
99-
<div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text" value="<%= GrapeSwaggerRails.options.api_key_default_value %>"/></div>
99+
<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>
100100
<div class='input'><a id="explore" class="exploreBtn" href="#">Explore</a></div>
101101
</form>
102102
</div>

lib/grape-swagger-rails.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def before_action(&block)
3232
api_key_name: 'api_key', # 'Authorization'
3333
api_key_type: 'query', # 'header'
3434
api_key_default_value: '', # Auto populates api_key
35+
api_key_placeholder: 'api_key', # Placeholder for api_key input
3536

3637
doc_expansion: 'none',
3738
supported_submit_methods: %w[get post put delete patch],

spec/features/swagger_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@
6666
.to eq('name' => 'Authorization', 'value' => 'Bearer token')
6767
end
6868
end
69+
context '#api_key_placeholder' do
70+
before do
71+
GrapeSwaggerRails.options.api_key_placeholder = 'authorization_code'
72+
visit '/swagger'
73+
end
74+
it 'adds a custom placeholder' do
75+
expect(find('#input_apiKey')['placeholder']).to eq 'authorization_code'
76+
end
77+
end
6978
context '#api_auth:basic' do
7079
before do
7180
GrapeSwaggerRails.options.api_auth = 'basic'

0 commit comments

Comments
 (0)