class OpenAPIParser::SchemaValidator::IntegerValidator

Public Instance Methods

coerce_and_validate(value, schema, **_keyword_args) click to toggle source

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

# File lib/openapi_parser/schema_validators/integer_validator.rb, line 9
def coerce_and_validate(value, schema, **_keyword_args)
  value = coerce(value) if @coerce_value

  return OpenAPIParser::ValidateError.build_error_result(value, schema) unless value.kind_of?(Integer)

  value, err = check_enum_include(value, schema)
  return [nil, err] if err

  check_minimum_maximum(value, schema)
end

Private Instance Methods

coerce(value) click to toggle source
# File lib/openapi_parser/schema_validators/integer_validator.rb, line 22
def coerce(value)
  return value if value.kind_of?(Integer)

  begin
    Integer(value)
  rescue ArgumentError, TypeError
    value
  end
end