mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 15:22:56 +00:00
Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
741f0dc240 | ||
|
|
3404fa72aa | ||
|
|
521ab14eaf | ||
|
|
8f5cb1aa12 | ||
|
|
519eb74cdd | ||
|
|
de7ec5f15d | ||
|
|
e40c5fc26e | ||
|
|
1de29136ef | ||
|
|
88449944e1 | ||
|
|
e03a6d333f | ||
|
|
215aaddb7d | ||
|
|
925b754233 | ||
|
|
69c7decce1 | ||
|
|
353be669e4 | ||
|
|
75d676d753 | ||
|
|
1b3a976313 | ||
|
|
2617fdc48d | ||
|
|
724ede0076 | ||
|
|
8aeb9a6c70 | ||
|
|
25d8adaf8b | ||
|
|
f195c82759 | ||
|
|
37f86f6d94 | ||
|
|
51c9f4e5e6 | ||
|
|
233c5cc735 | ||
|
|
cf9170101b | ||
|
|
98d5b982c4 | ||
|
|
77d4cbe0ea | ||
|
|
32a7ab8234 | ||
|
|
95b009a72f |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,3 +3,5 @@
|
|||||||
**/*/*.gem
|
**/*/*.gem
|
||||||
**/*/*.sqlite3
|
**/*/*.sqlite3
|
||||||
**/*/public/assets
|
**/*/public/assets
|
||||||
|
*.swp
|
||||||
|
Gemfile.lock
|
||||||
|
|||||||
1
.ruby-version
Normal file
1
.ruby-version
Normal file
@@ -0,0 +1 @@
|
|||||||
|
2.3.0
|
||||||
68
.travis.yml
68
.travis.yml
@@ -1,14 +1,64 @@
|
|||||||
nguage: ruby
|
language: ruby
|
||||||
|
|
||||||
rvm:
|
rvm:
|
||||||
- 2.2.5
|
- 2.2.5
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- "RAILS_VERSION=3.2.22"
|
- RAILS_VERSION=5.1.2
|
||||||
- "RAILS_VERSION=4.2.0"
|
- RAILS_VERSION=4.2.0
|
||||||
- "RAILS_VERSION=5.0.0"
|
- RAILS_VERSION=3.2.22
|
||||||
cache: bundler
|
|
||||||
install: bundle update
|
cache:
|
||||||
|
directories:
|
||||||
|
- /home/travis/.rvm/gems/ruby-2.2.5
|
||||||
|
|
||||||
|
install: bundle install
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- "export DISPLAY=:99.0"
|
- export DISPLAY=:99.0
|
||||||
- "sh -e /etc/init.d/xvfb start"
|
- sh -e /etc/init.d/xvfb start
|
||||||
- sleep 3 # give xvfb some time to start
|
- sleep 3
|
||||||
|
|
||||||
script: ./ci/test.sh
|
script: ./ci/test.sh
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
include:
|
||||||
|
- stage: publish components
|
||||||
|
script: 'cd rswag-api'
|
||||||
|
deploy:
|
||||||
|
gemspec: rswag-api.gemspec
|
||||||
|
provider: rubygems
|
||||||
|
api_key: $RUBYGEMS_API_KEY
|
||||||
|
on:
|
||||||
|
branch: master
|
||||||
|
tags: true
|
||||||
|
|
||||||
|
- stage: publish components
|
||||||
|
script: 'cd rswag-specs'
|
||||||
|
deploy:
|
||||||
|
gemspec: rswag-specs.gemspec
|
||||||
|
provider: rubygems
|
||||||
|
api_key: $RUBYGEMS_API_KEY
|
||||||
|
on:
|
||||||
|
branch: master
|
||||||
|
tags: true
|
||||||
|
|
||||||
|
- stage: publish components
|
||||||
|
script: 'cd rswag-ui'
|
||||||
|
deploy:
|
||||||
|
gemspec: rswag-ui.gemspec
|
||||||
|
provider: rubygems
|
||||||
|
api_key: $RUBYGEMS_API_KEY
|
||||||
|
on:
|
||||||
|
branch: master
|
||||||
|
tags: true
|
||||||
|
|
||||||
|
- stage: publish rswag
|
||||||
|
script: 'cd rswag'
|
||||||
|
deploy:
|
||||||
|
gemspec: rswag.gemspec
|
||||||
|
provider: rubygems
|
||||||
|
api_key: $RUBYGEMS_API_KEY
|
||||||
|
on:
|
||||||
|
branch: master
|
||||||
|
tags: true
|
||||||
|
|||||||
4
Gemfile
4
Gemfile
@@ -2,7 +2,7 @@ source "https://rubygems.org"
|
|||||||
|
|
||||||
# Allow the rails version to come from an ENV setting so Travis can test multiple versions.
|
# Allow the rails version to come from an ENV setting so Travis can test multiple versions.
|
||||||
# See http://www.schneems.com/post/50991826838/testing-against-multiple-rails-versions/
|
# See http://www.schneems.com/post/50991826838/testing-against-multiple-rails-versions/
|
||||||
rails_version = ENV['RAILS_VERSION'] || '3.2.22'
|
rails_version = ENV['RAILS_VERSION'] || '5.1.2'
|
||||||
|
|
||||||
gem 'rails', "#{rails_version}"
|
gem 'rails', "#{rails_version}"
|
||||||
|
|
||||||
@@ -15,6 +15,7 @@ end
|
|||||||
|
|
||||||
gem 'sqlite3'
|
gem 'sqlite3'
|
||||||
|
|
||||||
|
gem 'rswag-specs', path: './rswag-specs'
|
||||||
gem 'rswag-api', path: './rswag-api'
|
gem 'rswag-api', path: './rswag-api'
|
||||||
gem 'rswag-ui', path: './rswag-ui'
|
gem 'rswag-ui', path: './rswag-ui'
|
||||||
|
|
||||||
@@ -27,7 +28,6 @@ group :test do
|
|||||||
gem 'generator_spec'
|
gem 'generator_spec'
|
||||||
gem 'capybara'
|
gem 'capybara'
|
||||||
gem 'capybara-webkit'
|
gem 'capybara-webkit'
|
||||||
gem 'rswag-specs', path: './rswag-specs'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
group :assets do
|
group :assets do
|
||||||
|
|||||||
173
Gemfile.lock
173
Gemfile.lock
@@ -1,173 +0,0 @@
|
|||||||
PATH
|
|
||||||
remote: ./rswag-api
|
|
||||||
specs:
|
|
||||||
rswag-api (1.1.0)
|
|
||||||
rails (>= 3.1, < 5.1)
|
|
||||||
|
|
||||||
PATH
|
|
||||||
remote: ./rswag-specs
|
|
||||||
specs:
|
|
||||||
rswag-specs (1.1.0)
|
|
||||||
json-schema (~> 2.2)
|
|
||||||
rails (>= 3.1, < 5.1)
|
|
||||||
rspec-rails (>= 2.14, < 4)
|
|
||||||
|
|
||||||
PATH
|
|
||||||
remote: ./rswag-ui
|
|
||||||
specs:
|
|
||||||
rswag-ui (1.1.0)
|
|
||||||
rails (>= 3.1, < 5.1)
|
|
||||||
|
|
||||||
GEM
|
|
||||||
remote: https://rubygems.org/
|
|
||||||
specs:
|
|
||||||
actionmailer (3.2.22)
|
|
||||||
actionpack (= 3.2.22)
|
|
||||||
mail (~> 2.5.4)
|
|
||||||
actionpack (3.2.22)
|
|
||||||
activemodel (= 3.2.22)
|
|
||||||
activesupport (= 3.2.22)
|
|
||||||
builder (~> 3.0.0)
|
|
||||||
erubis (~> 2.7.0)
|
|
||||||
journey (~> 1.0.4)
|
|
||||||
rack (~> 1.4.5)
|
|
||||||
rack-cache (~> 1.2)
|
|
||||||
rack-test (~> 0.6.1)
|
|
||||||
sprockets (~> 2.2.1)
|
|
||||||
activemodel (3.2.22)
|
|
||||||
activesupport (= 3.2.22)
|
|
||||||
builder (~> 3.0.0)
|
|
||||||
activerecord (3.2.22)
|
|
||||||
activemodel (= 3.2.22)
|
|
||||||
activesupport (= 3.2.22)
|
|
||||||
arel (~> 3.0.2)
|
|
||||||
tzinfo (~> 0.3.29)
|
|
||||||
activeresource (3.2.22)
|
|
||||||
activemodel (= 3.2.22)
|
|
||||||
activesupport (= 3.2.22)
|
|
||||||
activesupport (3.2.22)
|
|
||||||
i18n (~> 0.6, >= 0.6.4)
|
|
||||||
multi_json (~> 1.0)
|
|
||||||
addressable (2.4.0)
|
|
||||||
arel (3.0.3)
|
|
||||||
builder (3.0.4)
|
|
||||||
capybara (2.10.1)
|
|
||||||
addressable
|
|
||||||
mime-types (>= 1.16)
|
|
||||||
nokogiri (>= 1.3.3)
|
|
||||||
rack (>= 1.0.0)
|
|
||||||
rack-test (>= 0.5.4)
|
|
||||||
xpath (~> 2.0)
|
|
||||||
capybara-webkit (1.1.0)
|
|
||||||
capybara (~> 2.0, >= 2.0.2)
|
|
||||||
json
|
|
||||||
diff-lcs (1.2.5)
|
|
||||||
erubis (2.7.0)
|
|
||||||
execjs (2.7.0)
|
|
||||||
generator_spec (0.9.3)
|
|
||||||
activesupport (>= 3.0.0)
|
|
||||||
railties (>= 3.0.0)
|
|
||||||
hike (1.2.3)
|
|
||||||
i18n (0.7.0)
|
|
||||||
journey (1.0.4)
|
|
||||||
json (1.8.3)
|
|
||||||
json-schema (2.7.0)
|
|
||||||
addressable (>= 2.4)
|
|
||||||
libv8 (3.16.14.15)
|
|
||||||
mail (2.5.4)
|
|
||||||
mime-types (~> 1.16)
|
|
||||||
treetop (~> 1.4.8)
|
|
||||||
mime-types (1.25.1)
|
|
||||||
mini_portile2 (2.1.0)
|
|
||||||
multi_json (1.12.1)
|
|
||||||
nokogiri (1.6.8.1)
|
|
||||||
mini_portile2 (~> 2.1.0)
|
|
||||||
polyglot (0.3.5)
|
|
||||||
power_assert (0.3.1)
|
|
||||||
rack (1.4.7)
|
|
||||||
rack-cache (1.6.1)
|
|
||||||
rack (>= 0.4)
|
|
||||||
rack-ssl (1.3.4)
|
|
||||||
rack
|
|
||||||
rack-test (0.6.3)
|
|
||||||
rack (>= 1.0)
|
|
||||||
rails (3.2.22)
|
|
||||||
actionmailer (= 3.2.22)
|
|
||||||
actionpack (= 3.2.22)
|
|
||||||
activerecord (= 3.2.22)
|
|
||||||
activeresource (= 3.2.22)
|
|
||||||
activesupport (= 3.2.22)
|
|
||||||
bundler (~> 1.0)
|
|
||||||
railties (= 3.2.22)
|
|
||||||
railties (3.2.22)
|
|
||||||
actionpack (= 3.2.22)
|
|
||||||
activesupport (= 3.2.22)
|
|
||||||
rack-ssl (~> 1.3.2)
|
|
||||||
rake (>= 0.8.7)
|
|
||||||
rdoc (~> 3.4)
|
|
||||||
thor (>= 0.14.6, < 2.0)
|
|
||||||
rake (11.3.0)
|
|
||||||
rdoc (3.12.2)
|
|
||||||
json (~> 1.4)
|
|
||||||
ref (2.0.0)
|
|
||||||
rspec-core (3.5.4)
|
|
||||||
rspec-support (~> 3.5.0)
|
|
||||||
rspec-expectations (3.5.0)
|
|
||||||
diff-lcs (>= 1.2.0, < 2.0)
|
|
||||||
rspec-support (~> 3.5.0)
|
|
||||||
rspec-mocks (3.5.0)
|
|
||||||
diff-lcs (>= 1.2.0, < 2.0)
|
|
||||||
rspec-support (~> 3.5.0)
|
|
||||||
rspec-rails (3.5.2)
|
|
||||||
actionpack (>= 3.0)
|
|
||||||
activesupport (>= 3.0)
|
|
||||||
railties (>= 3.0)
|
|
||||||
rspec-core (~> 3.5.0)
|
|
||||||
rspec-expectations (~> 3.5.0)
|
|
||||||
rspec-mocks (~> 3.5.0)
|
|
||||||
rspec-support (~> 3.5.0)
|
|
||||||
rspec-support (3.5.0)
|
|
||||||
sprockets (2.2.3)
|
|
||||||
hike (~> 1.2)
|
|
||||||
multi_json (~> 1.0)
|
|
||||||
rack (~> 1.0)
|
|
||||||
tilt (~> 1.1, != 1.3.0)
|
|
||||||
sqlite3 (1.3.12)
|
|
||||||
strong_parameters (0.2.3)
|
|
||||||
actionpack (~> 3.0)
|
|
||||||
activemodel (~> 3.0)
|
|
||||||
activesupport (~> 3.0)
|
|
||||||
railties (~> 3.0)
|
|
||||||
test-unit (3.2.1)
|
|
||||||
power_assert
|
|
||||||
therubyracer (0.12.2)
|
|
||||||
libv8 (~> 3.16.14.0)
|
|
||||||
ref
|
|
||||||
thor (0.19.1)
|
|
||||||
tilt (1.4.1)
|
|
||||||
treetop (1.4.15)
|
|
||||||
polyglot
|
|
||||||
polyglot (>= 0.3.1)
|
|
||||||
tzinfo (0.3.51)
|
|
||||||
uglifier (3.0.2)
|
|
||||||
execjs (>= 0.3.0, < 3)
|
|
||||||
xpath (2.0.0)
|
|
||||||
nokogiri (~> 1.3)
|
|
||||||
|
|
||||||
PLATFORMS
|
|
||||||
ruby
|
|
||||||
|
|
||||||
DEPENDENCIES
|
|
||||||
capybara
|
|
||||||
capybara-webkit
|
|
||||||
generator_spec
|
|
||||||
rails (= 3.2.22)
|
|
||||||
rspec-rails
|
|
||||||
rswag-api!
|
|
||||||
rswag-specs!
|
|
||||||
rswag-ui!
|
|
||||||
sqlite3
|
|
||||||
strong_parameters
|
|
||||||
test-unit
|
|
||||||
therubyracer
|
|
||||||
uglifier
|
|
||||||
106
README.md
106
README.md
@@ -103,6 +103,17 @@ If you've used [Swagger](http://swagger.io/specification) before, then the synta
|
|||||||
|
|
||||||
Take special note of the __run_test!__ method that's called within each response block. This tells rswag to create and execute a corresponding example. It builds and submits a request based on parameter descriptions and corresponding values that have been provided using the rspec "let" syntax. For example, the "post" description in the example above specifies a "body" parameter called "blog". It also lists 2 different responses. For the success case (i.e. the 201 response), notice how "let" is used to set the blog parameter to a value that matches the provided schema. For the failure case (i.e. the 422 response), notice how it's set to a value that does not match the provided schema. When the test is executed, rswag also validates the actual response code and, where applicable, the response body against the provided [JSON Schema](http://json-schema.org/documentation.html).
|
Take special note of the __run_test!__ method that's called within each response block. This tells rswag to create and execute a corresponding example. It builds and submits a request based on parameter descriptions and corresponding values that have been provided using the rspec "let" syntax. For example, the "post" description in the example above specifies a "body" parameter called "blog". It also lists 2 different responses. For the success case (i.e. the 201 response), notice how "let" is used to set the blog parameter to a value that matches the provided schema. For the failure case (i.e. the 422 response), notice how it's set to a value that does not match the provided schema. When the test is executed, rswag also validates the actual response code and, where applicable, the response body against the provided [JSON Schema](http://json-schema.org/documentation.html).
|
||||||
|
|
||||||
|
If you want to do additional validation on the response, pass a block to the __run_test!__ method:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
response '201', 'blog created' do
|
||||||
|
run_test! do |response|
|
||||||
|
data = JSON.parse(response.body)
|
||||||
|
expect(data['title']).to eq('foo')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
If you'd like your specs to be a little more explicit about what's going on here, you can replace the call to __run_test!__ with equivalent "before" and "it" blocks:
|
If you'd like your specs to be a little more explicit about what's going on here, you can replace the call to __run_test!__ with equivalent "before" and "it" blocks:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
@@ -119,6 +130,31 @@ response '201', 'blog created' do
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Null Values ###
|
||||||
|
|
||||||
|
This library is currently using JSON::Draft4 for validation of response models. It does not support null as a value. So you can add the property 'x-nullable' to a definition to allow null/nil values to pass.
|
||||||
|
```ruby
|
||||||
|
describe 'Blogs API' do
|
||||||
|
path '/blogs' do
|
||||||
|
post 'Creates a blog' do
|
||||||
|
...
|
||||||
|
|
||||||
|
response '200', 'blog found' do
|
||||||
|
schema type: :object,
|
||||||
|
properties: {
|
||||||
|
id: { type: :integer },
|
||||||
|
title: { type: :string },
|
||||||
|
content: { type: :string, 'x-nullable': true }
|
||||||
|
}
|
||||||
|
....
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
*Note:* the OAI v3 may be released soon(ish?) and include a nullable property. This may have an effect on the need/use of custom extension to the draft. Do not use this property if you don't understand the implications.
|
||||||
|
<https://github.com/OAI/OpenAPI-Specification/issues/229#issuecomment-280376087>
|
||||||
|
|
||||||
### Global Metadata ###
|
### Global Metadata ###
|
||||||
|
|
||||||
In addition to paths, operations and responses, Swagger also supports global API metadata. When you install rswag, a file called _swagger_helper.rb_ is added to your spec folder. This is where you define one or more Swagger documents and provide global metadata. Again, the format is based on Swagger so most of the global fields supported by the top level ["Swagger" object](http://swagger.io/specification/#swaggerObject) can be provided with each document definition. As an example, you could define a Swagger document for each version of your API and in each case specify a title, version string and URL basePath:
|
In addition to paths, operations and responses, Swagger also supports global API metadata. When you install rswag, a file called _swagger_helper.rb_ is added to your spec folder. This is where you define one or more Swagger documents and provide global metadata. Again, the format is based on Swagger so most of the global fields supported by the top level ["Swagger" object](http://swagger.io/specification/#swaggerObject) can be provided with each document definition. As an example, you could define a Swagger document for each version of your API and in each case specify a title, version string and URL basePath:
|
||||||
@@ -164,6 +200,58 @@ describe 'Blogs API', swagger_doc: 'v2/swagger.json' do
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Specifying/Testing API Security ###
|
||||||
|
|
||||||
|
Swagger allows for the specification of different security schemes and their applicability to operations in an API. To leverage this in rswag, you define the schemes globally in _swagger_helper.rb_ and then use the "security" attribute at the operation level to specify which schemes, if any, are applicable to that operation. Swagger supports :basic, :apiKey and :oauth2 scheme types. See [the spec](http://swagger.io/specification/#security-definitions-object-109) for more info.
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
# spec/swagger_helper.rb
|
||||||
|
RSpec.configure do |config|
|
||||||
|
config.swagger_root = Rails.root.to_s + '/swagger'
|
||||||
|
|
||||||
|
config.swagger_docs = {
|
||||||
|
'v1/swagger.json' => {
|
||||||
|
...
|
||||||
|
securityDefinitions: {
|
||||||
|
basic: {
|
||||||
|
type: :basic
|
||||||
|
},
|
||||||
|
apiKey: {
|
||||||
|
type: :apiKey,
|
||||||
|
name: 'api_key',
|
||||||
|
in: :query
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
# spec/integration/blogs_spec.rb
|
||||||
|
describe 'Blogs API' do
|
||||||
|
|
||||||
|
path '/blogs' do
|
||||||
|
|
||||||
|
post 'Creates a blog' do
|
||||||
|
tags 'Blogs'
|
||||||
|
security [ basic: [] ]
|
||||||
|
...
|
||||||
|
|
||||||
|
response '201', 'blog created' do
|
||||||
|
let(:Authorization) { "Basic #{::Base64.strict_encode64('jsmith:jspass')}" }
|
||||||
|
run_test!
|
||||||
|
end
|
||||||
|
|
||||||
|
response '401', 'authentication failed' do
|
||||||
|
let(:Authorization) { "Basic #{::Base64.strict_encode64('bogus:bogus')}" }
|
||||||
|
run_test!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
__NOTE:__ Depending on the scheme types, you'll be required to assign a corresponding parameter value with each example. For example, :basic auth is required above and so the :Authorization (header) parameter must be set accordingly
|
||||||
|
|
||||||
## Configuration & Customization ##
|
## Configuration & Customization ##
|
||||||
|
|
||||||
The steps described above will get you up and running with minimal setup. However, rswag offers a lot of flexibility to customize as you see fit. Before exploring the various options, you'll need to be aware of it's different components. The following table lists each of them and the files that get added/updated as part of a standard install.
|
The steps described above will get you up and running with minimal setup. However, rswag offers a lot of flexibility to customize as you see fit. Before exploring the various options, you'll need to be aware of it's different components. The following table lists each of them and the files that get added/updated as part of a standard install.
|
||||||
@@ -284,6 +372,22 @@ describe 'Blogs API' do
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Enable generation examples from responses ###
|
||||||
|
|
||||||
|
To enable examples generation from responses add callback above run_test! like:
|
||||||
|
```ruby
|
||||||
|
after do |example|
|
||||||
|
example.metadata[:response][:examples] = { 'application/json' => JSON.parse(response.body, symbolize_names: true) }
|
||||||
|
end
|
||||||
|
```
|
||||||
|
You need to disable --dry-run option for Rspec > 3
|
||||||
|
|
||||||
|
Add to application.rb:
|
||||||
|
```ruby
|
||||||
|
RSpec.configure do |config|
|
||||||
|
config.swagger_dry_run = false
|
||||||
|
end
|
||||||
|
```
|
||||||
### Route Prefix for Swagger JSON Endpoints ###
|
### Route Prefix for Swagger JSON Endpoints ###
|
||||||
|
|
||||||
The functionality to expose Swagger files, such as those generated by rswag-specs, as JSON endpoints is implemented as a Rails Engine. As with any Engine, you can change it's mount prefix in _routes.rb_:
|
The functionality to expose Swagger files, such as those generated by rswag-specs, as JSON endpoints is implemented as a Rails Engine. As with any Engine, you can change it's mount prefix in _routes.rb_:
|
||||||
@@ -355,7 +459,7 @@ end
|
|||||||
|
|
||||||
### Customizing the swagger-ui ###
|
### Customizing the swagger-ui ###
|
||||||
|
|
||||||
The swagger-ui provides several options for customizing it's behavior, all of which are documented here https://github.com/swagger-api/swagger-ui#swaggerui. If you need to tweak these or customize the overall look and feel of your swagger-ui, then you'll need to provide your own version of index.html. You can do this with the following generator.
|
The swagger-ui provides several options for customizing it's behavior, all of which are documented here https://github.com/swagger-api/swagger-ui/tree/2.x#swaggerui. If you need to tweak these or customize the overall look and feel of your swagger-ui, then you'll need to provide your own version of index.html. You can do this with the following generator.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
rails g rswag:ui:custom
|
rails g rswag:ui:custom
|
||||||
|
|||||||
58
ci/deploy.sh
58
ci/deploy.sh
@@ -1,58 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
ROOT_PATH=$PWD
|
|
||||||
set -e # abort if anything fails
|
|
||||||
|
|
||||||
bundle check || bundle
|
|
||||||
|
|
||||||
echo '####################'
|
|
||||||
echo 'Build Gems'
|
|
||||||
echo '####################'
|
|
||||||
echo ''
|
|
||||||
|
|
||||||
echo '##### rswag-api #####'
|
|
||||||
cd $ROOT_PATH/rswag-api
|
|
||||||
gem build rswag-api.gemspec
|
|
||||||
|
|
||||||
echo '##### rswag-specs #####'
|
|
||||||
cd $ROOT_PATH/rswag-specs
|
|
||||||
gem build rswag-specs.gemspec
|
|
||||||
|
|
||||||
echo '##### rswag-ui #####'
|
|
||||||
cd $ROOT_PATH/rswag-ui
|
|
||||||
gem build rswag-ui.gemspec
|
|
||||||
|
|
||||||
echo '##### rswag #####'
|
|
||||||
cd $ROOT_PATH/rswag
|
|
||||||
gem build rswag.gemspec
|
|
||||||
|
|
||||||
echo '####################'
|
|
||||||
echo 'Push to RubyGems'
|
|
||||||
echo '####################'
|
|
||||||
echo ''
|
|
||||||
|
|
||||||
echo 'Type the version no, followed by [ENTER]:'
|
|
||||||
read version
|
|
||||||
|
|
||||||
echo '##### rswag-api #####'
|
|
||||||
cd $ROOT_PATH/rswag-api
|
|
||||||
gem push rswag-api-$version.gem
|
|
||||||
|
|
||||||
echo '##### rswag-specs #####'
|
|
||||||
cd $ROOT_PATH/rswag-specs
|
|
||||||
gem push rswag-specs-$version.gem
|
|
||||||
|
|
||||||
echo '##### rswag-ui #####'
|
|
||||||
cd $ROOT_PATH/rswag-ui
|
|
||||||
gem push rswag-ui-$version.gem
|
|
||||||
|
|
||||||
echo '##### rswag #####'
|
|
||||||
cd $ROOT_PATH/rswag
|
|
||||||
gem push rswag-$version.gem
|
|
||||||
|
|
||||||
# Cleanup
|
|
||||||
cd $ROOT_PATH
|
|
||||||
|
|
||||||
# Create git tag
|
|
||||||
git tag v$version
|
|
||||||
git push origin v$version
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
require 'rswag/api/version'
|
|
||||||
require 'rswag/api/configuration'
|
require 'rswag/api/configuration'
|
||||||
require 'rswag/api/engine'
|
require 'rswag/api/engine'
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
module Rswag
|
|
||||||
module Api
|
|
||||||
VERSION = '1.1.0'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
$:.push File.expand_path("../lib", __FILE__)
|
$:.push File.expand_path("../lib", __FILE__)
|
||||||
|
|
||||||
# Maintain your gem's version:
|
|
||||||
require 'rswag/api/version'
|
|
||||||
|
|
||||||
# Describe your gem and declare its dependencies:
|
# Describe your gem and declare its dependencies:
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = "rswag-api"
|
s.name = "rswag-api"
|
||||||
s.version = Rswag::Api::VERSION
|
s.version = ENV['TRAVIS_TAG'] || '0.0.0'
|
||||||
s.authors = ["Richie Morris"]
|
s.authors = ["Richie Morris"]
|
||||||
s.email = ["domaindrivendev@gmail.com"]
|
s.email = ["domaindrivendev@gmail.com"]
|
||||||
s.homepage = "https://github.com/domaindrivendev/rswag"
|
s.homepage = "https://github.com/domaindrivendev/rswag"
|
||||||
@@ -14,7 +11,7 @@ Gem::Specification.new do |s|
|
|||||||
s.description = "Open up your API to the phenomenal Swagger ecosystem by exposing Swagger files, that describe your service, as JSON endpoints"
|
s.description = "Open up your API to the phenomenal Swagger ecosystem by exposing Swagger files, that describe your service, as JSON endpoints"
|
||||||
s.license = "MIT"
|
s.license = "MIT"
|
||||||
|
|
||||||
s.files = Dir["{lib}/**/*"] + ["MIT-LICENSE", "Rakefile" ]
|
s.files = Dir["{lib}/**/*"] + ["MIT-LICENSE", "Rakefile"]
|
||||||
|
|
||||||
s.add_dependency "rails", ">= 3.1", "< 5.1"
|
s.add_dependency 'railties', '>= 3.1', '< 6.0'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
require 'rspec/core'
|
require 'rspec/core'
|
||||||
require 'rswag/specs/version'
|
|
||||||
require 'rswag/specs/example_group_helpers'
|
require 'rswag/specs/example_group_helpers'
|
||||||
require 'rswag/specs/example_helpers'
|
require 'rswag/specs/example_helpers'
|
||||||
require 'rswag/specs/configuration'
|
require 'rswag/specs/configuration'
|
||||||
@@ -12,6 +11,7 @@ module Rswag
|
|||||||
::RSpec.configure do |c|
|
::RSpec.configure do |c|
|
||||||
c.add_setting :swagger_root
|
c.add_setting :swagger_root
|
||||||
c.add_setting :swagger_docs
|
c.add_setting :swagger_docs
|
||||||
|
c.add_setting :swagger_dry_run
|
||||||
c.extend ExampleGroupHelpers, type: :request
|
c.extend ExampleGroupHelpers, type: :request
|
||||||
c.include ExampleHelpers, type: :request
|
c.include ExampleHelpers, type: :request
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,6 +25,12 @@ module Rswag
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def swagger_dry_run
|
||||||
|
@swagger_dry_run ||= begin
|
||||||
|
@rspec_config.swagger_dry_run.nil? || @rspec_config.swagger_dry_run
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def get_swagger_doc(name)
|
def get_swagger_doc(name)
|
||||||
return swagger_docs.values.first if name.nil?
|
return swagger_docs.values.first if name.nil?
|
||||||
raise ConfigurationError, "Unknown swagger_doc '#{name}'" unless swagger_docs[name]
|
raise ConfigurationError, "Unknown swagger_doc '#{name}'" unless swagger_docs[name]
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ module Rswag
|
|||||||
metadata[:response][:examples] = example
|
metadata[:response][:examples] = example
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_test!
|
def run_test!(&block)
|
||||||
# NOTE: rspec 2.x support
|
# NOTE: rspec 2.x support
|
||||||
if RSPEC_VERSION < 3
|
if RSPEC_VERSION < 3
|
||||||
before do
|
before do
|
||||||
@@ -77,7 +77,7 @@ module Rswag
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "returns a #{metadata[:response][:code]} response" do
|
it "returns a #{metadata[:response][:code]} response" do
|
||||||
assert_response_matches_metadata(example.metadata)
|
assert_response_matches_metadata(example.metadata, &block)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
before do |example|
|
before do |example|
|
||||||
@@ -85,7 +85,7 @@ module Rswag
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "returns a #{metadata[:response][:code]} response" do |example|
|
it "returns a #{metadata[:response][:code]} response" do |example|
|
||||||
assert_response_matches_metadata(example.metadata)
|
assert_response_matches_metadata(example.metadata, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ module Rswag
|
|||||||
api_metadata[:operation][:verb],
|
api_metadata[:operation][:verb],
|
||||||
factory.build_fullpath(self),
|
factory.build_fullpath(self),
|
||||||
factory.build_body(self),
|
factory.build_body(self),
|
||||||
factory.build_headers(self)
|
rackify_headers(factory.build_headers(self)) # Rails test infrastructure requires Rack headers
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
send(
|
send(
|
||||||
@@ -28,14 +28,30 @@ module Rswag
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_response_matches_metadata(api_metadata)
|
def assert_response_matches_metadata(api_metadata, &block)
|
||||||
global_metadata = rswag_config.get_swagger_doc(api_metadata[:swagger_doc])
|
global_metadata = rswag_config.get_swagger_doc(api_metadata[:swagger_doc])
|
||||||
validator = ResponseValidator.new(api_metadata, global_metadata)
|
validator = ResponseValidator.new(api_metadata, global_metadata)
|
||||||
validator.validate!(response)
|
validator.validate!(response, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def rackify_headers(headers)
|
||||||
|
name_value_pairs = headers.map do |name, value|
|
||||||
|
[
|
||||||
|
case name
|
||||||
|
when 'Accept' then 'HTTP_ACCEPT'
|
||||||
|
when 'Content-Type' then 'CONTENT_TYPE'
|
||||||
|
when 'Authorization' then 'HTTP_AUTHORIZATION'
|
||||||
|
else name
|
||||||
|
end,
|
||||||
|
value
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
Hash[ name_value_pairs ]
|
||||||
|
end
|
||||||
|
|
||||||
def rswag_config
|
def rswag_config
|
||||||
::Rswag::Specs.config
|
::Rswag::Specs.config
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,18 +2,18 @@ require 'json-schema'
|
|||||||
|
|
||||||
module Rswag
|
module Rswag
|
||||||
module Specs
|
module Specs
|
||||||
class ExtendedSchema < JSON::Schema::Validator
|
class ExtendedSchema < JSON::Schema::Draft4
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
extend_schema_definition("http://json-schema.org/draft-04/schema#")
|
|
||||||
@attributes['type'] = ExtendedTypeAttribute
|
@attributes['type'] = ExtendedTypeAttribute
|
||||||
@uri = URI.parse('http://tempuri.org/rswag/specs/extended_schema')
|
@uri = URI.parse('http://tempuri.org/rswag/specs/extended_schema')
|
||||||
|
@names = ['http://tempuri.org/rswag/specs/extended_schema']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ExtendedTypeAttribute < JSON::Schema::TypeV4Attribute
|
class ExtendedTypeAttribute < JSON::Schema::TypeV4Attribute
|
||||||
|
|
||||||
def self.validate(current_schema, data, fragments, processor, validator, options={})
|
def self.validate(current_schema, data, fragments, processor, validator, options={})
|
||||||
return if data.nil? && current_schema.schema['x-nullable'] == true
|
return if data.nil? && current_schema.schema['x-nullable'] == true
|
||||||
super
|
super
|
||||||
|
|||||||
@@ -32,13 +32,20 @@ module Rswag
|
|||||||
end
|
end
|
||||||
|
|
||||||
def build_headers(example)
|
def build_headers(example)
|
||||||
headers = Hash[ parameters_in(:header).map { |p| [ p[:name], example.send(p[:name]).to_s ] } ]
|
name_value_pairs = parameters_in(:header).map do |param|
|
||||||
headers.tap do |h|
|
[
|
||||||
produces = @api_metadata[:operation][:produces] || @global_metadata[:produces]
|
param[:name],
|
||||||
consumes = @api_metadata[:operation][:consumes] || @global_metadata[:consumes]
|
example.send(param[:name]).to_s
|
||||||
h['ACCEPT'] = produces.join(';') unless produces.nil?
|
]
|
||||||
h['CONTENT_TYPE'] = consumes.join(';') unless consumes.nil?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Add MIME type headers based on produces/consumes metadata
|
||||||
|
produces = @api_metadata[:operation][:produces] || @global_metadata[:produces]
|
||||||
|
consumes = @api_metadata[:operation][:consumes] || @global_metadata[:consumes]
|
||||||
|
name_value_pairs << [ 'Accept', produces.join(';') ] unless produces.nil?
|
||||||
|
name_value_pairs << [ 'Content-Type', consumes.join(';') ] unless consumes.nil?
|
||||||
|
|
||||||
|
Hash[ name_value_pairs ]
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -52,42 +59,48 @@ module Rswag
|
|||||||
|
|
||||||
applicable_params
|
applicable_params
|
||||||
.map { |p| p['$ref'] ? resolve_parameter(p['$ref']) : p } # resolve any references
|
.map { |p| p['$ref'] ? resolve_parameter(p['$ref']) : p } # resolve any references
|
||||||
.concat(resolve_api_key_parameters)
|
.concat(security_parameters)
|
||||||
.select { |p| p[:in] == location }
|
.select { |p| p[:in] == location }
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolve_parameter(ref)
|
def resolve_parameter(ref)
|
||||||
defined_params = @global_metadata[:parameters]
|
defined_params = @global_metadata[:parameters]
|
||||||
key = ref.sub('#/parameters/', '')
|
key = ref.sub('#/parameters/', '')
|
||||||
raise "Referenced parameter '#{ref}' must be defined" unless defined_params && defined_params[key]
|
raise "Referenced parameter '#{ref}' must be defined" unless defined_params && defined_params[key]
|
||||||
defined_params[key]
|
defined_params[key]
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolve_api_key_parameters
|
def security_parameters
|
||||||
@api_key_params ||= begin
|
applicable_security_schemes.map do |scheme|
|
||||||
# First figure out the security requirement applicable to the operation
|
if scheme[:type] == :apiKey
|
||||||
global_requirements = (@global_metadata[:security] || [] ).map { |r| r.keys.first }
|
{ name: scheme[:name], type: :string, in: scheme[:in] }
|
||||||
operation_requirements = (@api_metadata[:operation][:security] || [] ).map { |r| r.keys.first }
|
else
|
||||||
requirements = global_requirements | operation_requirements
|
{ name: 'Authorization', type: :string, in: :header } # use auth header for basic & oauth2
|
||||||
|
end
|
||||||
# Then obtain the scheme definitions for those requirements
|
|
||||||
definitions = (@global_metadata[:securityDefinitions] || {}).slice(*requirements)
|
|
||||||
definitions.values.select { |d| d[:type] == :apiKey }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def applicable_security_schemes
|
||||||
|
# First figure out the security requirement applicable to the operation
|
||||||
|
requirements = @api_metadata[:operation][:security] || @global_metadata[:security]
|
||||||
|
scheme_names = requirements ? requirements.map { |r| r.keys.first } : []
|
||||||
|
|
||||||
|
# Then obtain the scheme definitions for those requirements
|
||||||
|
(@global_metadata[:securityDefinitions] || {}).slice(*scheme_names).values
|
||||||
|
end
|
||||||
|
|
||||||
def build_query_string_part(param, value)
|
def build_query_string_part(param, value)
|
||||||
return "#{param[:name]}=#{value.to_s}" unless param[:type].to_sym == :array
|
return "#{param[:name]}=#{value.to_s}" unless param[:type].to_sym == :array
|
||||||
|
|
||||||
name = param[:name]
|
name = param[:name]
|
||||||
case param[:collectionFormat]
|
case param[:collectionFormat]
|
||||||
when :ssv
|
when :ssv
|
||||||
"#{name}=#{value.join(' ')}"
|
"#{name}=#{value.join(' ')}"
|
||||||
when :tsv
|
when :tsv
|
||||||
"#{name}=#{value.join('\t')}"
|
"#{name}=#{value.join('\t')}"
|
||||||
when :pipes
|
when :pipes
|
||||||
"#{name}=#{value.join('|')}"
|
"#{name}=#{value.join('|')}"
|
||||||
when :multi
|
when :multi
|
||||||
value.map { |v| "#{name}=#{v}" }.join('&')
|
value.map { |v| "#{name}=#{v}" }.join('&')
|
||||||
else
|
else
|
||||||
"#{name}=#{value.join(',')}" # csv is default
|
"#{name}=#{value.join(',')}" # csv is default
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
require 'active_support/core_ext/hash/slice'
|
require 'active_support/core_ext/hash/slice'
|
||||||
require 'json-schema'
|
require 'json-schema'
|
||||||
|
require 'json'
|
||||||
require 'rswag/specs/extended_schema'
|
require 'rswag/specs/extended_schema'
|
||||||
|
|
||||||
module Rswag
|
module Rswag
|
||||||
@@ -11,10 +12,11 @@ module Rswag
|
|||||||
@global_metadata = global_metadata
|
@global_metadata = global_metadata
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate!(response)
|
def validate!(response, &block)
|
||||||
validate_code!(response.code)
|
validate_code!(response.code)
|
||||||
validate_headers!(response.headers)
|
validate_headers!(response.headers)
|
||||||
validate_body!(response.body)
|
validate_body!(response.body, &block)
|
||||||
|
block.call(response) if block_given?
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
module Rswag
|
|
||||||
module Specs
|
|
||||||
VERSION = '1.1.0'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -8,7 +8,7 @@ namespace :rswag do
|
|||||||
t.pattern = 'spec/requests/**/*_spec.rb, spec/api/**/*_spec.rb, spec/integration/**/*_spec.rb'
|
t.pattern = 'spec/requests/**/*_spec.rb, spec/api/**/*_spec.rb, spec/integration/**/*_spec.rb'
|
||||||
|
|
||||||
# NOTE: rspec 2.x support
|
# NOTE: rspec 2.x support
|
||||||
if Rswag::Specs::RSPEC_VERSION > 2
|
if Rswag::Specs::RSPEC_VERSION > 2 && Rswag::Specs.config.swagger_dry_run
|
||||||
t.rspec_opts = [ '--format Rswag::Specs::SwaggerFormatter', '--dry-run', '--order defined' ]
|
t.rspec_opts = [ '--format Rswag::Specs::SwaggerFormatter', '--dry-run', '--order defined' ]
|
||||||
else
|
else
|
||||||
t.rspec_opts = [ '--format Rswag::Specs::SwaggerFormatter', '--order defined' ]
|
t.rspec_opts = [ '--format Rswag::Specs::SwaggerFormatter', '--order defined' ]
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
$:.push File.expand_path("../lib", __FILE__)
|
$:.push File.expand_path("../lib", __FILE__)
|
||||||
|
|
||||||
# Maintain your gem's version:
|
|
||||||
require 'rswag/specs/version'
|
|
||||||
|
|
||||||
# Describe your gem and declare its dependencies:
|
# Describe your gem and declare its dependencies:
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = "rswag-specs"
|
s.name = "rswag-specs"
|
||||||
s.version = Rswag::Specs::VERSION
|
s.version = ENV['TRAVIS_TAG'] || '0.0.0'
|
||||||
s.authors = ["Richie Morris"]
|
s.authors = ["Richie Morris"]
|
||||||
s.email = ["domaindrivendev@gmail.com"]
|
s.email = ["domaindrivendev@gmail.com"]
|
||||||
s.homepage = "https://github.com/domaindrivendev/rswag"
|
s.homepage = "https://github.com/domaindrivendev/rswag"
|
||||||
@@ -16,7 +13,7 @@ Gem::Specification.new do |s|
|
|||||||
|
|
||||||
s.files = Dir["{lib}/**/*"] + ["MIT-LICENSE", "Rakefile" ]
|
s.files = Dir["{lib}/**/*"] + ["MIT-LICENSE", "Rakefile" ]
|
||||||
|
|
||||||
s.add_dependency "rails", ">= 3.1", "< 5.1"
|
s.add_dependency 'activesupport', '>= 3.1', '< 6.0'
|
||||||
|
s.add_dependency 'railties', '>= 3.1', '< 6.0'
|
||||||
s.add_dependency 'json-schema', '~> 2.2'
|
s.add_dependency 'json-schema', '~> 2.2'
|
||||||
s.add_dependency 'rspec-rails', '>= 2.14', '< 4'
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -193,6 +193,33 @@ module Rswag
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "global definition for 'basic auth'" do
|
||||||
|
before do
|
||||||
|
global_metadata[:securityDefinitions] = { basic_auth: { type: :basic} }
|
||||||
|
allow(example).to receive(:'Authorization').and_return('Basic foobar')
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'global requirement' do
|
||||||
|
before { global_metadata[:security] = [ { basic_auth: [] } ] }
|
||||||
|
|
||||||
|
it "includes a corresponding Authorization header" do
|
||||||
|
expect(headers).to match(
|
||||||
|
'Authorization' => 'Basic foobar'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'operation-specific requirement' do
|
||||||
|
before { api_metadata[:operation][:security] = [ { basic_auth: [] } ] }
|
||||||
|
|
||||||
|
it "includes a corresponding Authorization header" do
|
||||||
|
expect(headers).to match(
|
||||||
|
'Authorization' => 'Basic foobar'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'consumes & produces' do
|
context 'consumes & produces' do
|
||||||
before do
|
before do
|
||||||
api_metadata[:operation][:consumes] = [ 'application/json', 'application/xml' ]
|
api_metadata[:operation][:consumes] = [ 'application/json', 'application/xml' ]
|
||||||
@@ -201,8 +228,8 @@ module Rswag
|
|||||||
|
|
||||||
it "includes corresponding 'Accept' & 'Content-Type' headers" do
|
it "includes corresponding 'Accept' & 'Content-Type' headers" do
|
||||||
expect(headers).to match(
|
expect(headers).to match(
|
||||||
'ACCEPT' => 'application/json;application/xml',
|
'Accept' => 'application/json;application/xml',
|
||||||
'CONTENT_TYPE' => 'application/json;application/xml'
|
'Content-Type' => 'application/json;application/xml'
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -217,8 +244,8 @@ module Rswag
|
|||||||
|
|
||||||
it "includes corresponding 'Accept' & 'Content-Type' headers" do
|
it "includes corresponding 'Accept' & 'Content-Type' headers" do
|
||||||
expect(headers).to match(
|
expect(headers).to match(
|
||||||
'ACCEPT' => 'application/json;application/xml',
|
'Accept' => 'application/json;application/xml',
|
||||||
'CONTENT_TYPE' => 'application/json;application/xml'
|
'Content-Type' => 'application/json;application/xml'
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ module Rswag
|
|||||||
api_metadata[:response][:schema] = {
|
api_metadata[:response][:schema] = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: { text: { type: 'string' } },
|
properties: { text: { type: 'string' } },
|
||||||
required: [ 'text' ]
|
required: ['text']
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -42,6 +42,25 @@ module Rswag
|
|||||||
let(:response) { OpenStruct.new(code: 200, body: "{\"foo\":\"Some comment\"}") }
|
let(:response) { OpenStruct.new(code: 200, body: "{\"foo\":\"Some comment\"}") }
|
||||||
it { expect { call }.to raise_error UnexpectedResponse }
|
it { expect { call }.to raise_error UnexpectedResponse }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "'block' provided" do
|
||||||
|
let(:call) do
|
||||||
|
subject.validate!(response) do |response|
|
||||||
|
data = JSON.parse(response.body)
|
||||||
|
expect(data['text']).to eq('Some comment')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'the block validation passes' do
|
||||||
|
let(:response) { OpenStruct.new(code: 200, body: "{\"text\":\"Some comment\"}") }
|
||||||
|
it { expect { call }.to_not raise_error }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'the block validation fails' do
|
||||||
|
let(:response) { OpenStruct.new(code: 200, body: "{\"text\":\"Some other comment\"}") }
|
||||||
|
it { expect { call }.to raise_error(RSpec::Expectations::ExpectationNotMetError) }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "referenced 'schema' provided" do
|
context "referenced 'schema' provided" do
|
||||||
@@ -51,7 +70,7 @@ module Rswag
|
|||||||
author: {
|
author: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: { name: { type: 'string' } },
|
properties: { name: { type: 'string' } },
|
||||||
required: [ 'name' ]
|
required: ['name']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
require 'rswag/ui/version'
|
|
||||||
require 'rswag/ui/configuration'
|
require 'rswag/ui/configuration'
|
||||||
require 'rswag/ui/engine'
|
require 'rswag/ui/engine'
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,14 @@ module Rswag
|
|||||||
|
|
||||||
initializer 'rswag-ui.initialize' do |app|
|
initializer 'rswag-ui.initialize' do |app|
|
||||||
if app.config.respond_to?(:assets)
|
if app.config.respond_to?(:assets)
|
||||||
app.config.assets.precompile += [ 'swagger-ui/*' ]
|
app.config.assets.precompile += [
|
||||||
|
'swagger-ui/css/*',
|
||||||
|
'swagger-ui/fonts/*',
|
||||||
|
'swagger-ui/images/*',
|
||||||
|
'swagger-ui/lang/*',
|
||||||
|
'swagger-ui/lib/*',
|
||||||
|
'swagger-ui/swagger-ui.min.js'
|
||||||
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
module Rswag
|
|
||||||
module Ui
|
|
||||||
VERSION = '1.1.0'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
$:.push File.expand_path("../lib", __FILE__)
|
$:.push File.expand_path("../lib", __FILE__)
|
||||||
|
|
||||||
# Maintain your gem's version:
|
|
||||||
require 'rswag/ui/version'
|
|
||||||
|
|
||||||
# Describe your gem and declare its dependencies:
|
# Describe your gem and declare its dependencies:
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = "rswag-ui"
|
s.name = "rswag-ui"
|
||||||
s.version = Rswag::Ui::VERSION
|
s.version = ENV['TRAVIS_TAG'] || '0.0.0'
|
||||||
s.authors = ["Richie Morris"]
|
s.authors = ["Richie Morris"]
|
||||||
s.email = ["domaindrivendev@gmail.com"]
|
s.email = ["domaindrivendev@gmail.com"]
|
||||||
s.homepage = "https://github.com/domaindrivendev/rswag"
|
s.homepage = "https://github.com/domaindrivendev/rswag"
|
||||||
@@ -16,5 +13,6 @@ Gem::Specification.new do |s|
|
|||||||
|
|
||||||
s.files = Dir["{app,config,lib,vendor}/**/*"] + ["MIT-LICENSE", "Rakefile" ]
|
s.files = Dir["{app,config,lib,vendor}/**/*"] + ["MIT-LICENSE", "Rakefile" ]
|
||||||
|
|
||||||
s.add_dependency "rails", ">= 3.1", "< 5.1"
|
s.add_dependency 'actionpack', '>=3.1', '< 6.0'
|
||||||
|
s.add_dependency 'railties', '>= 3.1', '< 6.0'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -880,7 +880,7 @@
|
|||||||
padding: 6px 8px;
|
padding: 6px 8px;
|
||||||
}
|
}
|
||||||
.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header span.response_throbber {
|
.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header span.response_throbber {
|
||||||
background-image: url('../images/throbber.gif');
|
background-image: url(<%= asset_path('swagger-ui/images/throbber.gif') %>);
|
||||||
width: 128px;
|
width: 128px;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
display: block;
|
display: block;
|
||||||
@@ -1222,7 +1222,7 @@
|
|||||||
height: 18px;
|
height: 18px;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
background: url(../images/explorer_icons.png) no-repeat;
|
background: url(<%= asset_path('swagger-ui/images/explorer_icons.png') %>) no-repeat;
|
||||||
}
|
}
|
||||||
.swagger-section .authorize__btn_operation_login {
|
.swagger-section .authorize__btn_operation_login {
|
||||||
background-position: 0 0;
|
background-position: 0 0;
|
||||||
@@ -880,7 +880,7 @@
|
|||||||
padding: 6px 8px;
|
padding: 6px 8px;
|
||||||
}
|
}
|
||||||
.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header span.response_throbber {
|
.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header span.response_throbber {
|
||||||
background-image: url('../images/throbber.gif');
|
background-image: url(<%= asset_path('swagger-ui/images/throbber.gif') %>);
|
||||||
width: 128px;
|
width: 128px;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
display: block;
|
display: block;
|
||||||
@@ -1222,7 +1222,7 @@
|
|||||||
height: 18px;
|
height: 18px;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
background: url(../images/explorer_icons.png) no-repeat;
|
background: url(<%= asset_path('swagger-ui/images/explorer_icons.png') %>) no-repeat;
|
||||||
}
|
}
|
||||||
.swagger-section .authorize__btn_operation_login {
|
.swagger-section .authorize__btn_operation_login {
|
||||||
background-position: 0 0;
|
background-position: 0 0;
|
||||||
@@ -1354,7 +1354,7 @@
|
|||||||
height: 18px;
|
height: 18px;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
background: url(../images/explorer_icons.png) no-repeat;
|
background: url(<%= asset_path('swagger-ui/images/explorer_icons.png') %>) no-repeat;
|
||||||
}
|
}
|
||||||
.swagger-section .api-ic .api_information_panel {
|
.swagger-section .api-ic .api_information_panel {
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
font-size: 1.5em;
|
font-size: 1.5em;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
background: transparent url(../images/logo.png) no-repeat left center;
|
background: transparent url(<%= asset_path('swagger-ui/images/logo.png') %>) no-repeat left center;
|
||||||
padding: 20px 0 20px 40px;
|
padding: 20px 0 20px 40px;
|
||||||
}
|
}
|
||||||
#text-head {
|
#text-head {
|
||||||
@@ -64,7 +64,7 @@ h1 {
|
|||||||
width: 1500px;
|
width: 1500px;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
background-image: url('../images/shield.png');
|
background-image: url(<%= asset_path('swagger-ui/images/shield.png') %>);
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-position: -40px -20px;
|
background-position: -40px -20px;
|
||||||
margin-bottom: 210px;
|
margin-bottom: 210px;
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
/* Google Font's Droid Sans */
|
|
||||||
@font-face {
|
|
||||||
font-family: 'Droid Sans';
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 400;
|
|
||||||
src: local('Droid Sans'), local('DroidSans'), url('../fonts/DroidSans.ttf'), format('truetype');
|
|
||||||
}
|
|
||||||
/* Google Font's Droid Sans Bold */
|
|
||||||
@font-face {
|
|
||||||
font-family: 'Droid Sans';
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 700;
|
|
||||||
src: local('Droid Sans Bold'), local('DroidSans-Bold'), url('../fonts/DroidSans-Bold.ttf'), format('truetype');
|
|
||||||
}
|
|
||||||
14
rswag-ui/vendor/assets/components/swagger-ui/css/typography.css.erb
vendored
Normal file
14
rswag-ui/vendor/assets/components/swagger-ui/css/typography.css.erb
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/* Google Font's Droid Sans */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Droid Sans';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 400;
|
||||||
|
src: local('Droid Sans'), local('DroidSans'), url(<%= asset_path('swagger-ui/fonts/DroidSans.ttf') %>), format('truetype');
|
||||||
|
}
|
||||||
|
/* Google Font's Droid Sans Bold */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Droid Sans';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 700;
|
||||||
|
src: local('Droid Sans Bold'), local('DroidSans-Bold'), url(<%= asset_path('swagger-ui/fonts/DroidSans-Bold.ttf') %>), format('truetype');
|
||||||
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
require 'rswag/version'
|
|
||||||
require 'rswag/specs'
|
require 'rswag/specs'
|
||||||
require 'rswag/api'
|
require 'rswag/api'
|
||||||
require 'rswag/ui'
|
require 'rswag/ui'
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
module Rswag
|
|
||||||
VERSION = '1.1.0'
|
|
||||||
end
|
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
$:.push File.expand_path("../lib", __FILE__)
|
$:.push File.expand_path("../lib", __FILE__)
|
||||||
|
|
||||||
# Maintain your gem's version:
|
|
||||||
require 'rswag/version'
|
|
||||||
|
|
||||||
# Describe your gem and declare its dependencies:
|
# Describe your gem and declare its dependencies:
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = "rswag"
|
s.name = "rswag"
|
||||||
s.version = Rswag::VERSION
|
s.version = ENV['TRAVIS_TAG'] || '0.0.0'
|
||||||
s.authors = ["Richie Morris"]
|
s.authors = ["Richie Morris"]
|
||||||
s.email = ["domaindrivendev@gmail.com"]
|
s.email = ["domaindrivendev@gmail.com"]
|
||||||
s.homepage = "https://github.com/domaindrivendev/rswag"
|
s.homepage = "https://github.com/domaindrivendev/rswag"
|
||||||
@@ -16,7 +13,7 @@ Gem::Specification.new do |s|
|
|||||||
|
|
||||||
s.files = Dir["{lib}/**/*"] + [ "MIT-LICENSE" ]
|
s.files = Dir["{lib}/**/*"] + [ "MIT-LICENSE" ]
|
||||||
|
|
||||||
s.add_dependency 'rswag-specs', Rswag::VERSION
|
s.add_dependency 'rswag-specs', ENV['TRAVIS_TAG'] || '0.0.0'
|
||||||
s.add_dependency 'rswag-api', Rswag::VERSION
|
s.add_dependency 'rswag-api', ENV['TRAVIS_TAG'] || '0.0.0'
|
||||||
s.add_dependency 'rswag-ui', Rswag::VERSION
|
s.add_dependency 'rswag-ui', ENV['TRAVIS_TAG'] || '0.0.0'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
# Prevent CSRF attacks by raising an exception.
|
# Prevent CSRF attacks by raising an exception.
|
||||||
# For APIs, you may want to use :null_session instead.
|
# For APIs, you may want to use :null_session instead.
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :null_session
|
||||||
|
|
||||||
wrap_parameters format: [ :json ]
|
wrap_parameters format: [ :json ]
|
||||||
end
|
end
|
||||||
|
|||||||
13
test-app/app/controllers/auth_tests_controller.rb
Normal file
13
test-app/app/controllers/auth_tests_controller.rb
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
class AuthTestsController < ApplicationController
|
||||||
|
wrap_parameters Blog
|
||||||
|
respond_to :json
|
||||||
|
|
||||||
|
# POST /auth-tests/basic
|
||||||
|
def basic
|
||||||
|
if authenticate_with_http_basic { |u, p| u == 'jsmith' && p == 'jspass' }
|
||||||
|
head :no_content
|
||||||
|
else
|
||||||
|
request_http_basic_authentication
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -5,7 +5,7 @@ class Blog < ActiveRecord::Base
|
|||||||
{
|
{
|
||||||
id: id,
|
id: id,
|
||||||
title: title,
|
title: title,
|
||||||
content: content
|
content: nil
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
gemfile = File.expand_path('../../../../Gemfile', __FILE__)
|
gemfile = File.expand_path('../../../Gemfile', __FILE__)
|
||||||
|
|
||||||
if File.exist?(gemfile)
|
if File.exist?(gemfile)
|
||||||
ENV['BUNDLE_GEMFILE'] = gemfile
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
||||||
@@ -7,4 +7,4 @@ if File.exist?(gemfile)
|
|||||||
Bundler.setup
|
Bundler.setup
|
||||||
end
|
end
|
||||||
|
|
||||||
$:.unshift File.expand_path('../../../../lib', __FILE__)
|
$:.unshift File.expand_path('../../../../lib', __FILE__)
|
||||||
|
|||||||
@@ -28,4 +28,6 @@ TestApp::Application.configure do
|
|||||||
|
|
||||||
# Expands the lines which load the assets
|
# Expands the lines which load the assets
|
||||||
config.assets.debug = true
|
config.assets.debug = true
|
||||||
|
|
||||||
|
config.eager_load = false
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
TestApp::Application.configure do
|
|
||||||
# Settings specified here will take precedence over those in config/application.rb
|
|
||||||
|
|
||||||
# Code is not reloaded between requests
|
|
||||||
config.cache_classes = true
|
|
||||||
|
|
||||||
# Full error reports are disabled and caching is turned on
|
|
||||||
config.consider_all_requests_local = false
|
|
||||||
config.action_controller.perform_caching = true
|
|
||||||
|
|
||||||
# Disable Rails's static asset server (Apache or nginx will already do this)
|
|
||||||
config.serve_static_assets = true
|
|
||||||
|
|
||||||
# Compress JavaScripts and CSS
|
|
||||||
config.assets.compress = true
|
|
||||||
|
|
||||||
# Don't fallback to assets pipeline if a precompiled asset is missed
|
|
||||||
config.assets.compile = false
|
|
||||||
|
|
||||||
# Generate digests for assets URLs
|
|
||||||
config.assets.digest = true
|
|
||||||
|
|
||||||
# Defaults to nil and saved in location specified by config.assets.prefix
|
|
||||||
# config.assets.manifest = YOUR_PATH
|
|
||||||
|
|
||||||
# Specifies the header that your server uses for sending files
|
|
||||||
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
|
|
||||||
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
|
||||||
|
|
||||||
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
|
||||||
# config.force_ssl = true
|
|
||||||
|
|
||||||
# See everything in the log (default is :info)
|
|
||||||
# config.log_level = :debug
|
|
||||||
|
|
||||||
# Prepend all log lines with the following tags
|
|
||||||
# config.log_tags = [ :subdomain, :uuid ]
|
|
||||||
|
|
||||||
# Use a different logger for distributed setups
|
|
||||||
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
|
||||||
|
|
||||||
# Use a different cache store in production
|
|
||||||
# config.cache_store = :mem_cache_store
|
|
||||||
|
|
||||||
# Enable serving of images, stylesheets, and JavaScripts from an asset server
|
|
||||||
# config.action_controller.asset_host = "http://assets.example.com"
|
|
||||||
|
|
||||||
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
|
||||||
# config.assets.precompile += %w( search.js )
|
|
||||||
|
|
||||||
# Disable delivery errors, bad email addresses will be ignored
|
|
||||||
# config.action_mailer.raise_delivery_errors = false
|
|
||||||
|
|
||||||
# Enable threaded mode
|
|
||||||
# config.threadsafe!
|
|
||||||
|
|
||||||
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
|
||||||
# the I18n.default_locale when a translation can not be found)
|
|
||||||
config.i18n.fallbacks = true
|
|
||||||
|
|
||||||
# Send deprecation notices to registered listeners
|
|
||||||
config.active_support.deprecation = :notify
|
|
||||||
|
|
||||||
# Log the query plan for queries taking more than this (works
|
|
||||||
# with SQLite, MySQL, and PostgreSQL)
|
|
||||||
# config.active_record.auto_explain_threshold_in_seconds = 0.5
|
|
||||||
end
|
|
||||||
@@ -32,4 +32,6 @@ TestApp::Application.configure do
|
|||||||
|
|
||||||
# Print deprecation notices to the stderr
|
# Print deprecation notices to the stderr
|
||||||
config.active_support.deprecation = :stderr
|
config.active_support.deprecation = :stderr
|
||||||
|
|
||||||
|
config.eager_load = false
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,3 +5,6 @@
|
|||||||
# Make sure the secret is at least 30 characters and all random,
|
# Make sure the secret is at least 30 characters and all random,
|
||||||
# no regular words or you'll be exposed to dictionary attacks.
|
# no regular words or you'll be exposed to dictionary attacks.
|
||||||
TestApp::Application.config.secret_token = '60f36cd33756d73f362053f1d45256ae50d75440b634ae73b070a6e35a2df38692f59e28e5ecbd1f9f2e850255f6d29a468bc59ac4484c2b7f0548ddbfc1b870'
|
TestApp::Application.config.secret_token = '60f36cd33756d73f362053f1d45256ae50d75440b634ae73b070a6e35a2df38692f59e28e5ecbd1f9f2e850255f6d29a468bc59ac4484c2b7f0548ddbfc1b870'
|
||||||
|
|
||||||
|
# See http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml
|
||||||
|
TestApp::Application.config.secret_key_base = 'f6a820cc8aa76094583cd68ef46a735e25e3278648086355f8bd24721f036959c728c06a28dcecfe695f17ae2db44dfa1424f22b81377f2a1496d4e19f6f7faa'
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
TestApp::Application.routes.draw do
|
TestApp::Application.routes.draw do
|
||||||
resources :blogs, defaults: { :format => :json }
|
resources :blogs, defaults: { :format => :json }
|
||||||
|
|
||||||
|
post 'auth-tests/basic', to: 'auth_tests#basic'
|
||||||
|
|
||||||
mount Rswag::Api::Engine => 'api-docs'
|
mount Rswag::Api::Engine => 'api-docs'
|
||||||
mount Rswag::Ui::Engine => 'api-docs'
|
mount Rswag::Ui::Engine => 'api-docs'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
class CreateBlogs < ActiveRecord::Migration
|
migration_class = if Gem::Version.new(Rails.version) >= Gem::Version.new("5.0")
|
||||||
|
ActiveRecord::Migration[4.2]
|
||||||
|
else
|
||||||
|
ActiveRecord::Migration
|
||||||
|
end
|
||||||
|
|
||||||
|
class CreateBlogs < migration_class
|
||||||
def change
|
def change
|
||||||
create_table :blogs do |t|
|
create_table :blogs do |t|
|
||||||
t.string :title
|
t.string :title
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
# encoding: UTF-8
|
|
||||||
# This file is auto-generated from the current state of the database. Instead
|
# This file is auto-generated from the current state of the database. Instead
|
||||||
# of editing this file, please use the migrations feature of Active Record to
|
# of editing this file, please use the migrations feature of Active Record to
|
||||||
# incrementally modify your database, and then regenerate this schema definition.
|
# incrementally modify your database, and then regenerate this schema definition.
|
||||||
@@ -9,15 +8,15 @@
|
|||||||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||||
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20160218212104) do
|
ActiveRecord::Schema.define(version: 20160218212104) do
|
||||||
|
|
||||||
create_table "blogs", :force => true do |t|
|
create_table "blogs", force: :cascade do |t|
|
||||||
t.string "title"
|
t.string "title"
|
||||||
t.text "content"
|
t.text "content"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
22
test-app/spec/integration/auth_tests_spec.rb
Normal file
22
test-app/spec/integration/auth_tests_spec.rb
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
require 'swagger_helper'
|
||||||
|
|
||||||
|
describe 'Auth Tests API', type: :request, swagger_doc: 'v1/swagger.json' do
|
||||||
|
|
||||||
|
path '/auth-tests/basic' do
|
||||||
|
post 'Authenticates with basic auth' do
|
||||||
|
tags 'Auth Test'
|
||||||
|
operationId 'testBasicAuth'
|
||||||
|
security [ basic_auth: [] ]
|
||||||
|
|
||||||
|
response '204', 'Valid credentials' do
|
||||||
|
let(:Authorization) { "Basic #{::Base64.strict_encode64('jsmith:jspass')}" }
|
||||||
|
run_test!
|
||||||
|
end
|
||||||
|
|
||||||
|
response '401', 'Invalid credentials' do
|
||||||
|
let(:Authorization) { "Basic #{::Base64.strict_encode64('foo:bar')}" }
|
||||||
|
run_test!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -39,12 +39,15 @@ RSpec.configure do |config|
|
|||||||
properties: {
|
properties: {
|
||||||
id: { type: 'integer' },
|
id: { type: 'integer' },
|
||||||
title: { type: 'string' },
|
title: { type: 'string' },
|
||||||
content: { type: 'string' }
|
content: { type: 'string', 'x-nullable': true }
|
||||||
},
|
},
|
||||||
required: [ 'id', 'title', 'content' ]
|
required: [ 'id', 'title', 'content' ]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
securityDefinitions: {
|
securityDefinitions: {
|
||||||
|
basic_auth: {
|
||||||
|
type: :basic
|
||||||
|
},
|
||||||
api_key: {
|
api_key: {
|
||||||
type: :apiKey,
|
type: :apiKey,
|
||||||
name: 'api_key',
|
name: 'api_key',
|
||||||
|
|||||||
@@ -5,6 +5,30 @@
|
|||||||
"version": "v1"
|
"version": "v1"
|
||||||
},
|
},
|
||||||
"paths": {
|
"paths": {
|
||||||
|
"/auth-tests/basic": {
|
||||||
|
"post": {
|
||||||
|
"summary": "Authenticates with basic auth",
|
||||||
|
"tags": [
|
||||||
|
"Auth Test"
|
||||||
|
],
|
||||||
|
"operationId": "testBasicAuth",
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"basic_auth": [
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"204": {
|
||||||
|
"description": "Valid credentials"
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Invalid credentials"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/blogs": {
|
"/blogs": {
|
||||||
"post": {
|
"post": {
|
||||||
"summary": "Creates a blog",
|
"summary": "Creates a blog",
|
||||||
@@ -146,7 +170,8 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"content": {
|
"content": {
|
||||||
"type": "string"
|
"type": "string",
|
||||||
|
"x-nullable": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
@@ -157,6 +182,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"securityDefinitions": {
|
"securityDefinitions": {
|
||||||
|
"basic_auth": {
|
||||||
|
"type": "basic"
|
||||||
|
},
|
||||||
"api_key": {
|
"api_key": {
|
||||||
"type": "apiKey",
|
"type": "apiKey",
|
||||||
"name": "api_key",
|
"name": "api_key",
|
||||||
|
|||||||
Reference in New Issue
Block a user