lib/datadog_api_client/v2/model_base.rb
# Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
' File ' is missing here because in the regular case we get the data _after_ a call to JSON . parse .
def find_and_cast_into_type(klass, data)
      return if data.nil?
      case klass.to_s
      when 'Boolean'
        return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
      when 'Float'
        return data if data.instance_of?(Float)
      when 'Integer'
        return data if data.instance_of?(Integer)
      when 'Time'
        return Time.parse(data)
      when 'Date'
        return Date.parse(data)
      when 'String'
        return data if data.instance_of?(String)
      when 'Object' 
        return data if data.instance_of?(Hash)
      when /\AArray<(?<sub_type>.+)>\z/ 
        if data.instance_of?(Array)
          sub_type = Regexp.last_match[:sub_type]
          return data.map { |item| find_and_cast_into_type(sub_type, item) }
        end
      when /\AHash<String, (?<sub_type>.+)>\z/  with "additionalProperties: { ... }"
        if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
          sub_type = Regexp.last_match[:sub_type]
          return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
        end
      else 
        const = DatadogAPIClient::V1.const_get(klass)
        if const
          if const.respond_to?(:openapi_one_of) 
            model = const.build(data)
            return model if model
          else
            raise unless (data.keys - const.acceptable_attributes).empty?
            model = const.build_from_hash(data)
            return model if model && model.valid?
          end
        end
      end
      raise 
    rescue
      raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
    end
def find_and_cast_into_type ( klass , data ) return if data . nil? case klass . to_s when 'Boolean' return data if data . instance_of? ( TrueClass ) || data . instance_of? ( FalseClass ) when 'Float' return data if data . instance_of? ( Float ) when 'Integer' return data if data . instance_of? ( Integer ) when 'Time' return Time . parse ( data ) when 'Date' return Date . parse ( data ) when 'String' return data if data . instance_of? ( String ) when 'Object' return data if data . instance_of? ( Hash ) when / \A Array<(?<sub_type>.+)> \z / if data . instance_of? ( Array ) sub_type = Regexp . last_match [ :sub_type ] return data . map { | item | find_and_cast_into_type ( sub_type , item ) } end when / \A Hash<String, (?<sub_type>.+)> \z / if data . instance_of? ( Hash ) && data . keys . all? { | k | k . instance_of? ( Symbol ) || k . instance_of? ( String ) } sub_type = Regexp . last_match [ :sub_type ] return data . each_with_object ( { } ) { | ( k , v ) , hsh | hsh [ k ] = find_and_cast_into_type ( sub_type , v ) } end else const = DatadogAPIClient :: V1 . const_get ( klass ) if const if const . respond_to? ( :openapi_one_of ) model = const . build ( data ) return model if model else raise unless ( data . keys - const . acceptable_attributes ) . empty? model = const . build_from_hash ( data ) return model if model && model . valid? end end end raise rescue raise SchemaMismatchError , "#{data} doesn't match the #{klass} type" end
Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
Note : ' File ' is missing here because in the regular case we get the data _after_ a call to JSON . parse .
# "type: object" # "type: array" # "type: object" with "additionalProperties: { ... }" # model # nested oneOf model # raise if data contains keys that are not known to the model # if no match by now, raise
klass
<not_specific>
data
<not_specific>