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/properties_number.rb,
lib/openapi_parser/schema_validator/unspecified_type_validator.rb

Overview

validate AllOf schema

Defined Under Namespace

Modules: Enumable, MinimumMaximum, PropertiesNumber, 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:



53
54
55
56
57
58
# File 'lib/openapi_parser/schema_validator.rb', line 53

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



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

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



62
63
64
65
66
67
# File 'lib/openapi_parser/schema_validator.rb', line 62

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:



91
92
93
# File 'lib/openapi_parser/schema_validator.rb', line 91

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:



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/openapi_parser/schema_validator.rb', line 72

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