openapi_validator 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03d06da470bc735d01636c06b916e5247d961cb6c1ba45927bed48b052ea8063
4
- data.tar.gz: a1eb96abfb80219e9bf1019b6210a9b92a47a56be8db4887c6d6fdc59e97af6d
3
+ metadata.gz: 9ee3a6bfb7172dc7ba0758635a8a4303a5c4ea79c5548057340772ec3b41af5b
4
+ data.tar.gz: 9bda0a6bde8325778ba45494c70030919ae96b7422fab576c57404483463e9c2
5
5
  SHA512:
6
- metadata.gz: f8136a756581e5409821f4ca8d3ea10f9e1334b47dd1027af66415ab850f5db96bd69ed996d9e647ac41712bd22c7e6f0408c0fffef6c8a0edfef7a5f01d70f6
7
- data.tar.gz: 607e50ebd480b4e0b2cdb6f91494ead6c33e781ca290b901f457fc3731e118a17366fac841811ae5f6755856726c4d96bfbf9bc62ad4082da4b53ad193798cd9
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 JSON::Validator.fully_validate(schema, api_doc)
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'] = ExtendedTypeAttribute
9
- @uri = URI.parse('http://tempuri.org/apivore/extended_schema')
10
- @names = ['http://tempuri.org/apivore/extended_schema']
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
- JSON::Validator.register_validator(self.new)
14
- JSON::Validator.register_default_validator(self.new)
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 += JSON::Validator.fully_validate(validator.api_doc, body, fragment: path_validator.fragment)
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,6 @@
1
+
2
+ module OpenapiValidator
3
+ class JsonValidator < JSON::Validator
4
+ attr_reader :options
5
+ end
6
+ end
@@ -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 ExtendedTypeAttribute < JSON::Schema::TypeV4Attribute
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
@@ -1,3 +1,3 @@
1
1
  module OpenapiValidator
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
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.2
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-04-27 00:00:00.000000000 Z
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