def __validate_inputs(self, kwargs): for param in self.params_map['enum']: if param in kwargs: check_allowed_values( self.allowed_values, (param,), kwargs[param] ) for param in self.params_map['validation']: if param in kwargs: check_validations( self.validations, (param,), kwargs[param], configuration=self.api_client.configuration ) if kwargs['_check_input_type'] is False: return for key, value in kwargs.items(): fixed_val = validate_and_convert_types( value, self.openapi_types[key], [key], False, kwargs['_check_input_type'], configuration=self.api_client.configuration ) kwargs[key] = fixed_val
def __set_item(self, name, value): path_to_item = [] if self._path_to_item: path_to_item.extend(self._path_to_item) path_to_item.append(name) if name in self.openapi_types: required_types_mixed = self.openapi_types[name] elif self.additional_properties_type is None: raise ApiKeyError( "{0} has no key '{1}'".format(type(self).__name__, name), path_to_item ) elif self.additional_properties_type is not None: required_types_mixed = self.additional_properties_type if get_simple_class(name) != str: error_msg = type_error_message( var_name=name, var_value=name, valid_classes=(str,), key_type=True ) raise ApiTypeError( error_msg, path_to_item=path_to_item, valid_classes=(str,), key_type=True ) if self._check_type: value = validate_and_convert_types( value, required_types_mixed, path_to_item, self._from_server, self._check_type, configuration=self._configuration) if (name,) in self.allowed_values: check_allowed_values( self.allowed_values, (name,), value ) if (name,) in self.validations: check_validations( self.validations, (name,), value ) self._data_store[name] = value
def deserialize(self, response, response_type, _check_type): """Deserializes response into an object. :param response: RESTResponse object to be deserialized. :param response_type: For the response, a tuple containing: valid classes a list containing valid classes (for list schemas) a dict containing a tuple of valid classes as the value Example values: (str,) (Pet,) (float, none_type) ([int, none_type],) ({str: (bool, str, int, float, date, datetime, str, none_type)},) :param _check_type: boolean, whether to check the types of the data received from the server :type _check_type: bool :return: deserialized object. """ # handle file downloading # save response body into a tmp file and return the instance if response_type == (file_type,): content_disposition = response.getheader("Content-Disposition") return deserialize_file(response.data, self.configuration, content_disposition=content_disposition) # fetch data from response object try: received_data = json.loads(response.data) except ValueError: received_data = response.data # store our data under the key of 'received_data' so users have some # context if they are deserializing a string and the data type is wrong deserialized_data = validate_and_convert_types( received_data, response_type, ['received_data'], True, _check_type, configuration=self.configuration ) return deserialized_data