openapi_parser 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -2
  3. data/.rubocop_ignore.yml +6 -0
  4. data/.travis.yml +33 -4
  5. data/CHANGELOG.md +9 -0
  6. data/README.md +39 -6
  7. data/lib/openapi_parser/concern.rb +2 -1
  8. data/lib/openapi_parser/concerns/expandable.rb +52 -44
  9. data/lib/openapi_parser/concerns/media_type_selectable.rb +26 -0
  10. data/lib/openapi_parser/concerns/parser.rb +43 -0
  11. data/lib/openapi_parser/concerns/parser/core.rb +21 -0
  12. data/lib/openapi_parser/concerns/parser/hash.rb +10 -0
  13. data/lib/openapi_parser/concerns/parser/hash_body.rb +12 -0
  14. data/lib/openapi_parser/concerns/parser/list.rb +10 -0
  15. data/lib/openapi_parser/concerns/parser/object.rb +14 -0
  16. data/lib/openapi_parser/concerns/parser/value.rb +14 -0
  17. data/lib/openapi_parser/concerns/schema_loader.rb +58 -0
  18. data/lib/openapi_parser/concerns/schema_loader/base.rb +28 -0
  19. data/lib/openapi_parser/concerns/schema_loader/creator.rb +48 -0
  20. data/lib/openapi_parser/concerns/schema_loader/hash_body_loader.rb +37 -0
  21. data/lib/openapi_parser/concerns/schema_loader/hash_objects_loader.rb +29 -0
  22. data/lib/openapi_parser/concerns/schema_loader/list_loader.rb +28 -0
  23. data/lib/openapi_parser/concerns/schema_loader/objects_loader.rb +21 -0
  24. data/lib/openapi_parser/concerns/schema_loader/values_loader.rb +10 -0
  25. data/lib/openapi_parser/config.rb +1 -1
  26. data/lib/openapi_parser/errors.rb +9 -0
  27. data/lib/openapi_parser/path_item_finder.rb +18 -18
  28. data/lib/openapi_parser/request_operation.rb +4 -4
  29. data/lib/openapi_parser/schema_validator.rb +77 -54
  30. data/lib/openapi_parser/schema_validators/all_of_validator.rb +16 -0
  31. data/lib/openapi_parser/schema_validators/any_of_validator.rb +1 -1
  32. data/lib/openapi_parser/schema_validators/array_validator.rb +2 -4
  33. data/lib/openapi_parser/schema_validators/base.rb +9 -6
  34. data/lib/openapi_parser/schema_validators/boolean_validator.rb +11 -9
  35. data/lib/openapi_parser/schema_validators/float_validator.rb +8 -10
  36. data/lib/openapi_parser/schema_validators/integer_validator.rb +11 -10
  37. data/lib/openapi_parser/schema_validators/nil_validator.rb +1 -0
  38. data/lib/openapi_parser/schema_validators/object_validator.rb +3 -3
  39. data/lib/openapi_parser/schema_validators/string_validator.rb +13 -13
  40. data/lib/openapi_parser/schemas/base.rb +1 -2
  41. data/lib/openapi_parser/schemas/media_type.rb +3 -1
  42. data/lib/openapi_parser/schemas/openapi.rb +1 -1
  43. data/lib/openapi_parser/schemas/operation.rb +17 -14
  44. data/lib/openapi_parser/schemas/parameter.rb +2 -2
  45. data/lib/openapi_parser/schemas/request_body.rb +12 -5
  46. data/lib/openapi_parser/schemas/response.rb +4 -4
  47. data/lib/openapi_parser/schemas/responses.rb +21 -3
  48. data/lib/openapi_parser/version.rb +1 -1
  49. data/openapi_parser.gemspec +3 -2
  50. metadata +51 -19
  51. data/lib/openapi_parser/concerns/parseable.rb +0 -238
