Skip to content

Commit

Permalink
Add api_key_placeholder option (#114)
Browse files Browse the repository at this point in the history
* Update grape-swagger-rails.rb

* Update index.html.erb

* Update swagger_spec.rb

* Update README.md

* Update .rubocop_todo.yml

* Update CHANGELOG.md
  • Loading branch information
SofiaSousa authored Feb 24, 2024
1 parent 5799fa2 commit cffa0ce
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-03-30 00:44:45 UTC using RuboCop version 1.48.1.
# on 2024-02-22 14:55:40 UTC using RuboCop version 1.60.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -29,7 +29,7 @@ Lint/MixedRegexpCaptureTypes:
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 282
Max: 291

# Offense count: 2
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Your contribution here.
* [#110](https://github.com/ruby-grape/grape-swagger-rails/pull/110): Update dummy app to current rails conventions - [@duffn](https://github.com/duffn).
* [#112](https://github.com/ruby-grape/grape-swagger-rails/pull/112): Add Rubocop Action & autocorrect violations - [@duffn](https://github.com/duffn).
* [#114](https://github.com/ruby-grape/grape-swagger-rails/pull/114): Add `api_key_placeholder` option - [@SofiaSousa](https://github.com/SofiaSousa).

### 0.4.0 (2023/03/28)

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ by specify:
GrapeSwaggerRails.options.api_auth = 'token'
GrapeSwaggerRails.options.api_key_name = 'Authorization'
GrapeSwaggerRails.options.api_key_type = 'header'
GrapeSwaggerRails.options.api_key_placeholder = 'authorization_token'
```

You can use the ```api_key``` input box to fill in your API token.
You can use the ```authorization_token``` input box to fill in your API token.
### Swagger UI Authorization

You may want to authenticate users before displaying the Swagger UI, particularly when the API is protected by Basic Authentication.
Expand Down
2 changes: 1 addition & 1 deletion app/views/grape_swagger_rails/application/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@

<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="api_key" id="input_apiKey" name="apiKey" type="text" value="<%= GrapeSwaggerRails.options.api_key_default_value %>"/></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>
Expand Down
1 change: 1 addition & 0 deletions lib/grape-swagger-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def before_action(&block)
api_key_name: 'api_key', # 'Authorization'
api_key_type: 'query', # 'header'
api_key_default_value: '', # Auto populates api_key
api_key_placeholder: 'api_key', # Placeholder for api_key input

doc_expansion: 'none',
supported_submit_methods: %w[get post put delete patch],
Expand Down
9 changes: 9 additions & 0 deletions spec/features/swagger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@
.to eq('name' => 'Authorization', 'value' => 'Bearer token')
end
end
context '#api_key_placeholder' do
before do
GrapeSwaggerRails.options.api_key_placeholder = 'authorization_code'
visit '/swagger'
end
it 'adds a custom placeholder' do
expect(find('#input_apiKey')['placeholder']).to eq 'authorization_code'
end
end
context '#api_auth:basic' do
before do
GrapeSwaggerRails.options.api_auth = 'basic'
Expand Down

0 comments on commit cffa0ce

Please sign in to comment.