Skip to content

Commit

Permalink
Merge pull request #30 from JamalZeynalov/add_headers_support
Browse files Browse the repository at this point in the history
Add headers support
  • Loading branch information
JamalZeynalov authored Apr 25, 2024
2 parents 0c55656 + 595edd2 commit 260ad6b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="swagger-coverage",
version="3.4.0",
version="3.5.0",
author="Jamal Zeinalov",
author_email="[email protected]",
description='Python adapter for "swagger-coverage" tool',
Expand Down
25 changes: 18 additions & 7 deletions swagger_coverage_py/results_writers/base_schemas_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_ = []
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_: {
Expand Down

0 comments on commit 260ad6b

Please sign in to comment.