@@ -0,0 +1,58 @@
1
+ class OpenAPIParser::SchemaLoader
2
+ end
3
+
4
+ require_relative './schema_loader/base'
5
+ require_relative './schema_loader/creator'
6
+ require_relative './schema_loader/values_loader'
7
+ require_relative './schema_loader/list_loader'
8
+ require_relative './schema_loader/objects_loader'
9
+ require_relative './schema_loader/hash_objects_loader'
10
+ require_relative './schema_loader/hash_body_loader'
11
+
12
+ # load data to target_object by schema definition in core
13
+ class OpenAPIParser::SchemaLoader
14
+ # @param [OpenAPIParser::Schemas::Base] target_object
15
+ # @param [OpenAPIParser::Parser::Core] core
16
+ def initialize(target_object, core)
17
+ @target_object = target_object
18
+ @core = core
19
+ @children = {}
20
+ end
21
+
22
+ # @!attribute [r] children
23
+ # @return [Array<OpenAPIParser::Schemas::Base>]
24
+ attr_reader :children
25
+
26
+ # execute load data
27
+ # return data is equal to :children
28
+ # @return [Array<OpenAPIParser::Schemas::Base>]
29
+ def load_data
30
+ all_loader.each { |l| load_data_by_schema_loader(l) }
31
+ children
32
+ end
33
+
34
+ private
35
+
36
+ attr_reader :core, :target_object
37
+
38
+ # @param [OpenAPIParser::SchemaLoader::Base] schema_loader
39
+ def load_data_by_schema_loader(schema_loader)
40
+ children = schema_loader.load_data(target_object, target_object.raw_schema)
41
+
42
+ children.each { |c| register_child(c) } if children
43
+ end
44
+
45
+ def register_child(object)
46
+ return unless object.kind_of?(OpenAPIParser::Parser)
47
+
48
+ @children[object.object_reference] = object
49
+ end
50
+
51
+ def all_loader
52
+ core._openapi_attr_values.values +
53
+ core._openapi_attr_objects.values +
54
+ core._openapi_attr_list_objects.values +
55
+ core._openapi_attr_hash_objects.values +
56
+ core._openapi_attr_hash_body_objects.values
57
+ end
58
+ end
@@ -0,0 +1,28 @@
1
+ # loader base class
2
+ class OpenAPIParser::SchemaLoader::Base
3
+ # @param [String] variable_name
4
+ # @param [Hash] options
5
+ def initialize(variable_name, options)
6
+ @variable_name = variable_name
7
+ @schema_key = options[:schema_key] || variable_name
8
+ end
9
+
10
+ # @param [OpenAPIParser::Schemas::Base] _target_object
11
+ # @param [Hash] _raw_schema
12
+ # @return [Array<OpenAPIParser::Schemas::Base>, nil]
13
+ def load_data(_target_object, _raw_schema)
14
+ raise 'need implement'
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :variable_name, :schema_key
20
+
21
+ # create instance variable @variable_name using data
22
+ # @param [OpenAPIParser::Schemas::Base] target
23
+ # @param [String] variable_name
24
+ # @param [Object] data
25
+ def variable_set(target, variable_name, data)
26
+ target.instance_variable_set("@#{variable_name}", data)
27
+ end
28
+ end
@@ -0,0 +1,48 @@
1
+ # loader base class for create OpenAPI::Schemas::Base object
2
+ class OpenAPIParser::SchemaLoader::Creator < OpenAPIParser::SchemaLoader::Base
3
+ # @param [String] variable_name
4
+ # @param [Hash] options
5
+ def initialize(variable_name, options)
6
+ super(variable_name, options)
7
+
8
+ @klass = options[:klass]
9
+ @allow_reference = options[:reference] || false
10
+ @allow_data_type = options[:allow_data_type]
11
+ end
12
+
13
+ private
14
+
15
+ attr_reader :klass, :allow_reference, :allow_data_type
16
+
17
+ def build_object_reference_from_base(base, names)
18
+ names = [names] unless names.kind_of?(Array)
19
+ ref = names.map { |n| escape_reference(n) }.join('/')
20
+
21
+ "#{base}/#{ref}"
22
+ end
23
+
24
+ # @return Boolean
25
+ def check_reference_schema?(check_schema)
26
+ check_object_schema?(check_schema) && !check_schema['$ref'].nil?
27
+ end
28
+
29
+ def check_object_schema?(check_schema)
30
+ check_schema.kind_of?(::Hash)
31
+ end
32
+
33
+ def escape_reference(str)
34
+ str.to_s.gsub('/', '~1')
35
+ end
36
+
37
+ def build_openapi_object_from_option(target_object, ref, schema)
38
+ return nil unless schema
39
+
40
+ if @allow_data_type && !check_object_schema?(schema)
41
+ schema
42
+ elsif @allow_reference && check_reference_schema?(schema)
43
+ OpenAPIParser::Schemas::Reference.new(ref, target_object, target_object.root, schema)
44
+ else
45
+ @klass.new(ref, target_object, target_object.root, schema)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,37 @@
1
+ # hash body object loader
2
+ class OpenAPIParser::SchemaLoader::HashBodyLoader < OpenAPIParser::SchemaLoader::Creator
3
+ # @param [String] variable_name
4
+ # @param [Hash] options
5
+ def initialize(variable_name, options)
6
+ super(variable_name, options)
7
+
8
+ @reject_keys = options[:reject_keys] ? options[:reject_keys].map(&:to_s) : []
9
+ end
10
+
11
+ # @param [OpenAPIParser::Schemas::Base] target_object
12
+ # @param [Hash] raw_schema
13
+ # @return [Array<OpenAPIParser::Schemas::Base>, nil]
14
+ def load_data(target_object, raw_schema)
15
+ # raw schema always exist because if not exist' this object don't create
16
+ create_hash_body_objects(target_object, raw_schema)
17
+ end
18
+
19
+ private
20
+
21
+ # for responses and paths object
22
+ def create_hash_body_objects(target_object, raw_schema)
23
+ object_list = raw_schema.reject { |k, _| reject_keys.include?(k) }.map do |child_name, child_schema|
24
+ ref = build_object_reference_from_base(target_object.object_reference, escape_reference(child_name))
25
+ [
26
+ child_name.to_s, # support string key only in OpenAPI3
27
+ build_openapi_object_from_option(target_object, ref, child_schema),
28
+ ]
29
+ end
30
+
31
+ objects = object_list.to_h
32
+ variable_set(target_object, variable_name, objects)
33
+ objects.values
34
+ end
35
+
36
+ attr_reader :reject_keys
37
+ end
@@ -0,0 +1,29 @@
1
+ # hash object loader
2
+ class OpenAPIParser::SchemaLoader::HashObjectsLoader < OpenAPIParser::SchemaLoader::Creator
3
+ # @param [OpenAPIParser::Schemas::Base] target_object
4
+ # @param [Hash] raw_schema
5
+ # @return [Array<OpenAPIParser::Schemas::Base>, nil]
6
+ def load_data(target_object, raw_schema)
7
+ create_attr_hash_object(target_object, raw_schema[ref_name_base.to_s])
8
+ end
9
+
10
+ private
11
+
12
+ def create_attr_hash_object(target_object, hash_schema)
13
+ unless hash_schema
14
+ variable_set(target_object, variable_name, nil)
15
+ return
16
+ end
17
+
18
+ data_list = hash_schema.map do |key, s|
19
+ ref = build_object_reference_from_base(target_object.object_reference, [ref_name_base, key])
20
+ [key, build_openapi_object_from_option(target_object, ref, s)]
21
+ end
22
+
23
+ data = data_list.to_h
24
+ variable_set(target_object, variable_name, data)
25
+ data.values
26
+ end
27
+
28
+ alias_method :ref_name_base, :schema_key
29
+ end
@@ -0,0 +1,28 @@
1
+ # list object loader
2
+ class OpenAPIParser::SchemaLoader::ListLoader < OpenAPIParser::SchemaLoader::Creator
3
+ # @param [OpenAPIParser::Schemas::Base] target_object
4
+ # @param [Hash] raw_schema
5
+ # @return [Array<OpenAPIParser::Schemas::Base>, nil]
6
+ def load_data(target_object, raw_schema)
7
+ create_attr_list_object(target_object, raw_schema[ref_name_base.to_s])
8
+ end
9
+
10
+ private
11
+
12
+ def create_attr_list_object(target_object, array_schema)
13
+ unless array_schema
14
+ variable_set(target_object, variable_name, nil)
15
+ return
16
+ end
17
+
18
+ data = array_schema.map.with_index do |s, idx|
19
+ ref = build_object_reference_from_base(target_object.object_reference, [ref_name_base, idx])
20
+ build_openapi_object_from_option(target_object, ref, s)
21
+ end
22
+
23
+ variable_set(target_object, variable_name, data)
24
+ data
25
+ end
26
+
27
+ alias_method :ref_name_base, :schema_key
28
+ end
@@ -0,0 +1,21 @@
1
+ # Specific Object loader (defined by klass option)
2
+ class OpenAPIParser::SchemaLoader::ObjectsLoader < OpenAPIParser::SchemaLoader::Creator
3
+ # @param [OpenAPIParser::Schemas::Base] target_object
4
+ # @param [Hash] raw_schema
5
+ # @return [Array<OpenAPIParser::Schemas::Base>, nil]
6
+ def load_data(target_object, raw_schema)
7
+ obj = create_attr_object(target_object, raw_schema[schema_key.to_s])
8
+ [obj]
9
+ end
10
+
11
+ private
12
+
13
+ # @return [OpenAPIParser::Schemas::Base]
14
+ def create_attr_object(target_object, schema)
15
+ ref = build_object_reference_from_base(target_object.object_reference, schema_key)
16
+
17
+ data = build_openapi_object_from_option(target_object, ref, schema)
18
+ variable_set(target_object, variable_name, data)
19
+ data
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ # data type values loader
2
+ class OpenAPIParser::SchemaLoader::ValuesLoader < OpenAPIParser::SchemaLoader::Base
3
+ # @param [OpenAPIParser::Schemas::Base] target_object
4
+ # @param [Hash] raw_schema
5
+ # @return [Array<OpenAPIParser::Schemas::Base>, nil]
6
+ def load_data(target_object, raw_schema)
7
+ variable_set(target_object, variable_name, raw_schema[schema_key.to_s])
8
+ nil # this loader not return schema object
9
+ end
10
+ end
@@ -16,7 +16,7 @@ class OpenAPIParser::Config
16
16
  end
