diff --git a/setup.py b/setup.py index 9b3ce18..f1aed4f 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="swagger-coverage", - version="3.4.0", + version="3.5.0", author="Jamal Zeinalov", author_email="jamal.zeynalov@gmail.com", description='Python adapter for "swagger-coverage" tool', diff --git a/swagger_coverage_py/results_writers/base_schemas_manager.py b/swagger_coverage_py/results_writers/base_schemas_manager.py index 4b4e870..01248fa 100644 --- a/swagger_coverage_py/results_writers/base_schemas_manager.py +++ b/swagger_coverage_py/results_writers/base_schemas_manager.py @@ -17,7 +17,7 @@ def __init__(self, uri: URI, response: Response, kwargs: dict, method: str = Non self._uri = uri self._method = method self._response: Response = response - self.__other_request_params = kwargs + self._other_request_params = kwargs def _get_path_params(self) -> list: params_ = [] @@ -96,26 +96,37 @@ def _get_body_params(self): return request_body - def _get_query_params(self) -> list: - q_params = list(self.__other_request_params.get("params", {}).items()) + def _get_other_request_params(self, params_key: str, params_in: str) -> list: + prams_raw = self._other_request_params.get(params_key, {}) + if prams_raw: + params = list(prams_raw.items()) + else: + params = [] + raw = self._uri.raw.split("?") if len(raw) > 1: - q_params += [tuple(x.split("=")) for x in str(raw[1]).split("&")] - if not q_params: + params += [tuple(x.split("=")) for x in str(raw[1]).split("&")] + if not params: return [] params_ = [] - for key, value in q_params: + for key, value in params: params_.append( { "name": key, - "in": "query", + "in": params_in, "required": False, "x-example": urllib.parse.unquote(str(value)), } ) return params_ + def _get_query_params(self) -> list: + return self._get_other_request_params(params_key="params", params_in="query") + + def _get_header_params(self) -> list: + return self._get_other_request_params(params_key="headers", params_in="header") + def __get_output_subdir(self): return re.match(r"(^\w*)://(.*)", self._uri.host).group(2) diff --git a/swagger_coverage_py/results_writers/openapi_schemas_manager.py b/swagger_coverage_py/results_writers/openapi_schemas_manager.py index 20da466..542b801 100644 --- a/swagger_coverage_py/results_writers/openapi_schemas_manager.py +++ b/swagger_coverage_py/results_writers/openapi_schemas_manager.py @@ -11,10 +11,15 @@ def __init__(self, uri: URI, method: str, response: Response, kwargs: dict): def _paths(self): path_ = self._uri.raw.split("?")[0] + params = ( + self._get_path_params() + + self._get_query_params() + + self._get_header_params() + ) dict_ = { path_: { self._method: { - "parameters": self._get_path_params() + self._get_query_params(), + "parameters": params, "responses": {self._response.status_code: {}}, } } diff --git a/swagger_coverage_py/results_writers/swagger_schemas_manager.py b/swagger_coverage_py/results_writers/swagger_schemas_manager.py index 92f9eb8..89e0d5d 100644 --- a/swagger_coverage_py/results_writers/swagger_schemas_manager.py +++ b/swagger_coverage_py/results_writers/swagger_schemas_manager.py @@ -29,7 +29,10 @@ def __produces(self) -> list: def _paths(self): path_ = self._uri.raw.split("?")[0] params = ( - self._get_path_params() + self._get_query_params() + self._get_body_params() + self._get_path_params() + + self._get_query_params() + + self._get_body_params() + + self._get_header_params() ) dict_ = { path_: {