mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 23:32:58 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3506fee3d0 | ||
|
|
5df130922f | ||
|
|
5a19cd2373 |
@@ -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
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module Rswag
|
module Rswag
|
||||||
module Api
|
module Api
|
||||||
VERSION = '1.0.2'
|
VERSION = '1.0.3'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
25
rswag-specs/lib/rswag/specs/extended_schema.rb
Normal file
25
rswag-specs/lib/rswag/specs/extended_schema.rb
Normal 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
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module Rswag
|
module Rswag
|
||||||
module Specs
|
module Specs
|
||||||
VERSION = '1.0.2'
|
VERSION = '1.0.3'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module Rswag
|
module Rswag
|
||||||
module Ui
|
module Ui
|
||||||
VERSION = '1.0.2'
|
VERSION = '1.0.3'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module Rswag
|
module Rswag
|
||||||
VERSION = '1.0.2'
|
VERSION = '1.0.3'
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user