mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 07:16:40 +00:00
allow headers to be set in the configuration of rswag-api
This commit is contained in:
17
README.md
17
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
|
||||
@@ -466,6 +466,19 @@ end
|
||||
|
||||
Note how the filter is passed the rack env for the current request. This provides a lot of flexibilty. For example, you can assign the "host" property (as shown) or you could inspect session information or an Authoriation header and remove operations based on user permissions.
|
||||
|
||||
### Custom Headers for Swagger Files ###
|
||||
|
||||
You can specify custom headers for serving your generated Swagger JSON. For example you may want to force a specific charset for the 'Content-Type' header. You can configure a hash of headers to be sent with the request:
|
||||
|
||||
```ruby
|
||||
Rswag::Api.configure do |c|
|
||||
...
|
||||
|
||||
c.swagger_headers = { 'Content-Type' => 'application/json; charset=UTF-8' }
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
### Enable Swagger Endpoints for swagger-ui ###
|
||||
|
||||
You can update the _rswag-ui.rb_ initializer, installed with rswag-ui, to specify which Swagger endpoints should be available to power the documentation UI. If you're using rswag-api, these should correspond to the Swagger endpoints it exposes. When the UI is rendered, you'll see these listed in a drop-down to the top right of the page:
|
||||
|
||||
Reference in New Issue
Block a user