Sha256: 280db0cff0cafebae22b1d9ff189c6088401c0c6cd4cdd88d6ec91b440a7ddba

Contents?: true

Size: 601 Bytes

Versions: 16

Compression:

Stored size: 601 Bytes

Contents

class OpenAPIParser::SchemaValidator
  class BooleanValidator < Base
    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, 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

16 entries across 16 versions & 1 rubygems

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