Sha256: 7be394854146d53cfb486120c055375bd364d245127b0915d8ef071956189de4

Contents?: true

Size: 1.02 KB

Versions: 15

Compression:

Stored size: 1.02 KB

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 => e
        raise e unless e.message =~ /invalid value for Float/
      end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
openapi_parser-0.13.0 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.12.1 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.12.0 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.11.2 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.11.1 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.11.0 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.10.0 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.9.0 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.8.0 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.7.0 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.6.1 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.6.0 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.5.0 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.4.1 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.4.0 lib/openapi_parser/schema_validators/float_validator.rb