17
17
 
18
18
  def request_validator_options
19
- @request_options ||= OpenAPIParser::SchemaValidator::Options.new(coerce_value: coerce_value, datetime_coerce_class: datetime_coerce_class)
19
+ @request_validator_options ||= OpenAPIParser::SchemaValidator::Options.new(coerce_value: coerce_value, datetime_coerce_class: datetime_coerce_class)
20
20
  end
21
21
 
22
22
  alias_method :request_body_options, :request_validator_options
@@ -15,6 +15,15 @@ module OpenAPIParser
15
15
  def message
16
16
  "#{@data} class is #{@data.class} but it's not valid #{@type} in #{@reference}"
17
17
  end
18
+
19
+ class << self
20
+ # create ValidateError for SchemaValidator return data
21
+ # @param [Object] value
22
+ # @param [OpenAPIParser::Schemas::Base] schema
23
+ def build_error_result(value, schema)
24
+ [nil, OpenAPIParser::ValidateError.new(value, schema.type, schema.object_reference)]
25
+ end
26
+ end
18
27
  end
19
28
 
20
29
  class NotNullError < OpenAPIError
@@ -4,7 +4,7 @@ class OpenAPIParser::PathItemFinder
4
4
  @root = PathNode.new('/')
5
5
  @paths = paths
