docs: add docs for HAR support

pull/6/head
alufers 2 years ago
parent b5a0fb5b88
commit 561ebdfc25

@ -7,6 +7,13 @@ https://user-images.githubusercontent.com/5400940/168086818-c48f60ab-3f95-42eb-b
A tool for automatically converting [mitmproxy](https://mitmproxy.org/) captures to [OpenAPI 3.0](https://swagger.io/specification/) specifications. This means that you can automatically reverse-engineer REST APIs by just running the apps and capturing the traffic.
---
**🆕 NEW!**
Added support for processing HAR exported from the browser DevTools. See [Usage - HAR](#har) for more details.
---
## Installation
First you will need python3 and pip3.
@ -21,6 +28,8 @@ Then clone the repo and run `mitmproxy2swagger` as per examples below.
## Usage
### Mitmproxy
To create a specification by inspecting HTTP traffic you will need to:
1. Capture the traffic by using the mitmproxy tool. I personally recommend using mitmweb, which is a web interface built-in to mitmproxy.
@ -89,6 +98,15 @@ To create a specification by inspecting HTTP traffic you will need to:
Passing `--examples` will add example data to requests and responses. Take caution when using this option, as it may add sensitive data (tokens, passwords, personal information etc.) to the schema.
### HAR
1. Capture and export the traffic from the browser DevTools.
In the browser DevTools, go to the Network tab and click the "Export HAR" button.
![A screenshot showing where the export har button is located](./docs/export_har_button.png)
2. Continue the same way you would do with the mitmproxy dump. `mitmproxy2swagger` will automatically detect the HAR file and process it.
## Example output
See the [examples](./example_outputs/). You will find a generated schema there and an html file with the generated documentation (via [redoc-cli](https://www.npmjs.com/package/redoc-cli)).

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

@ -38,9 +38,9 @@ def set_key_if_not_exists(dict, key, value):
def main():
parser = argparse.ArgumentParser(
description='Converts a mitmproxy dump file to a swagger schema.')
description='Converts a mitmproxy dump file or HAR to a swagger schema.')
parser.add_argument(
'-i', '--input', help='The input mitmproxy dump file', required=True)
'-i', '--input', help='The input mitmproxy dump file or HAR dump file (from DevTools)', required=True)
parser.add_argument(
'-o', '--output', help='The output swagger schema file (yaml). If it exists, new endpoints will be added', required=True)
parser.add_argument('-p', '--api-prefix', help='The api prefix', required=True)
@ -94,10 +94,6 @@ def main():
# new endpoints will be added here so that they can be added as comments in the swagger file
new_path_templates = []
path_template_regexes = [re.compile(path_to_regex(path))
for path in path_templates]

Loading…
Cancel
Save