rswag-specs 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rswag/specs/extended_schema.rb +25 -0
- data/lib/rswag/specs/response_validator.rb +9 -3
- data/lib/rswag/specs/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2643849549d65f9a5854dad6d177588db4390bd9
|
4
|
+
data.tar.gz: c164db99213ff0543cb2359a629bba5c9e162a64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f96616d29280adf887600c0c33cf31cac2899de178101ec27641e5f32a3f685ec02108016925fac17899b2663f155c197852d3c8932db8da7f6932300ce8bba
|
7
|
+
data.tar.gz: b85ec04810dfb22c059f61a1519ffeb4c7dcdc28ed675b98bbe7ec314680eb31dd70476d9fe03e0c04eda2634cc117027692280c2de2c1c4999360d08f5f2f1a
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'json-schema'
|
2
|
+
|
3
|
+
module Rswag
|
4
|
+
module Specs
|
5
|
+
class ExtendedSchema < JSON::Schema::Validator
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
extend_schema_definition("http://json-schema.org/draft-04/schema#")
|
10
|
+
@attributes['type'] = ExtendedTypeAttribute
|
11
|
+
@uri = URI.parse('http://tempuri.org/rswag/specs/extended_schema')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class ExtendedTypeAttribute < JSON::Schema::TypeV4Attribute
|
16
|
+
|
17
|
+
def self.validate(current_schema, data, fragments, processor, validator, options={})
|
18
|
+
return if data.nil? && current_schema.schema['x-nullable'] == true
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
JSON::Validator.register_validator(ExtendedSchema.new)
|
24
|
+
end
|
25
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
|
+
require 'active_support/core_ext/hash/slice'
|
1
2
|
require 'json-schema'
|
3
|
+
require 'rswag/specs/extended_schema'
|
2
4
|
|
3
5
|
module Rswag
|
4
6
|
module Specs
|
@@ -23,10 +25,14 @@ module Rswag
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def validate_body!(body)
|
26
|
-
|
27
|
-
return if
|
28
|
+
response_schema = @api_metadata[:response][:schema]
|
29
|
+
return if response_schema.nil?
|
30
|
+
|
28
31
|
begin
|
29
|
-
|
32
|
+
validation_schema = response_schema
|
33
|
+
.merge('$schema' => 'http://tempuri.org/rswag/specs/extended_schema')
|
34
|
+
.merge(@global_metadata.slice(:definitions))
|
35
|
+
JSON::Validator.validate!(validation_schema, body)
|
30
36
|
rescue JSON::Schema::ValidationError => ex
|
31
37
|
raise UnexpectedResponse, "Expected response body to match schema: #{ex.message}"
|
32
38
|
end
|
data/lib/rswag/specs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rswag-specs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richie Morris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- lib/rswag/specs/configuration.rb
|
82
82
|
- lib/rswag/specs/example_group_helpers.rb
|
83
83
|
- lib/rswag/specs/example_helpers.rb
|
84
|
+
- lib/rswag/specs/extended_schema.rb
|
84
85
|
- lib/rswag/specs/railtie.rb
|
85
86
|
- lib/rswag/specs/request_factory.rb
|
86
87
|
- lib/rswag/specs/response_validator.rb
|