From f95a45933ab1d9356300062bde90bdad443e6402 Mon Sep 17 00:00:00 2001 From: William Turner Date: Sat, 11 Jun 2022 16:34:40 -0400 Subject: [PATCH] feat: add input format selection --- mitmproxy2swagger/mitmproxy2swagger.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/mitmproxy2swagger/mitmproxy2swagger.py b/mitmproxy2swagger/mitmproxy2swagger.py index 00374af..6ff429a 100755 --- a/mitmproxy2swagger/mitmproxy2swagger.py +++ b/mitmproxy2swagger/mitmproxy2swagger.py @@ -36,6 +36,12 @@ def progress_callback(progress): console_util.print_progress_bar(progress) +def detect_input_format(file_path): + if har_archive_heuristic(file_path) > mitmproxy_dump_file_huristic(file_path): + return HarCaptureReader(file_path, progress_callback) + return MitmproxyCaptureReader(file_path, progress_callback) + + def main(): parser = argparse.ArgumentParser( description='Converts a mitmproxy dump file or HAR to a swagger schema.') @@ -46,15 +52,20 @@ def main(): parser.add_argument('-p', '--api-prefix', help='The api prefix', required=True) parser.add_argument('-e', '--examples', action='store_true', help='Include examples in the schema. This might expose sensitive information.') + parser.add_argument('-f', '--format', choices=['flow', 'har'], + help='Override the input file format auto-detection.') args = parser.parse_args() yaml = ruamel.yaml.YAML() + caputre_reader = None - # detect the input file type - if har_archive_heuristic(args.input) > mitmproxy_dump_file_huristic(args.input): + if args.format == 'flow': + caputre_reader = MitmproxyCaptureReader(args.input, progress_callback) + elif args.format == 'har': caputre_reader = HarCaptureReader(args.input, progress_callback) else: - caputre_reader = MitmproxyCaptureReader(args.input, progress_callback) + caputre_reader = detect_input_format(args.input) + swagger = None # try loading the existing swagger file