Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: JamalZeynalov/swagger-coverage-py
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v.3.4.0
Choose a base ref
...
head repository: JamalZeynalov/swagger-coverage-py
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 7 commits
  • 5 files changed
  • 2 contributors

Commits on Apr 10, 2024

  1. Update reporter.py

    Adding better command handling for subprocess.run
    This function runs the command directly (without going through a shell).
    This fixes issues when folder path containing spaces and avoids shell injection vulnerabilities.
    navchandar authored Apr 10, 2024
    Copy the full SHA
    361bf93 View commit details

Commits on Apr 25, 2024

  1. Add headers support

    JamalZeynalov committed Apr 25, 2024
    Copy the full SHA
    17292fa View commit details
  2. fix

    JamalZeynalov committed Apr 25, 2024
    Copy the full SHA
    ca5ee60 View commit details
  3. fix

    JamalZeynalov committed Apr 25, 2024
    Copy the full SHA
    595edd2 View commit details
  4. Merge pull request #30 from JamalZeynalov/add_headers_support

    Add headers support
    JamalZeynalov authored Apr 25, 2024
    Copy the full SHA
    260ad6b View commit details
  5. Merge pull request #29 from navchandar/reporter-patch-1

    Update reporter.py
    JamalZeynalov authored Apr 25, 2024
    Copy the full SHA
    dac4f10 View commit details
  6. Copy the full SHA
    5c14e5b View commit details
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

setup(
name="swagger-coverage",
version="3.4.0",
version="3.5.1",
author="Jamal Zeinalov",
author_email="jamal.zeynalov@gmail.com",
description='Python adapter for "swagger-coverage" tool',
23 changes: 12 additions & 11 deletions swagger_coverage_py/reporter.py
Original file line number Diff line number Diff line change
@@ -73,27 +73,28 @@ def setup(

def generate_report(self):
inner_location = "swagger-coverage-commandline/bin/swagger-coverage-commandline"

cmd_path = os.path.join(os.path.dirname(__file__), inner_location)
assert Path(
cmd_path
).exists(), (
f"No commandline tools is found in following locations:\n{cmd_path}\n"
)

command = [cmd_path, "-s", self.swagger_doc_file, "-i", self.output_dir]
if self.swagger_coverage_config:
command = f"{cmd_path} -s {self.swagger_doc_file} -i {self.output_dir} -c {self.swagger_coverage_config}"
else:
command = f"{cmd_path} -s {self.swagger_doc_file} -i {self.output_dir}"

command = (
command if platform.system() != "Windows" else command.replace("/", "\\")
)
command.extend(["-c", self.swagger_coverage_config])

# Adjust the file paths for Windows
if platform.system() == "Windows":
command = [arg.replace("/", "\\") for arg in command]

# Suppress all output if not in debug mode
command = command + " > /dev/null 2>&1" if not DEBUG_MODE else command
if not DEBUG_MODE:
with open(os.devnull, 'w') as devnull:
subprocess.run(command, stdout=devnull, stderr=devnull)
else:
subprocess.run(command)

subprocess.run(command, shell=True)

def cleanup_input_files(self):
shutil.rmtree(self.output_dir, ignore_errors=True)
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
@@ -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)

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