Class: OpenAPIParser::SchemaValidator

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

Overview

validate AllOf schema

Defined Under Namespace

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, schema, options) ⇒ SchemaValidator

Returns a new instance of SchemaValidator.

Parameters:



50
51
52
53
54
55
# File 'lib/openapi_parser/schema_validator.rb', line 50

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



42
43
44
# File 'lib/openapi_parser/schema_validator.rb', line 42

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



59
60
61
62
63
64
# File 'lib/openapi_parser/schema_validator.rb', line 59

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:



88
89
90
# File 'lib/openapi_parser/schema_validator.rb', line 88

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:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/openapi_parser/schema_validator.rb', line 69

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