mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-22 22:06:43 +00:00
Merge branch 'master' into fixdepnotice
This commit is contained in:
commit
e03a6d333f
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
|||||||
**/*/*.gem
|
**/*/*.gem
|
||||||
**/*/*.sqlite3
|
**/*/*.sqlite3
|
||||||
**/*/public/assets
|
**/*/public/assets
|
||||||
|
*.swp
|
||||||
|
|||||||
1
.ruby-version
Normal file
1
.ruby-version
Normal file
@ -0,0 +1 @@
|
|||||||
|
2.3.0
|
||||||
@ -5,6 +5,7 @@ env:
|
|||||||
- "RAILS_VERSION=3.2.22"
|
- "RAILS_VERSION=3.2.22"
|
||||||
- "RAILS_VERSION=4.2.0"
|
- "RAILS_VERSION=4.2.0"
|
||||||
- "RAILS_VERSION=5.0.0"
|
- "RAILS_VERSION=5.0.0"
|
||||||
|
- "RAILS_VERSION=5.1.1"
|
||||||
cache: bundler
|
cache: bundler
|
||||||
install: bundle update
|
install: bundle update
|
||||||
before_script:
|
before_script:
|
||||||
|
|||||||
2
Gemfile
2
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.1'
|
||||||
|
|
||||||
gem 'rails', "#{rails_version}"
|
gem 'rails', "#{rails_version}"
|
||||||
|
|
||||||
|
|||||||
202
Gemfile.lock
202
Gemfile.lock
@ -1,56 +1,67 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: ./rswag-api
|
remote: rswag-api
|
||||||
specs:
|
specs:
|
||||||
rswag-api (1.2.0)
|
rswag-api (1.2.1)
|
||||||
rails (>= 3.1, < 5.1)
|
rails (>= 3.1, < 5.2)
|
||||||
|
|
||||||
PATH
|
PATH
|
||||||
remote: ./rswag-specs
|
remote: rswag-specs
|
||||||
specs:
|
specs:
|
||||||
rswag-specs (1.2.0)
|
rswag-specs (1.2.1)
|
||||||
|
json (~> 1.8)
|
||||||
json-schema (~> 2.2)
|
json-schema (~> 2.2)
|
||||||
rails (>= 3.1, < 5.1)
|
rails (>= 3.1, < 5.2)
|
||||||
rspec-rails (>= 2.14, < 4)
|
rspec-rails (>= 2.14, < 4)
|
||||||
|
|
||||||
PATH
|
PATH
|
||||||
remote: ./rswag-ui
|
remote: rswag-ui
|
||||||
specs:
|
specs:
|
||||||
rswag-ui (1.2.0)
|
rswag-ui (1.2.1)
|
||||||
rails (>= 3.1, < 5.1)
|
rails (>= 3.1, < 5.2)
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
actionmailer (3.2.22)
|
actioncable (5.1.1)
|
||||||
actionpack (= 3.2.22)
|
actionpack (= 5.1.1)
|
||||||
mail (~> 2.5.4)
|
nio4r (~> 2.0)
|
||||||
actionpack (3.2.22)
|
websocket-driver (~> 0.6.1)
|
||||||
activemodel (= 3.2.22)
|
actionmailer (5.1.1)
|
||||||
activesupport (= 3.2.22)
|
actionpack (= 5.1.1)
|
||||||
builder (~> 3.0.0)
|
actionview (= 5.1.1)
|
||||||
erubis (~> 2.7.0)
|
activejob (= 5.1.1)
|
||||||
journey (~> 1.0.4)
|
mail (~> 2.5, >= 2.5.4)
|
||||||
rack (~> 1.4.5)
|
rails-dom-testing (~> 2.0)
|
||||||
rack-cache (~> 1.2)
|
actionpack (5.1.1)
|
||||||
rack-test (~> 0.6.1)
|
actionview (= 5.1.1)
|
||||||
sprockets (~> 2.2.1)
|
activesupport (= 5.1.1)
|
||||||
activemodel (3.2.22)
|
rack (~> 2.0)
|
||||||
activesupport (= 3.2.22)
|
rack-test (~> 0.6.3)
|
||||||
builder (~> 3.0.0)
|
rails-dom-testing (~> 2.0)
|
||||||
activerecord (3.2.22)
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
||||||
activemodel (= 3.2.22)
|
actionview (5.1.1)
|
||||||
activesupport (= 3.2.22)
|
activesupport (= 5.1.1)
|
||||||
arel (~> 3.0.2)
|
builder (~> 3.1)
|
||||||
tzinfo (~> 0.3.29)
|
erubi (~> 1.4)
|
||||||
activeresource (3.2.22)
|
rails-dom-testing (~> 2.0)
|
||||||
activemodel (= 3.2.22)
|
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
||||||
activesupport (= 3.2.22)
|
activejob (5.1.1)
|
||||||
activesupport (3.2.22)
|
activesupport (= 5.1.1)
|
||||||
i18n (~> 0.6, >= 0.6.4)
|
globalid (>= 0.3.6)
|
||||||
multi_json (~> 1.0)
|
activemodel (5.1.1)
|
||||||
|
activesupport (= 5.1.1)
|
||||||
|
activerecord (5.1.1)
|
||||||
|
activemodel (= 5.1.1)
|
||||||
|
activesupport (= 5.1.1)
|
||||||
|
arel (~> 8.0)
|
||||||
|
activesupport (5.1.1)
|
||||||
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
||||||
|
i18n (~> 0.7)
|
||||||
|
minitest (~> 5.1)
|
||||||
|
tzinfo (~> 1.1)
|
||||||
addressable (2.4.0)
|
addressable (2.4.0)
|
||||||
arel (3.0.3)
|
arel (8.0.0)
|
||||||
builder (3.0.4)
|
builder (3.2.3)
|
||||||
capybara (2.10.1)
|
capybara (2.10.1)
|
||||||
addressable
|
addressable
|
||||||
mime-types (>= 1.16)
|
mime-types (>= 1.16)
|
||||||
@ -61,55 +72,65 @@ GEM
|
|||||||
capybara-webkit (1.1.0)
|
capybara-webkit (1.1.0)
|
||||||
capybara (~> 2.0, >= 2.0.2)
|
capybara (~> 2.0, >= 2.0.2)
|
||||||
json
|
json
|
||||||
|
concurrent-ruby (1.0.5)
|
||||||
diff-lcs (1.2.5)
|
diff-lcs (1.2.5)
|
||||||
erubis (2.7.0)
|
erubi (1.6.0)
|
||||||
execjs (2.7.0)
|
execjs (2.7.0)
|
||||||
generator_spec (0.9.3)
|
generator_spec (0.9.3)
|
||||||
activesupport (>= 3.0.0)
|
activesupport (>= 3.0.0)
|
||||||
railties (>= 3.0.0)
|
railties (>= 3.0.0)
|
||||||
hike (1.2.3)
|
globalid (0.4.0)
|
||||||
i18n (0.7.0)
|
activesupport (>= 4.2.0)
|
||||||
journey (1.0.4)
|
i18n (0.8.1)
|
||||||
json (1.8.3)
|
json (1.8.6)
|
||||||
json-schema (2.7.0)
|
json-schema (2.8.0)
|
||||||
addressable (>= 2.4)
|
addressable (>= 2.4)
|
||||||
libv8 (3.16.14.15)
|
libv8 (3.16.14.15)
|
||||||
mail (2.5.4)
|
loofah (2.0.3)
|
||||||
mime-types (~> 1.16)
|
nokogiri (>= 1.5.9)
|
||||||
treetop (~> 1.4.8)
|
mail (2.6.5)
|
||||||
mime-types (1.25.1)
|
mime-types (>= 1.16, < 4)
|
||||||
|
method_source (0.8.2)
|
||||||
|
mime-types (3.1)
|
||||||
|
mime-types-data (~> 3.2015)
|
||||||
|
mime-types-data (3.2016.0521)
|
||||||
mini_portile2 (2.1.0)
|
mini_portile2 (2.1.0)
|
||||||
multi_json (1.12.1)
|
minitest (5.10.2)
|
||||||
|
nio4r (2.0.0)
|
||||||
nokogiri (1.6.8.1)
|
nokogiri (1.6.8.1)
|
||||||
mini_portile2 (~> 2.1.0)
|
mini_portile2 (~> 2.1.0)
|
||||||
polyglot (0.3.5)
|
|
||||||
power_assert (0.3.1)
|
power_assert (0.3.1)
|
||||||
rack (1.4.7)
|
rack (2.0.3)
|
||||||
rack-cache (1.6.1)
|
|
||||||
rack (>= 0.4)
|
|
||||||
rack-ssl (1.3.4)
|
|
||||||
rack
|
|
||||||
rack-test (0.6.3)
|
rack-test (0.6.3)
|
||||||
rack (>= 1.0)
|
rack (>= 1.0)
|
||||||
rails (3.2.22)
|
rails (5.1.1)
|
||||||
actionmailer (= 3.2.22)
|
actioncable (= 5.1.1)
|
||||||
actionpack (= 3.2.22)
|
actionmailer (= 5.1.1)
|
||||||
activerecord (= 3.2.22)
|
actionpack (= 5.1.1)
|
||||||
activeresource (= 3.2.22)
|
actionview (= 5.1.1)
|
||||||
activesupport (= 3.2.22)
|
activejob (= 5.1.1)
|
||||||
bundler (~> 1.0)
|
activemodel (= 5.1.1)
|
||||||
railties (= 3.2.22)
|
activerecord (= 5.1.1)
|
||||||
railties (3.2.22)
|
activesupport (= 5.1.1)
|
||||||
actionpack (= 3.2.22)
|
bundler (>= 1.3.0, < 2.0)
|
||||||
activesupport (= 3.2.22)
|
railties (= 5.1.1)
|
||||||
rack-ssl (~> 1.3.2)
|
sprockets-rails (>= 2.0.0)
|
||||||
|
rails-dom-testing (2.0.3)
|
||||||
|
activesupport (>= 4.2.0)
|
||||||
|
nokogiri (>= 1.6)
|
||||||
|
rails-html-sanitizer (1.0.3)
|
||||||
|
loofah (~> 2.0)
|
||||||
|
railties (5.1.1)
|
||||||
|
actionpack (= 5.1.1)
|
||||||
|
activesupport (= 5.1.1)
|
||||||
|
method_source
|
||||||
rake (>= 0.8.7)
|
rake (>= 0.8.7)
|
||||||
rdoc (~> 3.4)
|
thor (>= 0.18.1, < 2.0)
|
||||||
thor (>= 0.14.6, < 2.0)
|
rake (12.0.0)
|
||||||
rake (11.3.0)
|
|
||||||
rdoc (3.12.2)
|
|
||||||
json (~> 1.4)
|
|
||||||
ref (2.0.0)
|
ref (2.0.0)
|
||||||
|
responders (2.4.0)
|
||||||
|
actionpack (>= 4.2.0, < 5.3)
|
||||||
|
railties (>= 4.2.0, < 5.3)
|
||||||
rspec-core (3.5.4)
|
rspec-core (3.5.4)
|
||||||
rspec-support (~> 3.5.0)
|
rspec-support (~> 3.5.0)
|
||||||
rspec-expectations (3.5.0)
|
rspec-expectations (3.5.0)
|
||||||
@ -127,30 +148,28 @@ GEM
|
|||||||
rspec-mocks (~> 3.5.0)
|
rspec-mocks (~> 3.5.0)
|
||||||
rspec-support (~> 3.5.0)
|
rspec-support (~> 3.5.0)
|
||||||
rspec-support (3.5.0)
|
rspec-support (3.5.0)
|
||||||
sprockets (2.2.3)
|
sprockets (3.7.1)
|
||||||
hike (~> 1.2)
|
concurrent-ruby (~> 1.0)
|
||||||
multi_json (~> 1.0)
|
rack (> 1, < 3)
|
||||||
rack (~> 1.0)
|
sprockets-rails (3.2.0)
|
||||||
tilt (~> 1.1, != 1.3.0)
|
actionpack (>= 4.0)
|
||||||
|
activesupport (>= 4.0)
|
||||||
|
sprockets (>= 3.0.0)
|
||||||
sqlite3 (1.3.12)
|
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)
|
test-unit (3.2.1)
|
||||||
power_assert
|
power_assert
|
||||||
therubyracer (0.12.2)
|
therubyracer (0.12.2)
|
||||||
libv8 (~> 3.16.14.0)
|
libv8 (~> 3.16.14.0)
|
||||||
ref
|
ref
|
||||||
thor (0.19.1)
|
thor (0.19.4)
|
||||||
tilt (1.4.1)
|
thread_safe (0.3.6)
|
||||||
treetop (1.4.15)
|
tzinfo (1.2.3)
|
||||||
polyglot
|
thread_safe (~> 0.1)
|
||||||
polyglot (>= 0.3.1)
|
|
||||||
tzinfo (0.3.51)
|
|
||||||
uglifier (3.0.2)
|
uglifier (3.0.2)
|
||||||
execjs (>= 0.3.0, < 3)
|
execjs (>= 0.3.0, < 3)
|
||||||
|
websocket-driver (0.6.5)
|
||||||
|
websocket-extensions (>= 0.1.0)
|
||||||
|
websocket-extensions (0.1.2)
|
||||||
xpath (2.0.0)
|
xpath (2.0.0)
|
||||||
nokogiri (~> 1.3)
|
nokogiri (~> 1.3)
|
||||||
|
|
||||||
@ -161,13 +180,16 @@ DEPENDENCIES
|
|||||||
capybara
|
capybara
|
||||||
capybara-webkit
|
capybara-webkit
|
||||||
generator_spec
|
generator_spec
|
||||||
rails (= 3.2.22)
|
rails (= 5.1.1)
|
||||||
|
responders
|
||||||
rspec-rails
|
rspec-rails
|
||||||
rswag-api!
|
rswag-api!
|
||||||
rswag-specs!
|
rswag-specs!
|
||||||
rswag-ui!
|
rswag-ui!
|
||||||
sqlite3
|
sqlite3
|
||||||
strong_parameters
|
|
||||||
test-unit
|
test-unit
|
||||||
therubyracer
|
therubyracer
|
||||||
uglifier
|
uglifier
|
||||||
|
|
||||||
|
BUNDLED WITH
|
||||||
|
1.14.6
|
||||||
|
|||||||
11
README.md
11
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
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
module Rswag
|
module Rswag
|
||||||
module Api
|
module Api
|
||||||
VERSION = '1.2.0'
|
VERSION = '1.2.1'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -14,7 +14,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 "rails", ">= 3.1", "< 5.2"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -28,10 +28,10 @@ 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
|
||||||
|
|||||||
@ -3,6 +3,7 @@ require 'json-schema'
|
|||||||
module Rswag
|
module Rswag
|
||||||
module Specs
|
module Specs
|
||||||
class ExtendedSchema < JSON::Schema::Draft4
|
class ExtendedSchema < JSON::Schema::Draft4
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
@attributes['type'] = ExtendedTypeAttribute
|
@attributes['type'] = ExtendedTypeAttribute
|
||||||
@ -12,6 +13,7 @@ module Rswag
|
|||||||
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
|
||||||
|
|||||||
@ -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 +1,5 @@
|
|||||||
module Rswag
|
module Rswag
|
||||||
module Specs
|
module Specs
|
||||||
VERSION = '1.2.0'
|
VERSION = '1.2.1'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -16,7 +16,8 @@ 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 "rails", ">= 3.1", "< 5.2"
|
||||||
|
s.add_dependency 'json', '~> 1.8'
|
||||||
s.add_dependency 'json-schema', '~> 2.2'
|
s.add_dependency 'json-schema', '~> 2.2'
|
||||||
s.add_dependency 'rspec-rails', '>= 2.14', '< 4'
|
s.add_dependency 'rspec-rails', '>= 2.14', '< 4'
|
||||||
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
|
||||||
|
|||||||
@ -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 +1,5 @@
|
|||||||
module Rswag
|
module Rswag
|
||||||
module Ui
|
module Ui
|
||||||
VERSION = '1.2.0'
|
VERSION = '1.2.1'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -16,5 +16,5 @@ 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 "rails", ">= 3.1", "< 5.2"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
module Rswag
|
module Rswag
|
||||||
VERSION = '1.2.0'
|
VERSION = '1.2.1'
|
||||||
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
|
||||||
|
|||||||
@ -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,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", limit: 255
|
||||||
t.text "content"
|
t.text "content"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -39,7 +39,7 @@ 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' ]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -146,7 +146,8 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"content": {
|
"content": {
|
||||||
"type": "string"
|
"type": "string",
|
||||||
|
"x-nullable": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user