Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add api_key_placeholder option #114

Merged
merged 7 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading