lib/apia/argument_set.rb
# This is a constant that represents a missing value where `nil` means
# the user actually wanted to send null/nil.
This is a constant that represents a missing value where `nil` means
the user actually wanted to send null/nil.
This is a constant that represents a missing value where ` nil ` means the user actually wanted to send null / nil .
def parse_value(argument, value, index: nil, in_array: false)
      if value.nil?
        nil
      elsif argument.array? && value.is_a?(Array)
        value.each_with_index.map do |v, i|
          parse_value(argument, v, index: i, in_array: true)
        end
      elsif argument.array? && !in_array
        raise InvalidArgumentError.new(argument, issue: :array_expected, index: index, path: @path + [argument])
      elsif argument.type.scalar?
        begin
          type = argument.type.klass.parse(value)
        rescue Apia::ParseError => e
          raise InvalidArgumentError.new(argument, issue: :parse_error, errors: [e.message], index: index, path: @path + [argument])
        end
        unless argument.type.klass.valid?(type)
          raise InvalidArgumentError.new(argument, issue: :invalid_scalar, index: index, path: @path + [argument])
        end
        type
      elsif argument.type.argument_set?
        unless value.is_a?(Hash)
          raise InvalidArgumentError.new(argument, issue: :object_expected, index: index, path: @path + [argument])
        end
        value = argument.type.klass.new(value, path: @path + [argument], request: @request)
        value.validate(argument, index: index)
        value
      elsif argument.type.enum?
        unless argument.type.klass.definition.values[value]
          raise InvalidArgumentError.new(argument, issue: :invalid_enum_value, index: index, path: @path + [argument])
        end
        value
      end
    end
def parse_value ( argument , value , index : nil , in_array : false ) if value . nil? nil elsif argument . array? && value . is_a? ( Array ) value . each_with_index . map do | v , i | parse_value ( argument , v , index : i , in_array : true ) end elsif argument . array? && ! in_array raise InvalidArgumentError . new ( argument , issue : :array_expected , index : index , path : @path + [ argument ] ) elsif argument . type . scalar? begin type = argument . type . klass . parse ( value ) rescue Apia :: ParseError => e raise InvalidArgumentError . new ( argument , issue : :parse_error , errors : [ e . message ] , index : index , path : @path + [ argument ] ) end unless argument . type . klass . valid? ( type ) raise InvalidArgumentError . new ( argument , issue : :invalid_scalar , index : index , path : @path + [ argument ] ) end type elsif argument . type . argument_set? unless value . is_a? ( Hash ) raise InvalidArgumentError . new ( argument , issue : :object_expected , index : index , path : @path + [ argument ] ) end value = argument . type . klass . new ( value , path : @path + [ argument ] , request : @request ) value . validate ( argument , index : index ) value elsif argument . type . enum? unless argument . type . klass . definition . values [ value ] raise InvalidArgumentError . new ( argument , issue : :invalid_enum_value , index : index , path : @path + [ argument ] ) end value end end
This is a constant that represents a missing value where `nil` means
the user actually wanted to send null/nil.
This is a constant that represents a missing value where ` nil ` means the user actually wanted to send null / nil .
# If we cannot parse the given input, this is cause for a parse error to be raised. # If value we have parsed is not actually valid, we 'll raise an argument error. # In most cases, it is likely that an integer has been provided to string etc...
argument
<not_specific>
value
<not_specific>
index
<not_specific>
in_array
<not_specific>