6
6
 
7
- @paths.path.each { |path, _path_item_object| @root.register_path_node(path.split("/"), path) }
7
+ @paths.path.each { |path, _path_item_object| @root.register_path_node(path.split('/'), path) }
8
8
  end
9
9
 
10
10
  # @param [String, Symbol] http_method like (get, post .... allow symbol)
@@ -26,7 +26,7 @@ class OpenAPIParser::PathItemFinder
26
26
 
27
27
  def initialize(name)
28
28
  @name = name
29
- @children = Hash.new {|h, k| h[k] = PathNode.new(k) }
29
+ @children = Hash.new { |h, k| h[k] = PathNode.new(k) }
30
30
  @path_template_node = nil # we can't initialize because recursive initialize...
31
31
  @full_path = nil
32
32
  end
@@ -55,11 +55,11 @@ class OpenAPIParser::PathItemFinder
55
55
  # OpenAPI3 depend on the tooling so we use concrete one (using /books/)
56
56
 
57
57
  path_params = {}
58
- if children.key?(path_name)
58
+ if children.has_key?(path_name)
59
59
  child = children[path_name]
60
60
  else
61
61
  child = path_template_node(path_name)
62
- path_params = {"#{child.name}" =>path_name}
62
+ path_params = { child.name.to_s => path_name }
63
63
  end
64
64
 
65
65
  ret, other_path_params = child.find_full_path(splited_path)
@@ -68,26 +68,26 @@ class OpenAPIParser::PathItemFinder
68
68
 
69
69
  private
70
70
 
71
- attr_reader :children
71
+ attr_reader :children
72
72
 
73
- def path_template_node(path_name)
74
- @path_template_node ||= PathNode.new(path_name[1..(path_name.length-2)]) # delete {} from {name}
75
- end
73
+ def path_template_node(path_name)
74
+ @path_template_node ||= PathNode.new(path_name[1..(path_name.length - 2)]) # delete {} from {name}
75
+ end
76
76
 
77
- def path_template?(path_name)
78
- path_name.start_with?('{') && path_name.end_with?('}')
79
- end
77
+ def path_template?(path_name)
78
+ path_name.start_with?('{') && path_name.end_with?('}')
79
+ end
80
80
  end
