diff --git a/test/api/checkAPI.py b/test/api/checkAPI.py index 09220a41..d0a1bf2e 100644 --- a/test/api/checkAPI.py +++ b/test/api/checkAPI.py @@ -9,13 +9,17 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. +import sys +import trace from libs.openAPI import openApi from libs.FTLAPI import FTLAPI from libs.responseVerifyer import ResponseVerifyer -if __name__ == "__main__": +TRACE = False + +def main(): # OpenAPI specs are split into multiple files, this script extracts the endpoints from them - openapi = openApi(base_path = "src/api/docs/content/specs/", api_root = "/api") + openapi = openApi(base_path = "src/api/docs/content/specs/", api_root = "/api", trace = TRACE) if not openapi.parse("main.yaml"): exit(1) @@ -110,4 +114,22 @@ if __name__ == "__main__": # If there are no errors, exit with success print("Everything okay!") - exit(0) + #exit(0) + +if __name__ == "__main__": + if TRACE: + tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix], + trace=1, count=1) + tracer.run('main()') + + # make a report, placing output in the current directory + r = tracer.results() + print(r.write_results(show_missing=True, coverdir=".")) + + # Exit with success + exit(0) + else: + main() + + # Exit with success + exit(0) diff --git a/test/api/libs/openAPI.py b/test/api/libs/openAPI.py index 0cec4596..1eddcc03 100644 --- a/test/api/libs/openAPI.py +++ b/test/api/libs/openAPI.py @@ -17,10 +17,11 @@ class openApi(): # List of methods we want to extract METHODS = ["get", "post", "put", "patch", "delete"] - def __init__(self, base_path: str, api_root: str = "/api") -> None: + def __init__(self, base_path: str, api_root: str = "/api", trace: bool = False) -> None: # Store arguments self.base_path = base_path self.api_root = api_root + self.TRACE = trace # Prepare list of YAML endpoints self.endpoints = {} @@ -83,6 +84,8 @@ class openApi(): for a in dict_in.keys(): # Create the next dict key next_dict_key = dict_key + "/" + a if len(dict_key) > 0 else a + if self.TRACE: + print("Resolving " + next_dict_key) # If the item is a dict, we check if it is a reference if isinstance(dict_in[a], dict): # Check if this is a reference @@ -108,6 +111,11 @@ class openApi(): else: # No reference, just recurse into the next level self.recurseRef(dict_in[a][i], next_dict_key) + else: + # If it is not a dict or list, we do not need to do anything + if self.TRACE: + print(f"Not recursing into {next_dict_key} as it is not a dict or list: {type(dict_in[a])}") + pass def parse(self, filename: str): @@ -116,7 +124,7 @@ class openApi(): # Get the paths self.paths = self.read_yaml_maybe_cache(self.base_path + filename)["paths"] except Exception as e: - print("Exception when trying to read " + e) + print("Exception when trying to read " + str(e)) return False # Recursively resolve references in the paths