Class: OpenAPIParser::SchemaValidator

Inherits:
Object
  • Object
show all
Includes:
Validatable
Defined in:
lib/openapi_parser/schema_validator/all_of_validator.rb,
lib/openapi_parser/schema_validator.rb,
lib/openapi_parser/schema_validator/base.rb,
lib/openapi_parser/schema_validator/options.rb,
lib/openapi_parser/schema_validator/enumable.rb,
lib/openapi_parser/schema_validator/nil_validator.rb,
lib/openapi_parser/schema_validator/array_validator.rb,
lib/openapi_parser/schema_validator/float_validator.rb,
lib/openapi_parser/schema_validator/minimum_maximum.rb,
lib/openapi_parser/schema_validator/any_of_validator.rb,
lib/openapi_parser/schema_validator/object_validator.rb,
lib/openapi_parser/schema_validator/one_of_validator.rb,
lib/openapi_parser/schema_validator/string_validator.rb,
lib/openapi_parser/schema_validator/boolean_validator.rb,
lib/openapi_parser/schema_validator/integer_validator.rb,
lib/openapi_parser/schema_validator/unspecified_type_validator.rb

Overview

validate AllOf schema

Defined Under Namespace

Modules: Enumable, MinimumMaximum, Validatable Classes: AllOfValidator, AnyOfValidator, ArrayValidator, Base, BooleanValidator, FloatValidator, IntegerValidator, NilValidator, ObjectValidator, OneOfValidator, Options, ResponseValidateOptions, StringValidator, UnspecifiedTypeValidator

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, schema, options) ⇒ SchemaValidator

Returns a new instance of SchemaValidator.

Parameters:



52
53
54
55
56
57
# 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

Class Method Details

.validate(value, schema, options) ⇒ Object

validate schema data

Parameters:

Returns:

  • (Object)

    coerced or original params



44
45
46
# File 'lib/openapi_parser/schema_validator.rb', line 44

def validate(value, schema, options)
  new(value, schema, options).validate_data
end

Instance Method Details

#validate_dataObject

execute validate data

Returns:

  • (Object)

    coerced or original params



61
62
63
64
65
66
# 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) ⇒ Object

validate integer value by schema this method use from float_validator because number allow float and integer

Parameters:



90
91
92
# 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) ⇒ Object

validate value eby schema

Parameters:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 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