81
81
 
82
82
  private
83
83
 
84
- def parse_request_path(http_method, request_path)
85
- original_path, path_params = @root.find_full_path(request_path.split("/"))
86
- return nil, nil, {} unless original_path # # can't find
84
+ def parse_request_path(http_method, request_path)
85
+ original_path, path_params = @root.find_full_path(request_path.split('/'))
86
+ return nil, nil, {} unless original_path # # can't find
87
87
 
88
- path_item_object = @paths.path[original_path]
89
- obj = path_item_object.operation(http_method.to_s)
88
+ path_item_object = @paths.path[original_path]
89
+ obj = path_item_object.operation(http_method.to_s)
90
90
 
91
- [obj, original_path, path_params]
92
- end
91
+ [obj, original_path, path_params]
92
+ end
93
93
  end
@@ -36,22 +36,22 @@ class OpenAPIParser::RequestOperation
36
36
  end
37
37
 
38
38
  def validate_path_params(options = nil)
39
- options = config.path_params_options unless options
39
+ options ||= config.path_params_options
40
40
  operation_object&.validate_path_params(path_params, options)
41
41
  end
42
42
 
43
- # support application/json only :(
44
43
  def validate_request_body(content_type, params, options = nil)
45
- options = config.request_body_options unless options
44
+ options ||= config.request_body_options
46
45
  operation_object&.validate_request_body(content_type, params, options)
47
46
  end
48
47
 
48
+ # @param [Integer] status_code
49
49
  def validate_response_body(status_code, content_type, data)
50
50
  operation_object&.validate_response_body(status_code, content_type, data)
51
51
  end
52
52
 
53
53
  def validate_request_parameter(params, options = nil)
54
- options = config.request_validator_options unless options
54
+ options ||= config.request_validator_options
55
55
  operation_object&.validate_request_parameter(params, options)
56
56
  end
57
57
  end
@@ -8,14 +8,24 @@ require_relative 'schema_validators/boolean_validator'
8
8
  require_relative 'schema_validators/object_validator'
9
9
  require_relative 'schema_validators/array_validator'
10
10
  require_relative 'schema_validators/any_of_validator'
11
+ require_relative 'schema_validators/all_of_validator'
11
12
  require_relative 'schema_validators/nil_validator'
12
13
 
13
14
  class OpenAPIParser::SchemaValidator
14
- class ValidatorOption
15
-
15
+ # validate value by schema
16
+ # this module for SchemaValidators::Base
17
+ # @param [Object] value
18
+ # @param [OpenAPIParser::Schemas::Schema] schema
19
+ module Validatable
20
+ def validate_schema(value, schema)
21
+ raise 'implement'
22
+ end
16
23
  end
17
24
 
25
+ include Validatable
26
+
18
27
  class << self
28
+ # validate schema data
19
29
  # @param [Hash] value
20
30
  # @param [OpenAPIParser::Schemas::Schema]
21
31
  # @param [OpenAPIParser::SchemaValidator::Options] options
@@ -35,75 +45,88 @@ class OpenAPIParser::SchemaValidator
35
45
  @datetime_coerce_class = options.datetime_coerce_class
36
46
  end
37
47
 
48
+ # execute validate data
38
49
  # @return [Object] coerced or original params
39
50
  def validate_data
40
51
  coerced, err = validate_schema(@value, @schema)
41
52
  raise err if err
53
+
42
54
  coerced
43
55
  end
44
56
 
45
- def validate_error(value, schema)
46
- [nil, OpenAPIParser::ValidateError.new(value, schema.type, schema.object_reference)]
47
- end
57
+ # validate value eby schema
58
+ # @param [Object] value
59
+ # @param [OpenAPIParser::Schemas::Schema] schema
60
+ def validate_schema(value, schema)
61
+ return [value, nil] unless schema
48
62
 
49
- def validate_string(value, schema)
50
- (@string_validator ||= OpenAPIParser::SchemaValidator::StringValidator.new(self, @coerce_value, @datetime_coerce_class)).coerce_and_validate(value, schema)
51
- end
63
+ if (v = validator(value, schema))
64
+ return v.coerce_and_validate(value, schema)
65
+ end
52
66
 
53
- def validate_integer(value, schema)
54
- (@integer_validator ||= OpenAPIParser::SchemaValidator::IntegerValidator.new(self, @coerce_value)).coerce_and_validate(value, schema)
67
+ # unknown return error
68
+ OpenAPIParser::ValidateError.build_error_result(value, schema)
55
69
  end
