class OpenAPIParser::SchemaValidator

validate AllOf schema

Public Class Methods

new(value, schema, options) click to toggle source

@param [Hash] value @param [OpenAPIParser::Schemas::Schema] schema @param [OpenAPIParser::SchemaValidator::Options] options

# File lib/openapi_parser/schema_validator.rb, line 52
def initialize(value, schema, options)
  @value = value
  @schema = schema
  @coerce_value = options.coerce_value
  @datetime_coerce_class = options.datetime_coerce_class
end
validate(value, schema, options) click to toggle source

validate schema data @param [Hash] value @param [OpenAPIParser::Schemas:v:Schema] @param [OpenAPIParser::SchemaValidator::Options] options @return [Object] coerced or original params

# File lib/openapi_parser/schema_validator.rb, line 44
def validate(value, schema, options)
  new(value, schema, options).validate_data
end

Public Instance Methods

validate_data() click to toggle source

execute validate data @return [Object] coerced or original params

# File lib/openapi_parser/schema_validator.rb, line 61
def validate_data
  coerced, err = validate_schema(@value, @schema)
  raise err if err

  coerced
end
validate_integer(value, schema) click to toggle source

validate integer value by schema this method use from float_validator because number allow float and integer @param [Object] value @param [OpenAPIParser::Schemas::Schema] schema

# File lib/openapi_parser/schema_validator.rb, line 90
def validate_integer(value, schema)
  integer_validator.coerce_and_validate(value, schema)
end
validate_schema(value, schema, **keyword_args) click to toggle source

validate value eby schema @param [Object] value @param [OpenAPIParser::Schemas::Schema] schema

# File lib/openapi_parser/schema_validator.rb, line 71
def validate_schema(value, schema, **keyword_args)
  return [value, nil] unless schema

  if (v = validator(value, schema))
    if keyword_args.empty?
      return v.coerce_and_validate(value, schema)
    else
      return v.coerce_and_validate(value, schema, **keyword_args)
    end
  end

  # unknown return error
  OpenAPIParser::ValidateError.build_error_result(value, schema)
end

Private Instance Methods

all_of_validator() click to toggle source
# File lib/openapi_parser/schema_validator.rb, line 149
def all_of_validator
  @all_of_validator ||= OpenAPIParser::SchemaValidator::AllOfValidator.new(self, @coerce_value)
end
any_of_validator() click to toggle source
# File lib/openapi_parser/schema_validator.rb, line 145
def any_of_validator
  @any_of_validator ||= OpenAPIParser::SchemaValidator::AnyOfValidator.new(self, @coerce_value)
end
array_validator() click to toggle source
# File lib/openapi_parser/schema_validator.rb, line 141
def array_validator
  @array_validator ||= OpenAPIParser::SchemaValidator::ArrayValidator.new(self, @coerce_value)
end
boolean_validator() click to toggle source
# File lib/openapi_parser/schema_validator.rb, line 133
def boolean_validator
  @boolean_validator ||= OpenAPIParser::SchemaValidator::BooleanValidator.new(self, @coerce_value)
end
float_validator() click to toggle source
# File lib/openapi_parser/schema_validator.rb, line 129
def float_validator
  @float_validator ||= OpenAPIParser::SchemaValidator::FloatValidator.new(self, @coerce_value)
end
integer_validator() click to toggle source
# File lib/openapi_parser/schema_validator.rb, line 125
def integer_validator
  @integer_validator ||= OpenAPIParser::SchemaValidator::IntegerValidator.new(self, @coerce_value)
end
nil_validator() click to toggle source
# File lib/openapi_parser/schema_validator.rb, line 157
def nil_validator
  @nil_validator ||= OpenAPIParser::SchemaValidator::NilValidator.new(self, @coerce_value)
end
object_validator() click to toggle source
# File lib/openapi_parser/schema_validator.rb, line 137
def object_validator
  @object_validator ||= OpenAPIParser::SchemaValidator::ObjectValidator.new(self, @coerce_value)
end
one_of_validator() click to toggle source
# File lib/openapi_parser/schema_validator.rb, line 153
def one_of_validator
  @one_of_validator ||= OpenAPIParser::SchemaValidator::OneOfValidator.new(self, @coerce_value)
end
string_validator() click to toggle source
# File lib/openapi_parser/schema_validator.rb, line 121
def string_validator
  @string_validator ||= OpenAPIParser::SchemaValidator::StringValidator.new(self, @coerce_value, @datetime_coerce_class)
end
unspecified_type_validator() click to toggle source
# File lib/openapi_parser/schema_validator.rb, line 161
def unspecified_type_validator
  @unspecified_type_validator ||= OpenAPIParser::SchemaValidator::UnspecifiedTypeValidator.new(self, @coerce_value)
end
validator(value, schema) click to toggle source

@return [OpenAPIParser::SchemaValidator::Base, nil]

# File lib/openapi_parser/schema_validator.rb, line 97
def validator(value, schema)
  return any_of_validator if schema.any_of
  return all_of_validator if schema.all_of
  return one_of_validator if schema.one_of
  return nil_validator if value.nil?

  case schema.type
  when 'string'
    string_validator
  when 'integer'
    integer_validator
  when 'boolean'
    boolean_validator
  when 'number'
    float_validator
  when 'object'
    object_validator
  when 'array'
    array_validator
  else
    unspecified_type_validator
  end
end