Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions swagger_coverage_py/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, api_name: str, host: str, verify: bool = True):

def __get_output_dir(self):
output_dir = "swagger-coverage-output"
subdir = re.match(r"(^\w*)://(.*)", self.host).group(2)
subdir = re.match(r"(^\w*)://(.*)", self.host).group(2).replace(".", "_").replace(":", "_")
return f"{output_dir}/{subdir}"

def __get_ignored_paths_from_config(self) -> List[str]:
Expand Down Expand Up @@ -72,29 +72,24 @@ 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]
base_dir = os.path.join(os.path.dirname(__file__), "swagger-coverage-commandline")
lib_path = os.path.join(base_dir, "lib", "*")

classpath = lib_path.replace("/", os.sep)
command = [
"java",
"-cp", classpath,
"com.github.viclovsky.swagger.coverage.CommandLine",
"-s", self.swagger_doc_file,
"-i", self.output_dir,
]
if self.swagger_coverage_config:
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
if not DEBUG_MODE:
with open(os.devnull, 'w') as devnull:
subprocess.run(command, stdout=devnull, stderr=devnull)
subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
else:
subprocess.run(command)

subprocess.run(command, check=True)

def cleanup_input_files(self):
shutil.rmtree(self.output_dir, ignore_errors=True)
Expand Down
4 changes: 3 additions & 1 deletion swagger_coverage_py/results_writers/base_schemas_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import pathlib
import platform
import re
import urllib
Expand Down Expand Up @@ -128,7 +129,7 @@ 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)
return re.match(r"(^\w*)://(.*)", self._uri.host).group(2).replace(".", "_").replace(":", "_")

def write_schema(self):
schema_dict = self._get_schema()
Expand All @@ -137,6 +138,7 @@ def write_schema(self):
"/", "-"
).replace(":", "_")
path_ = f"swagger-coverage-output/{self.__get_output_subdir()}"
pathlib.Path(path_).mkdir(parents=True, exist_ok=True)
file_path = f"{path_}/{file_name}".split("?")[0]
file_path = f"{file_path} ({rnd}).{API_DOCS_FORMAT}"

Expand Down