Sha256: 9980a5abfda4b8e51bf294f9fd00d4d7fd7589a360502cfaf1aac6d262399181

Contents?: true

Size: 742 Bytes

Versions: 12

Compression:

Stored size: 742 Bytes

Contents

class OpenAPIParser::SchemaValidator
  class BooleanValidator < Base
    include ::OpenAPIParser::SchemaValidator::Enumable

    TRUE_VALUES = ['true', '1'].freeze
    FALSE_VALUES = ['false', '0'].freeze

    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?(TrueClass) || value.kind_of?(FalseClass)

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

      [value, nil]
    end

    private

      def coerce(value)
        return true if TRUE_VALUES.include?(value)

        return false if FALSE_VALUES.include?(value)

        value
      end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

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