openapi_validator 0.3.2 → 0.3.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/openapi_validator/documentation_validator.rb +2 -1
- data/lib/openapi_validator/extended_schema.rb +9 -6
- data/lib/openapi_validator/request_validator.rb +2 -1
- data/lib/openapi_validator/schema/json_validator.rb +6 -0
- data/lib/openapi_validator/schema/required_attribute.rb +28 -0
- data/lib/openapi_validator/{extended_type_attribute.rb → schema/type_attribute.rb} +1 -1
- data/lib/openapi_validator/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ee3a6bfb7172dc7ba0758635a8a4303a5c4ea79c5548057340772ec3b41af5b
|
4
|
+
data.tar.gz: 9bda0a6bde8325778ba45494c70030919ae96b7422fab576c57404483463e9c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f3e2bad86407dd53b7fc0723b6e7149aa2b7f97ddb0b942e9e19407f0c8e3b064165373250eb12432255eed1374f19da9ee5dddbd89e13a15ce6f7a031143e9
|
7
|
+
data.tar.gz: 0fc7db57b782c4727adcf3494412779c328038bba545d216370d52f5eeddb1c67f3bab7b0aee15a67c89bf045c762036fe4d9e9b8299a1a4a994bbd891ff921b
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "json-schema"
|
2
2
|
require "openapi_validator/file_loader"
|
3
|
+
require "openapi_validator/schema/json_validator"
|
3
4
|
|
4
5
|
module OpenapiValidator
|
5
6
|
class DocumentationValidator
|
@@ -30,7 +31,7 @@ module OpenapiValidator
|
|
30
31
|
# @return [DocumentationValidator]
|
31
32
|
def validate
|
32
33
|
parsed_schemas.each do |schema|
|
33
|
-
errors.concat
|
34
|
+
errors.concat JsonValidator.fully_validate(schema, api_doc)
|
34
35
|
end
|
35
36
|
|
36
37
|
self
|
@@ -1,16 +1,19 @@
|
|
1
|
-
require "openapi_validator/extended_type_attribute"
|
2
1
|
require "json-schema"
|
2
|
+
require "openapi_validator/schema/json_validator"
|
3
|
+
require "openapi_validator/schema/required_attribute"
|
4
|
+
require "openapi_validator/schema/type_attribute"
|
3
5
|
|
4
6
|
module OpenapiValidator
|
5
7
|
class ExtendedSchema < JSON::Schema::Draft4
|
6
8
|
def initialize
|
7
9
|
super
|
8
|
-
@attributes['type'] =
|
9
|
-
@
|
10
|
-
@
|
10
|
+
@attributes['type'] = TypeAttribute
|
11
|
+
@attributes['required'] = RequiredAttribute
|
12
|
+
@uri = URI.parse('http://example.com/extended_schema')
|
13
|
+
@names = ['http://example.com/extended_schema']
|
11
14
|
end
|
12
15
|
|
13
|
-
|
14
|
-
|
16
|
+
JsonValidator.register_validator(self.new)
|
17
|
+
JsonValidator.register_default_validator(self.new)
|
15
18
|
end
|
16
19
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'openapi_validator/path_validator'
|
2
|
+
require 'openapi_validator/schema/json_validator'
|
2
3
|
|
3
4
|
module OpenapiValidator
|
4
5
|
class RequestValidator
|
@@ -26,7 +27,7 @@ module OpenapiValidator
|
|
26
27
|
if path_validator.empty_schema?
|
27
28
|
@errors << "Path #{request.path} should return empty response." unless body.empty?
|
28
29
|
else
|
29
|
-
@errors +=
|
30
|
+
@errors += JsonValidator.fully_validate(validator.api_doc, body, fragment: path_validator.fragment, response: true)
|
30
31
|
end
|
31
32
|
|
32
33
|
validator.remove_validated_path(path_validator.path) if @errors.empty?
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "json-schema/attributes/required"
|
2
|
+
|
3
|
+
module OpenapiValidator
|
4
|
+
class RequiredAttribute < JSON::Schema::RequiredAttribute
|
5
|
+
def self.validate(current_schema, data, fragments, processor, validator, options = {})
|
6
|
+
return unless data.is_a?(Hash)
|
7
|
+
|
8
|
+
schema = current_schema.schema
|
9
|
+
defined_properties = schema['properties']
|
10
|
+
|
11
|
+
schema['required'].each do |property, _property_schema|
|
12
|
+
next if data.has_key?(property.to_s)
|
13
|
+
prop_defaults = options[:insert_defaults] &&
|
14
|
+
defined_properties &&
|
15
|
+
defined_properties[property] &&
|
16
|
+
!defined_properties[property]["default"].nil? &&
|
17
|
+
!defined_properties[property]["readonly"]
|
18
|
+
|
19
|
+
skip_error = processor.options[:response] && defined_properties[property]["writeOnly"]
|
20
|
+
|
21
|
+
if !prop_defaults && !skip_error
|
22
|
+
message = "The property '#{build_fragment(fragments)}' did not contain a required property of '#{property}'"
|
23
|
+
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "json-schema/attributes/type_v4"
|
2
2
|
|
3
3
|
module OpenapiValidator
|
4
|
-
class
|
4
|
+
class TypeAttribute < JSON::Schema::TypeV4Attribute
|
5
5
|
def self.validate(current_schema, data, fragments, processor, validator, options = {})
|
6
6
|
return if data.nil? && current_schema.schema["nullable"] == true
|
7
7
|
super
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openapi_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Svyatoslav Kryukov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|
@@ -79,11 +79,13 @@ files:
|
|
79
79
|
- lib/openapi_validator.rb
|
80
80
|
- lib/openapi_validator/documentation_validator.rb
|
81
81
|
- lib/openapi_validator/extended_schema.rb
|
82
|
-
- lib/openapi_validator/extended_type_attribute.rb
|
83
82
|
- lib/openapi_validator/file_loader.rb
|
84
83
|
- lib/openapi_validator/path_validator.rb
|
85
84
|
- lib/openapi_validator/request.rb
|
86
85
|
- lib/openapi_validator/request_validator.rb
|
86
|
+
- lib/openapi_validator/schema/json_validator.rb
|
87
|
+
- lib/openapi_validator/schema/required_attribute.rb
|
88
|
+
- lib/openapi_validator/schema/type_attribute.rb
|
87
89
|
- lib/openapi_validator/validator.rb
|
88
90
|
- lib/openapi_validator/version.rb
|
89
91
|
homepage: https://github.com/medsolutions/openapi_validator
|