Sha256: 3ef97a844378ec9562de1f278b86ce44f6b2af42ff1278f6ef8a7d4a9693d430

Contents?: true

Size: 991 Bytes

Versions: 12

Compression:

Stored size: 991 Bytes

Contents

class OpenAPIParser::SchemaValidator
  class FloatValidator < Base
    include ::OpenAPIParser::SchemaValidator::Enumable
    include ::OpenAPIParser::SchemaValidator::MinimumMaximum

    # validate float value by schema
    # @param [Object] value
    # @param [OpenAPIParser::Schemas::Schema] schema
    def coerce_and_validate(value, schema, **_keyword_args)
      value = coerce(value) if @coerce_value

      return validatable.validate_integer(value, schema) if value.kind_of?(Integer)

      coercer_and_validate_numeric(value, schema)
    end

    private

      def coercer_and_validate_numeric(value, schema)
        return OpenAPIParser::ValidateError.build_error_result(value, schema) unless value.kind_of?(Numeric)

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

        check_minimum_maximum(value, schema)
      end

      def coerce(value)
        Float(value)
      rescue ArgumentError, TypeError
        value
      end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
openapi_parser-2.2.3 lib/openapi_parser/schema_validator/float_validator.rb
openapi_parser-2.2.2 lib/openapi_parser/schema_validator/float_validator.rb
openapi_parser-2.2.1 lib/openapi_parser/schema_validator/float_validator.rb
openapi_parser-2.2.0 lib/openapi_parser/schema_validator/float_validator.rb
openapi_parser-2.1.0 lib/openapi_parser/schema_validator/float_validator.rb
openapi_parser-2.0.0 lib/openapi_parser/schema_validator/float_validator.rb
openapi_parser_firetail-1.0.0 lib/openapi_parser/schema_validator/float_validator.rb
openapi_parser-1.0.0 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-1.0.0.beta1 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.15.0 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.14.1 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.14.0 lib/openapi_parser/schema_validators/float_validator.rb