$ show alufers/mitmproxy2swagger
mitmproxy2swagger is a CLI tool that automatically converts HTTP traffic captures from mitmproxy or browser HAR exports into OpenAPI 3.0 specifications. It enables reverse-engineering REST APIs by analyzing recorded traffic without manual inspection. The tool uses a two-pass workflow: the first pass identifies API paths and generates a template file with parameter placeholders; after the user edits the template to select endpoints, the second pass produces full endpoint descriptions with inferred request/response schemas. Architecturally, the tool is a single-purpose Python application organized into modular components: input readers (mitmproxy_capture_reader.py for binary flow files, har_capture_reader.py for HAR JSON), a core orchestration module (mitmproxy2swagger.py) that handles argument parsing, format auto-detection, and schema merging, and utility modules (swagger_util.py for OpenAPI schema generation, console_util.py for progress display). The tool supports multiple content types (JSON, msgpack, form-urlencoded) and can optionally include example data and headers in the output. Key entry points are the `mitmproxy2swagger` command with arguments for input file, output path, API prefix, and optional flags. External dependencies include mitmproxy for reading flow files, ruamel.yaml for YAML output, json-stream for streaming HAR parsing, and msgpack for msgpack support. The codebase is well-maintained with CI/CD, tests, Docker support, and pre-commit hooks.
The LLM identified 2 files worth highlighting for reuse:
Provides functions to infer OpenAPI schema components from raw Python values (dicts, lists, primitives). Includes logic to detect generic dictionary keys (numeric strings, UUIDs) and generate additionalProperties schemas instead of enumerating keys, which is crucial for scalable API documentation. Also includes URL parameter extraction and endpoint name generation from path templates. This module is self-contained (only uses standard library) and can be extracted for any project needing to generate OpenAPI schemas from sample data.
Implements a colorful, animated progress bar using ANSI escape codes with rainbow color interpolation. The progress bar uses Unicode block characters for smooth rendering. It is a self-contained utility (only depends on sys) that can be reused in any Python CLI application to provide visual feedback during long operations.