56
70
 
57
- def validate_float(value, schema)
58
- (@float_validator ||= OpenAPIParser::SchemaValidator::FloatValidator.new(self, @coerce_value)).coerce_and_validate(value, schema)
59
- end
71
+ private
72
+
73
+ # @return [OpenAPIParser::SchemaValidator::Base, nil]
74
+ def validator(value, schema)
75
+ return any_of_validator if schema.any_of
76
+ return all_of_validator if schema.all_of
77
+ return nil_validator if value.nil?
78
+
79
+ case schema.type
80
+ when 'string'
81
+ string_validator
82
+ when 'integer'
83
+ integer_validator
84
+ when 'boolean'
85
+ boolean_validator
86
+ when 'number'
87
+ float_validator
88
+ when 'object'
89
+ object_validator
90
+ when 'array'
91
+ array_validator
92
+ else
93
+ nil
94
+ end
95
+ end
60
96
 
61
- def validate_boolean(value, schema)
62
- (@boolean_validator ||= OpenAPIParser::SchemaValidator::BooleanValidator.new(self, @coerce_value)).coerce_and_validate(value, schema)
63
- end
97
+ def string_validator
98
+ @string_validator ||= OpenAPIParser::SchemaValidator::StringValidator.new(self, @coerce_value, @datetime_coerce_class)
99
+ end
64
100
 
65
- def validate_object(value, schema)
66
- (@object_validator ||= OpenAPIParser::SchemaValidator::ObjectValidator.new(self, @coerce_value)).coerce_and_validate(value, schema)
67
- end
101
+ def integer_validator
102
+ @integer_validator ||= OpenAPIParser::SchemaValidator::IntegerValidator.new(self, @coerce_value)
103
+ end
68
104
 
69
- def validate_array(value, schema)
70
- (@array_validator ||= OpenAPIParser::SchemaValidator::ArrayValidator.new(self, @coerce_value)).coerce_and_validate(value, schema)
71
- end
105
+ def float_validator
106
+ @float_validator ||= OpenAPIParser::SchemaValidator::FloatValidator.new(self, @coerce_value)
107
+ end
72
108
 
73
- def validate_any_of(value, schema)
74
- (@any_of_validator ||= OpenAPIParser::SchemaValidator::AnyOfValidator.new(self, @coerce_value)).coerce_and_validate(value, schema)
75
- end
109
+ def boolean_validator
110
+ @boolean_validator ||= OpenAPIParser::SchemaValidator::BooleanValidator.new(self, @coerce_value)
111
+ end
76
112
 
77
- def validate_nil(value, schema)
78
- (@nil_validator ||= OpenAPIParser::SchemaValidator::NilValidator.new(self, @coerce_value)).coerce_and_validate(value, schema)
79
- end
113
+ def object_validator
114
+ @object_validator ||= OpenAPIParser::SchemaValidator::ObjectValidator.new(self, @coerce_value)
115
+ end
80
116
 
81
- # @param [Object] value
82
- # @param [OpenAPIParser::Schemas::Schema] schema
83
- def validate_schema(value, schema)
84
- return [value, nil] unless schema # no schema
85
-
86
- return validate_any_of(value, schema) if schema.any_of
87
-
88
- return validate_nil(value, schema) if value.nil?
89
-
90
- case schema.type
91
- when "string"
92
- return validate_string(value, schema)
93
- when "integer"
94
- return validate_integer(value, schema)
95
- when "boolean"
96
- return validate_boolean(value, schema)
97
- when "number"
98
- return validate_float(value, schema)
99
- when "object"
100
- return validate_object(value, schema)
101
- when "array"
102
- return validate_array(value, schema)
103
- else
104
- # TODO: unknown type support
117
+ def array_validator
118
+ @array_validator ||= OpenAPIParser::SchemaValidator::ArrayValidator.new(self, @coerce_value)
105
119
  end
106
120
 
107
- validate_error(value, schema)
108
- end
121
+ def any_of_validator
122
+ @any_of_validator ||= OpenAPIParser::SchemaValidator::AnyOfValidator.new(self, @coerce_value)
123
+ end
124
+
125
+ def all_of_validator
126
+ @all_of_validator ||= OpenAPIParser::SchemaValidator::AllOfValidator.new(self, @coerce_value)
127
+ end
128
+
129
+ def nil_validator
130
+ @nil_validator ||= OpenAPIParser::SchemaValidator::NilValidator.new(self, @coerce_value)
131
+ end
109
132
  end