diff --git a/README.md b/README.md index 08f0157..80b0d41 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,9 @@ Once you have an API that can describe itself in Swagger, you've opened the trea ```ruby rails g rswag:install ``` - + Or run the install generators for each package separately if you installed Rswag as separate gems, as indicated above: - + ```ruby rails g rswag:api:install rswag:ui:install RAILS_ENV=test rails g rswag:specs:install @@ -477,6 +477,17 @@ Rswag::Ui.configure do |c| end ``` +### Enable Simple Basic Auth for swagger-ui + +You can also update the _rswag-ui.rb_ initializer, installed with rswag-ui to specify a username and password should you want to keep your documentation private. + +```ruby +Rswag::Ui.configure do |c| + c.basic_auth_enabled = true + c.basic_auth_credentials 'username', 'password' +end +``` + ### Route Prefix for the swagger-ui ### Similar to rswag-api, you can customize the swagger-ui path by changing it's mount prefix in _routes.rb_: diff --git a/rswag-ui/spec/rswag/ui/configuration_spec.rb b/rswag-ui/spec/rswag/ui/configuration_spec.rb new file mode 100644 index 0000000..2df2c8d --- /dev/null +++ b/rswag-ui/spec/rswag/ui/configuration_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +RSpec.describe Rswag::Ui::Configuration do + describe '#swagger_endpoints' + + describe '#basic_auth_enabled' do + context 'when unspecified' do + it 'defaults to false' do + configuration = described_class.new + basic_auth_enabled = configuration.basic_auth_enabled + + expect(basic_auth_enabled).to be(false) + end + end + + context 'when specified' do + context 'when set to true' do + it 'returns true' do + configuration = described_class.new + configuration.basic_auth_enabled = true + basic_auth_enabled = configuration.basic_auth_enabled + + expect(basic_auth_enabled).to be(true) + end + end + + context 'when set to false' do + it 'returns false' do + configuration = described_class.new + configuration.basic_auth_enabled = false + basic_auth_enabled = configuration.basic_auth_enabled + + expect(basic_auth_enabled).to be(false) + end + end + end + end + + describe '#basic_auth_credentials' do + it 'sets the username and password' do + configuration = described_class.new + configuration.basic_auth_credentials 'foo', 'bar' + credentials = configuration.config_object[:basic_aut] + + expect(credentials).to eq(username: 'foo', password: 'bar') + end + end + + describe '#get_binding' +end diff --git a/rswag-ui/spec/spec_helper.rb b/rswag-ui/spec/spec_helper.rb index e69de29..c242286 100644 --- a/rswag-ui/spec/spec_helper.rb +++ b/rswag-ui/spec/spec_helper.rb @@ -0,0 +1,16 @@ +require 'bundler/setup' + +require 'rack' +require 'rswag/ui/configuration' + +RSpec.configure do |config| + # Enable flags like --only-failures and --next-failure + config.example_status_persistence_file_path = ".rspec_status" + + # Disable RSpec exposing methods globally on `Module` and `main` + config.disable_monkey_patching! + + config.expect_with :rspec do |c| + c.syntax = :expect + end +end