https://github.com/perrym/postman-to-swagger
postman to swagger
https://github.com/perrym/postman-to-swagger
postman postman-to-swagger swagger
Last synced: about 2 months ago
JSON representation
postman to swagger
- Host: GitHub
- URL: https://github.com/perrym/postman-to-swagger
- Owner: perrym
- License: other
- Created: 2025-06-01T09:07:23.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-11-23T13:22:05.000Z (7 months ago)
- Last Synced: 2025-11-23T15:10:42.685Z (7 months ago)
- Topics: postman, postman-to-swagger, swagger
- Language: Python
- Homepage:
- Size: 58.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Postman to Swagger Converter by Perry Mertens pamsniffer@gmail.com (C)2025
This project converts a Postman v2.1 collection to an OpenAPI 3.0 spec and serves it with a lightweight web preview.
##License AGPL-v3.0
## 1) Requirements
- Python 3.9+
- Optional (for YAML output): `pip install pyyaml`
## 2) Convert your Postman collection
```bash
python postman-to-swagger.py --postman Collection.postman_collection.json --env postmanenvironment.json --output test --json-only
```
Outputs: `test.json` (and `test.yaml` if you omit `--json-only` and have PyYAML).
**Environment usage:** any enabled key in `postmanenvironment.json` that matches a server variable (e.g. `token_host`) becomes the default in `servers[0].variables` of the spec.
## 3) Quick preview options
### A) Open the generated spec file
```bash
python postman-to-swagger.py --postman Collection.postman_collection.json --output test --open-ui
```
This opens the raw JSON in your default browser (no UI).
### B) Start a tiny web server and use Swagger UI
```bash
python postman-to-swagger.py --postman Collection.postman_collection.json --env postmanenvironment.json --output test --json-only --serve
```
Then open:
```
http://localhost:8000/index.html?spec=test.json
```
> The built-in server serves the folder; it opens the spec file by default, but you can manually navigate to `index.html` for the Swagger UI.
Alternatively, you can use Python’s standard server:
```bash
python -m http.server 8000
# then browse to http://localhost:8000/index.html?spec=test.json
```
## 4) Tips
- Use `--yaml-only` or `--json-only` to control output format (default is both if neither is passed).
- The converter normalizes paths (`{{var}}` → `{var}`), pulls request/response bodies into components, and de-duplicates parameters.
## 5) Troubleshooting
- **`Invalid Postman structure`**: ensure you exported a **collection v2.1**, not an environment.
- **No server defaults**: pass `--env postmanenvironment.json` and confirm the keys are enabled.
- **Want multiple modules**: run the converter per subfolder and choose different `--output` names (e.g., `policy.json`, `claim.json`).