3 Commits

Author SHA1 Message Date
richie
3506fee3d0 Prep for 1.0.3 release 2016-10-17 14:50:57 -07:00
richie
5df130922f Support x-nullable in respone_validator 2016-10-17 14:47:11 -07:00
richie
5a19cd2373 Push latest Gemfile.lock 2016-10-14 17:50:42 -07:00
7 changed files with 41 additions and 10 deletions

View File

@@ -1,13 +1,13 @@
PATH PATH
remote: ./rswag-api remote: ./rswag-api
specs: specs:
rswag-api (1.0.1) rswag-api (1.0.3)
rails (>= 3.1, < 5.1) rails (>= 3.1, < 5.1)
PATH PATH
remote: ./rswag-specs remote: ./rswag-specs
specs: specs:
rswag-specs (1.0.1) rswag-specs (1.0.3)
json-schema (~> 2.2) json-schema (~> 2.2)
rails (>= 3.1, < 5.1) rails (>= 3.1, < 5.1)
rspec-rails (>= 2.14, < 4) rspec-rails (>= 2.14, < 4)
@@ -15,7 +15,7 @@ PATH
PATH PATH
remote: ./rswag-ui remote: ./rswag-ui
specs: specs:
rswag-ui (1.0.1) rswag-ui (1.0.3)
rails (>= 3.1, < 5.1) rails (>= 3.1, < 5.1)
GEM GEM

View File

@@ -1,5 +1,5 @@
module Rswag module Rswag
module Api module Api
VERSION = '1.0.2' VERSION = '1.0.3'
end end
end end

View File

@@ -0,0 +1,25 @@
require 'json-schema'
module Rswag
module Specs
class ExtendedSchema < JSON::Schema::Validator
def initialize
super
extend_schema_definition("http://json-schema.org/draft-04/schema#")
@attributes['type'] = ExtendedTypeAttribute
@uri = URI.parse('http://tempuri.org/rswag/specs/extended_schema')
end
end
class ExtendedTypeAttribute < JSON::Schema::TypeV4Attribute
def self.validate(current_schema, data, fragments, processor, validator, options={})
return if data.nil? && current_schema.schema['x-nullable'] == true
super
end
end
JSON::Validator.register_validator(ExtendedSchema.new)
end
end

View File

@@ -1,4 +1,6 @@
require 'active_support/core_ext/hash/slice'
require 'json-schema' require 'json-schema'
require 'rswag/specs/extended_schema'
module Rswag module Rswag
module Specs module Specs
@@ -23,10 +25,14 @@ module Rswag
end end
def validate_body!(body) def validate_body!(body)
schema = @api_metadata[:response][:schema] response_schema = @api_metadata[:response][:schema]
return if schema.nil? return if response_schema.nil?
begin begin
JSON::Validator.validate!(schema.merge(@global_metadata), body) validation_schema = response_schema
.merge('$schema' => 'http://tempuri.org/rswag/specs/extended_schema')
.merge(@global_metadata.slice(:definitions))
JSON::Validator.validate!(validation_schema, body)
rescue JSON::Schema::ValidationError => ex rescue JSON::Schema::ValidationError => ex
raise UnexpectedResponse, "Expected response body to match schema: #{ex.message}" raise UnexpectedResponse, "Expected response body to match schema: #{ex.message}"
end end

View File

@@ -1,5 +1,5 @@
module Rswag module Rswag
module Specs module Specs
VERSION = '1.0.2' VERSION = '1.0.3'
end end
end end

View File

@@ -1,5 +1,5 @@
module Rswag module Rswag
module Ui module Ui
VERSION = '1.0.2' VERSION = '1.0.3'
end end
end end

View File

@@ -1,3 +1,3 @@
module Rswag module Rswag
VERSION = '1.0.2' VERSION = '1.0.3'
end end