def _get_parameters(self, definition, method): p = {} if definition.get("requestBody"): schema = copy.deepcopy(definition.get("requestBody")["content"]["application/json"]["schema"]) if schema["type"] == "object": body_parameters = {} for k, v in schema["properties"].items(): v["in"] = "body" v["required"] = k in schema.get("required", {}) body_parameters.update({k: v}) p.update(body_parameters) p.update(utils.parameter_transform(definition.get("parameters"))) return p
def _api_call(*args, **kwargs): method_headers = kwargs.pop('headers') if kwargs.get( 'headers') else {} parameter_map = utils.parameter_transform(definition.get('params')) self._validate(kwargs, parameter_map) method = definition['method'].lower() requests_kwargs = {'headers': self._get_headers(method_headers)} url, data_kwargs = self._form_url(kwargs, definition['path'], parameter_map) requests_kwargs.update( self._data(data_kwargs, parameter_map, method)) requests_kwargs.update(self._auth(requests_kwargs)) _response = getattr(requests, method)(url, **requests_kwargs) try: attributes = _response.json() except ValueError: attributes = _response.text new_self = copy.deepcopy(self) setattr(new_self, '_response', _response) setattr(new_self, 'json', attributes) setattr(new_self, 'response', new_self._convert_to_object(attributes)) return new_self