swagger2drawio 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. swagger2drawio-1.0.0/.gitignore +67 -0
  2. swagger2drawio-1.0.0/CHANGELOG.md +96 -0
  3. swagger2drawio-1.0.0/LICENSE +21 -0
  4. swagger2drawio-1.0.0/PKG-INFO +274 -0
  5. swagger2drawio-1.0.0/README.md +221 -0
  6. swagger2drawio-1.0.0/config.yaml +46 -0
  7. swagger2drawio-1.0.0/pyproject.toml +138 -0
  8. swagger2drawio-1.0.0/swagger2drawio/__init__.py +3 -0
  9. swagger2drawio-1.0.0/swagger2drawio/_logging.py +73 -0
  10. swagger2drawio-1.0.0/swagger2drawio/cli.py +464 -0
  11. swagger2drawio-1.0.0/swagger2drawio/config_loader.py +258 -0
  12. swagger2drawio-1.0.0/swagger2drawio/diff.py +279 -0
  13. swagger2drawio-1.0.0/swagger2drawio/exceptions.py +65 -0
  14. swagger2drawio-1.0.0/swagger2drawio/layout/__init__.py +1 -0
  15. swagger2drawio-1.0.0/swagger2drawio/layout/graph_engine.py +599 -0
  16. swagger2drawio-1.0.0/swagger2drawio/layout/strategies.py +204 -0
  17. swagger2drawio-1.0.0/swagger2drawio/parser/__init__.py +1 -0
  18. swagger2drawio-1.0.0/swagger2drawio/parser/base.py +87 -0
  19. swagger2drawio-1.0.0/swagger2drawio/parser/openapi_parser.py +912 -0
  20. swagger2drawio-1.0.0/swagger2drawio/refs.py +261 -0
  21. swagger2drawio-1.0.0/swagger2drawio/renderer/__init__.py +1 -0
  22. swagger2drawio-1.0.0/swagger2drawio/renderer/diff_renderer.py +470 -0
  23. swagger2drawio-1.0.0/swagger2drawio/renderer/drawio_builder.py +224 -0
  24. swagger2drawio-1.0.0/swagger2drawio/themes/dark.yaml +43 -0
  25. swagger2drawio-1.0.0/swagger2drawio/themes/high-contrast.yaml +43 -0
  26. swagger2drawio-1.0.0/swagger2drawio/themes/light.yaml +43 -0
  27. swagger2drawio-1.0.0/swagger2drawio/themes/pastel.yaml +43 -0
  28. swagger2drawio-1.0.0/swagger2drawio/validator.py +40 -0
  29. swagger2drawio-1.0.0/tests/__init__.py +0 -0
  30. swagger2drawio-1.0.0/tests/conftest.py +76 -0
  31. swagger2drawio-1.0.0/tests/fixtures/circular.json +28 -0
  32. swagger2drawio-1.0.0/tests/fixtures/composition.json +53 -0
  33. swagger2drawio-1.0.0/tests/fixtures/custom_config.yaml +8 -0
  34. swagger2drawio-1.0.0/tests/fixtures/invalid_spec.json +11 -0
  35. swagger2drawio-1.0.0/tests/fixtures/malformed.json +1 -0
  36. swagger2drawio-1.0.0/tests/fixtures/minimal.json +6 -0
  37. swagger2drawio-1.0.0/tests/fixtures/petstore_oas3.json +137 -0
  38. swagger2drawio-1.0.0/tests/fixtures/petstore_oas3.yaml +35 -0
  39. swagger2drawio-1.0.0/tests/fixtures/petstore_oas3_v2.json +139 -0
  40. swagger2drawio-1.0.0/tests/fixtures/swagger2.json +45 -0
  41. swagger2drawio-1.0.0/tests/test_cli.py +229 -0
  42. swagger2drawio-1.0.0/tests/test_composition.py +111 -0
  43. swagger2drawio-1.0.0/tests/test_config_loader.py +135 -0
  44. swagger2drawio-1.0.0/tests/test_diff.py +211 -0
  45. swagger2drawio-1.0.0/tests/test_exceptions.py +108 -0
  46. swagger2drawio-1.0.0/tests/test_info_security.py +80 -0
  47. swagger2drawio-1.0.0/tests/test_layout.py +287 -0
  48. swagger2drawio-1.0.0/tests/test_logging.py +129 -0
  49. swagger2drawio-1.0.0/tests/test_network.py +184 -0
  50. swagger2drawio-1.0.0/tests/test_openapi_parser.py +519 -0
  51. swagger2drawio-1.0.0/tests/test_parser_protocol.py +94 -0
  52. swagger2drawio-1.0.0/tests/test_refs.py +180 -0
  53. swagger2drawio-1.0.0/tests/test_renderer.py +115 -0
  54. swagger2drawio-1.0.0/tests/test_strategies.py +110 -0
  55. swagger2drawio-1.0.0/tests/test_themes_init.py +162 -0
  56. swagger2drawio-1.0.0/tests/test_validator.py +131 -0
@@ -0,0 +1,67 @@
1
+ # ── Python ────────────────────────────────────────────────────
2
+ __pycache__/
3
+ *.py[oc]
4
+ *.pyd
5
+ *.pyo
6
+ build/
7
+ dist/
8
+ wheels/
9
+ *.egg-info/
10
+ *.egg
11
+ MANIFEST
12
+
13
+ # ── Virtual environments ──────────────────────────────────────
14
+ .venv/
15
+ venv/
16
+ env/
17
+ .env/
18
+
19
+ # ── UV ────────────────────────────────────────────────────────
20
+ .python-version
21
+ uv.lock
22
+
23
+ # ── Distribution / packaging ──────────────────────────────────
24
+ *.tar.gz
25
+ *.whl
26
+ site/
27
+
28
+ # ── Testing ───────────────────────────────────────────────────
29
+ .pytest_cache/
30
+ .coverage
31
+ .coverage.*
32
+ htmlcov/
33
+ coverage.xml
34
+ *.lcov
35
+ .tox/
36
+ .nox/
37
+
38
+ # ── Type checking ─────────────────────────────────────────────
39
+ .mypy_cache/
40
+ .pyright/
41
+ .ruff_cache/
42
+
43
+ # ── Generated Draw.io output ──────────────────────────────────
44
+ # Keep example specs but ignore generated diagrams
45
+ examples/output/
46
+
47
+ # ── IDEs & editors ────────────────────────────────────────────
48
+ .vscode/
49
+ .idea/
50
+ *.swp
51
+ *.swo
52
+ *~
53
+ .DS_Store
54
+ Thumbs.db
55
+
56
+ # ── Environment variables ─────────────────────────────────────
57
+ .env
58
+ .envrc
59
+ *.env.local
60
+
61
+ # ── Logs ──────────────────────────────────────────────────────
62
+ *.log
63
+ logs/
64
+
65
+ # ── OS ────────────────────────────────────────────────────────
66
+ .DS_Store
67
+ desktop.ini
@@ -0,0 +1,96 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [1.0.0] — 2026-05-17
11
+
12
+ First stable release. The CLI surface (`generate`, `validate`, `diff`,
13
+ `init`, `themes list / show`), the typed exception hierarchy + exit
14
+ codes, the bundled themes, and the `swagger2drawio.layouts` entry-point
15
+ group are all considered API stable.
16
+
17
+ ### Added — Phase 5 (Code Quality)
18
+
19
+ - `SpecParser` `Protocol` and `get_parser(raw_dict)` factory for parser
20
+ polymorphism (`swagger2drawio/parser/base.py`).
21
+ - `OpenAPIParser.parse_dict()` + `OpenAPIParser.from_dict_factory()` so
22
+ callers with an in-memory spec can skip the I/O layer.
23
+ - `LayoutStrategy` Protocol with two built-in strategies
24
+ (`HierarchicalBFSLayout`, `GridLayout`) and entry-point discovery
25
+ through the `swagger2drawio.layouts` group.
26
+ - `--layout` CLI flag and `build_endpoint_graph(layout=...)` parameter.
27
+
28
+ ### Changed — Phase 5
29
+
30
+ - All diff dataclasses now use `slots=True`.
31
+ - `Parameter.__post_init__` validates `in` against the OpenAPI
32
+ location set; `MethodDetail.__post_init__` validates `verb` against
33
+ the HTTP-method set.
34
+ - `mypy --strict` now passes on the whole package, not just the
35
+ parser / layout subpackages.
36
+
37
+ ### Added — Phase 4 (CLI & UX)
38
+
39
+ - Bundled themes: `light`, `dark`, `pastel`, `high-contrast` under
40
+ `swagger2drawio/themes/*.yaml`.
41
+ - `--theme <name>` flag on `generate`.
42
+ - `themes list` and `themes show <name>` subcommands.
43
+ - `init` subcommand that scaffolds a `.swagger2drawio.yaml` in CWD.
44
+ - Config discovery order: `--config` → `--theme` →
45
+ `./.swagger2drawio.yaml` → `$XDG_CONFIG_HOME/swagger2drawio/config.yaml`
46
+ → built-in defaults (deep-merged).
47
+ - `rich.progress` spinner + bar during `generate`, with a final summary
48
+ line: `<file> written (X.X KB) — N path(s), M method(s), K schema(s)`.
49
+ - Shell completion via Typer's `--install-completion` / `--show-completion`.
50
+
51
+ ### Added — Phase 3 (Feature Expansion)
52
+
53
+ - Richer endpoint rendering: parameters, request-body and response-ref
54
+ links, deprecated flag, request/response refs inline in the method
55
+ label, height auto-scales with content.
56
+ - Tag-based grouping (`--group-by tag|path|auto`).
57
+ - Schema composition: `allOf` / `oneOf` / `anyOf` / `discriminator`
58
+ edges with distinct styles; enum types rendered as `«enum»` nodes.
59
+ - Security legend (`securitySchemes` → standalone node) and an info
60
+ banner on the root with title / version / description / server URLs.
61
+ - **Diff mode** — new `swagger2drawio diff OLD NEW` subcommand
62
+ producing a three-page (`Summary` / `Endpoints` / `Schemas`)
63
+ side-by-side `.drawio` with green/red/yellow overlays and dashed
64
+ connectors between changed pairs.
65
+
66
+ ### Added — Phase 2 (Robustness)
67
+
68
+ - Typed exception hierarchy (`Swagger2DrawioError` and six subclasses)
69
+ with a stable per-category exit code map (`EXIT_CODE`, codes 1–7).
70
+ - `openapi-spec-validator` integration. New `validate` subcommand and
71
+ a `--no-validate` flag on `generate` (validation is on by default).
72
+ - `RefResolver` inlines external file / remote URL `$ref`s into
73
+ `components.schemas` with cycle safety and per-document caching.
74
+ - Network options on `generate`: `--timeout`, `--header / -H`
75
+ (repeatable), `--insecure`.
76
+ - Rich-based logging: `--verbose / -v` (count), `--quiet / -q`,
77
+ `--log-file <path>`.
78
+
79
+ ### Changed — Phase 2
80
+
81
+ - **Breaking** — `--version` no longer has the `-v` short alias.
82
+ `-v` is now `--verbose` (count). `--version` still works.
83
+
84
+ ### Added — Phase 1 (Foundations)
85
+
86
+ - Modern packaging via `hatchling` with dynamic version from
87
+ `swagger2drawio/__init__.py`.
88
+ - Test infrastructure: 96.7% coverage on parser/layout/renderer.
89
+ - `ruff` + `mypy` + `pre-commit` configuration.
90
+ - GitHub Actions CI (Python 3.10 × 3 OS matrix) and trusted-publishing
91
+ release workflow.
92
+
93
+ ## [0.1.0] — 2026-02-20
94
+
95
+ Initial public release. Single `generate` command. OAS 3 + Swagger 2
96
+ support. Two-page output (Endpoints Map, Schema Map).
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Abhishek Kumar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,274 @@
1
+ Metadata-Version: 2.4
2
+ Name: swagger2drawio
3
+ Version: 1.0.0
4
+ Summary: Generate structured Draw.io diagrams from OpenAPI 3.x / Swagger 2.0 specs.
5
+ Project-URL: Homepage, https://github.com/Abhishek-k03/swagger2drawio
6
+ Project-URL: Repository, https://github.com/Abhishek-k03/swagger2drawio
7
+ Project-URL: Issues, https://github.com/Abhishek-k03/swagger2drawio/issues
8
+ Project-URL: Changelog, https://github.com/Abhishek-k03/swagger2drawio/blob/main/CHANGELOG.md
9
+ Project-URL: Documentation, https://Abhishek-k03.github.io/swagger2drawio/
10
+ Author-email: Abhishek Kumar <thehypnoticsilence@gmail.com>
11
+ Maintainer-email: Abhishek Kumar <thehypnoticsilence@gmail.com>
12
+ License: MIT
13
+ License-File: LICENSE
14
+ Keywords: api,diagram,documentation,drawio,openapi,swagger,visualization
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Environment :: Console
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: License :: OSI Approved :: MIT License
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Programming Language :: Python
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Topic :: Documentation
27
+ Classifier: Topic :: Software Development :: Documentation
28
+ Classifier: Topic :: Utilities
29
+ Classifier: Typing :: Typed
30
+ Requires-Python: >=3.10
31
+ Requires-Dist: drawpyo>=0.2.0
32
+ Requires-Dist: networkx>=3.0
33
+ Requires-Dist: openapi-spec-validator>=0.7
34
+ Requires-Dist: pyyaml>=6.0
35
+ Requires-Dist: requests>=2.31
36
+ Requires-Dist: rich>=13.0
37
+ Requires-Dist: typer>=0.12
38
+ Provides-Extra: dev
39
+ Requires-Dist: mypy>=1.11; extra == 'dev'
40
+ Requires-Dist: pre-commit>=3.8; extra == 'dev'
41
+ Requires-Dist: pytest-cov>=5; extra == 'dev'
42
+ Requires-Dist: pytest>=8; extra == 'dev'
43
+ Requires-Dist: ruff>=0.6; extra == 'dev'
44
+ Requires-Dist: types-pyyaml; extra == 'dev'
45
+ Requires-Dist: types-requests; extra == 'dev'
46
+ Provides-Extra: docs
47
+ Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
48
+ Requires-Dist: mkdocs-typer>=0.0.3; extra == 'docs'
49
+ Provides-Extra: test
50
+ Requires-Dist: pytest-cov>=5; extra == 'test'
51
+ Requires-Dist: pytest>=8; extra == 'test'
52
+ Description-Content-Type: text/markdown
53
+
54
+ # swagger2drawio
55
+
56
+ [![CI](https://github.com/Abhishek-k03/swagger2drawio/actions/workflows/ci.yml/badge.svg)](https://github.com/Abhishek-k03/swagger2drawio/actions/workflows/ci.yml)
57
+ [![PyPI version](https://img.shields.io/pypi/v/swagger2drawio.svg)](https://pypi.org/project/swagger2drawio/)
58
+ [![Python versions](https://img.shields.io/pypi/pyversions/swagger2drawio.svg)](https://pypi.org/project/swagger2drawio/)
59
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
60
+
61
+ > Turn an OpenAPI 3.x / Swagger 2.0 spec into a clean, structured
62
+ > [draw.io](https://app.diagrams.net/) diagram. Local files, remote
63
+ > URLs, multi-file `$ref`s — all in one command.
64
+
65
+ ```text
66
+ $ swagger2drawio generate -i petstore.yaml -o api.drawio
67
+ ✔ api.drawio written (12.4 KB) — 8 path(s), 14 method(s), 6 schema(s).
68
+ ```
69
+
70
+ Open `api.drawio` in [diagrams.net](https://app.diagrams.net/) and you
71
+ get a two-page (or three-page in diff mode) view of your API.
72
+
73
+ ---
74
+
75
+ ## Why this exists
76
+
77
+ API specs are easy to write and impossible to keep in your head once
78
+ they grow past a handful of endpoints. swagger2drawio gives you a
79
+ visual map you can annotate, share, and diff — without leaving the
80
+ spec as the source of truth.
81
+
82
+ ## Features
83
+
84
+ - **Two-page output**: an endpoints tree (root → tag → path → method)
85
+ and an ER-style schema map with `$ref` relationships.
86
+ - **OpenAPI 3.x and Swagger 2.0** — auto-detected.
87
+ - **Rich method labels**: parameters, request/response refs,
88
+ deprecated badge, summary.
89
+ - **Schema composition**: `allOf` / `oneOf` / `anyOf` /
90
+ `discriminator` get distinct edge styles; enums render as their own
91
+ `«enum»` nodes.
92
+ - **Spec validation** powered by `openapi-spec-validator` (skippable
93
+ with `--no-validate`).
94
+ - **External `$ref` resolution**: relative-file and remote-URL
95
+ pointers are fetched and inlined; circular refs terminate cleanly.
96
+ - **`diff` subcommand** — compare two spec versions and get a
97
+ green/red/yellow side-by-side change report. The headline feature.
98
+ - **Bundled themes**: `light`, `dark`, `pastel`, `high-contrast`.
99
+ - **Pluggable layouts** via the `swagger2drawio.layouts` entry point.
100
+
101
+ ## Install
102
+
103
+ ```bash
104
+ # With uv (recommended)
105
+ uvx swagger2drawio --version
106
+
107
+ # With pip
108
+ pip install swagger2drawio
109
+ ```
110
+
111
+ Requires Python 3.10+.
112
+
113
+ ## Quick start
114
+
115
+ ```bash
116
+ # Generate a diagram from a local spec
117
+ swagger2drawio generate -i openapi.yaml -o api.drawio
118
+
119
+ # Generate from a live URL
120
+ swagger2drawio generate \
121
+ -i https://petstore3.swagger.io/api/v3/openapi.json \
122
+ -o petstore.drawio
123
+
124
+ # Use a built-in theme
125
+ swagger2drawio generate -i openapi.yaml -o api.drawio --theme dark
126
+
127
+ # Validate without rendering
128
+ swagger2drawio validate openapi.yaml
129
+
130
+ # Diff two versions of a spec
131
+ swagger2drawio diff v1.yaml v2.yaml -o changes.drawio
132
+ ```
133
+
134
+ ## Commands
135
+
136
+ | Command | What it does |
137
+ | ------------------ | --------------------------------------------------------- |
138
+ | `generate` | Parse a spec and emit a `.drawio` file. |
139
+ | `validate` | Validate a spec against the OpenAPI / Swagger schema. |
140
+ | `diff` | Compare two specs; render added/removed/changed overlay. |
141
+ | `init` | Scaffold a `.swagger2drawio.yaml` in the current folder. |
142
+ | `themes list` | List the bundled themes. |
143
+ | `themes show NAME` | Print one theme's YAML. |
144
+
145
+ Run `swagger2drawio <cmd> --help` for the full flag set on any command.
146
+
147
+ ## Key flags on `generate`
148
+
149
+ | Flag | Purpose |
150
+ | ----------------------------- | ----------------------------------------------------------------------- |
151
+ | `--input / -i` | Path or HTTP(S) URL to the spec. |
152
+ | `--output / -o` | Destination `.drawio` file (default: `output.drawio`). |
153
+ | `--config / -c` | Explicit YAML config file (highest precedence). |
154
+ | `--theme NAME` | One of the bundled themes (`light`, `dark`, `pastel`, `high-contrast`). |
155
+ | `--group-by tag\|path\|auto` | How to group operations on the endpoints page. |
156
+ | `--layout hierarchical\|grid` | Layout strategy. Extensible via entry points. |
157
+ | `--no-validate` | Skip schema validation. |
158
+ | `--timeout` | HTTP timeout in seconds (URL input). |
159
+ | `--header / -H "Name: v"` | Extra HTTP header for URL input (repeatable). |
160
+ | `--insecure` | Skip TLS verification (self-signed certs). |
161
+
162
+ Global flags (any subcommand):
163
+
164
+ | Flag | Purpose |
165
+ | ---------------- | ------------------------------------------------ |
166
+ | `--verbose / -v` | Increase log verbosity (`-v` INFO, `-vv` DEBUG). |
167
+ | `--quiet / -q` | Suppress INFO output. |
168
+ | `--log-file` | Append a DEBUG log to this file. |
169
+ | `--version` | Print the version and exit. |
170
+
171
+ ## Configuration
172
+
173
+ The active config is resolved in this order (each layer deep-merged
174
+ onto the previous):
175
+
176
+ 1. `--config` flag
177
+ 2. `--theme` (bundled YAML)
178
+ 3. `./.swagger2drawio.yaml`
179
+ 4. `$XDG_CONFIG_HOME/swagger2drawio/config.yaml` (defaults to
180
+ `~/.config/swagger2drawio/config.yaml`)
181
+ 5. Built-in defaults
182
+
183
+ Run `swagger2drawio init` to drop a starter config in the current
184
+ folder. `swagger2drawio themes show light` prints any bundled theme
185
+ verbatim so you can copy the bits you want to tweak.
186
+
187
+ ## Shell completion
188
+
189
+ ```bash
190
+ swagger2drawio --install-completion # auto-detect shell
191
+ swagger2drawio --show-completion # print the script
192
+ ```
193
+
194
+ Works with bash, zsh, fish, and PowerShell.
195
+
196
+ ## Use as a library
197
+
198
+ ```python
199
+ from swagger2drawio.parser.openapi_parser import OpenAPIParser
200
+ from swagger2drawio.layout.graph_engine import (
201
+ build_endpoint_graph,
202
+ build_schema_graph,
203
+ )
204
+ from swagger2drawio.renderer.drawio_builder import render
205
+ from swagger2drawio.config_loader import load_config
206
+
207
+ spec = OpenAPIParser(source="petstore.yaml").parse()
208
+ cfg = load_config(None, theme="dark")
209
+ ep = build_endpoint_graph(spec, group_by="tag", layout="hierarchical")
210
+ sc = build_schema_graph(spec)
211
+ render(ep, sc, "out.drawio", cfg)
212
+ ```
213
+
214
+ For diffs:
215
+
216
+ ```python
217
+ from swagger2drawio.diff import compute_diff
218
+ from swagger2drawio.renderer.diff_renderer import render_diff
219
+
220
+ old = OpenAPIParser(source="v1.yaml").parse(validate=False)
221
+ new = OpenAPIParser(source="v2.yaml").parse(validate=False)
222
+ diff = compute_diff(old, new)
223
+ render_diff(old, new, diff, "changes.drawio")
224
+ ```
225
+
226
+ ## Exit codes
227
+
228
+ Typed exceptions map to stable per-category exit codes so CI scripts
229
+ can branch on the failure mode:
230
+
231
+ | Code | Class | Meaning |
232
+ | ---- | ---------------------- | ---------------------------------- |
233
+ | 0 | — | Success |
234
+ | 1 | `Swagger2DrawioError` | Generic / unknown internal error |
235
+ | 2 | `SpecLoadError` | File missing or URL fetch failed |
236
+ | 3 | `SpecParseError` | Malformed JSON / YAML |
237
+ | 4 | `SpecValidationError` | Fails OpenAPI / Swagger schema |
238
+ | 5 | `LayoutError` | Graph construction / layout issue |
239
+ | 6 | `RenderError` | drawpyo / XML emission failure |
240
+ | 7 | `ConfigError` | Bad theme or config YAML |
241
+
242
+ ## Development
243
+
244
+ ```bash
245
+ git clone https://github.com/Abhishek-k03/swagger2drawio
246
+ cd swagger2drawio
247
+ uv sync --all-extras
248
+ uv run pre-commit install
249
+ uv run pytest # full suite + coverage
250
+ uv run ruff check . # lint
251
+ uv run mypy --strict swagger2drawio
252
+ ```
253
+
254
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the longer setup and the
255
+ custom-layout / custom-theme extension guide.
256
+
257
+ ## Project status
258
+
259
+ Beta. Public API surface (Typer commands, exit codes, the dataclasses
260
+ in `swagger2drawio.parser.openapi_parser`) is considered stable.
261
+ Internal modules may change without notice.
262
+
263
+ ## License
264
+
265
+ MIT — see [LICENSE](LICENSE).
266
+
267
+ ## Acknowledgements
268
+
269
+ - [drawpyo](https://github.com/MerrimanInd/drawpyo) for the `.drawio`
270
+ XML writer.
271
+ - [openapi-spec-validator](https://github.com/python-openapi/openapi-spec-validator)
272
+ for the schema validation pass.
273
+ - [Typer](https://typer.tiangolo.com/) and
274
+ [Rich](https://rich.readthedocs.io/) for the CLI plumbing.
@@ -0,0 +1,221 @@
1
+ # swagger2drawio
2
+
3
+ [![CI](https://github.com/Abhishek-k03/swagger2drawio/actions/workflows/ci.yml/badge.svg)](https://github.com/Abhishek-k03/swagger2drawio/actions/workflows/ci.yml)
4
+ [![PyPI version](https://img.shields.io/pypi/v/swagger2drawio.svg)](https://pypi.org/project/swagger2drawio/)
5
+ [![Python versions](https://img.shields.io/pypi/pyversions/swagger2drawio.svg)](https://pypi.org/project/swagger2drawio/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ > Turn an OpenAPI 3.x / Swagger 2.0 spec into a clean, structured
9
+ > [draw.io](https://app.diagrams.net/) diagram. Local files, remote
10
+ > URLs, multi-file `$ref`s — all in one command.
11
+
12
+ ```text
13
+ $ swagger2drawio generate -i petstore.yaml -o api.drawio
14
+ ✔ api.drawio written (12.4 KB) — 8 path(s), 14 method(s), 6 schema(s).
15
+ ```
16
+
17
+ Open `api.drawio` in [diagrams.net](https://app.diagrams.net/) and you
18
+ get a two-page (or three-page in diff mode) view of your API.
19
+
20
+ ---
21
+
22
+ ## Why this exists
23
+
24
+ API specs are easy to write and impossible to keep in your head once
25
+ they grow past a handful of endpoints. swagger2drawio gives you a
26
+ visual map you can annotate, share, and diff — without leaving the
27
+ spec as the source of truth.
28
+
29
+ ## Features
30
+
31
+ - **Two-page output**: an endpoints tree (root → tag → path → method)
32
+ and an ER-style schema map with `$ref` relationships.
33
+ - **OpenAPI 3.x and Swagger 2.0** — auto-detected.
34
+ - **Rich method labels**: parameters, request/response refs,
35
+ deprecated badge, summary.
36
+ - **Schema composition**: `allOf` / `oneOf` / `anyOf` /
37
+ `discriminator` get distinct edge styles; enums render as their own
38
+ `«enum»` nodes.
39
+ - **Spec validation** powered by `openapi-spec-validator` (skippable
40
+ with `--no-validate`).
41
+ - **External `$ref` resolution**: relative-file and remote-URL
42
+ pointers are fetched and inlined; circular refs terminate cleanly.
43
+ - **`diff` subcommand** — compare two spec versions and get a
44
+ green/red/yellow side-by-side change report. The headline feature.
45
+ - **Bundled themes**: `light`, `dark`, `pastel`, `high-contrast`.
46
+ - **Pluggable layouts** via the `swagger2drawio.layouts` entry point.
47
+
48
+ ## Install
49
+
50
+ ```bash
51
+ # With uv (recommended)
52
+ uvx swagger2drawio --version
53
+
54
+ # With pip
55
+ pip install swagger2drawio
56
+ ```
57
+
58
+ Requires Python 3.10+.
59
+
60
+ ## Quick start
61
+
62
+ ```bash
63
+ # Generate a diagram from a local spec
64
+ swagger2drawio generate -i openapi.yaml -o api.drawio
65
+
66
+ # Generate from a live URL
67
+ swagger2drawio generate \
68
+ -i https://petstore3.swagger.io/api/v3/openapi.json \
69
+ -o petstore.drawio
70
+
71
+ # Use a built-in theme
72
+ swagger2drawio generate -i openapi.yaml -o api.drawio --theme dark
73
+
74
+ # Validate without rendering
75
+ swagger2drawio validate openapi.yaml
76
+
77
+ # Diff two versions of a spec
78
+ swagger2drawio diff v1.yaml v2.yaml -o changes.drawio
79
+ ```
80
+
81
+ ## Commands
82
+
83
+ | Command | What it does |
84
+ | ------------------ | --------------------------------------------------------- |
85
+ | `generate` | Parse a spec and emit a `.drawio` file. |
86
+ | `validate` | Validate a spec against the OpenAPI / Swagger schema. |
87
+ | `diff` | Compare two specs; render added/removed/changed overlay. |
88
+ | `init` | Scaffold a `.swagger2drawio.yaml` in the current folder. |
89
+ | `themes list` | List the bundled themes. |
90
+ | `themes show NAME` | Print one theme's YAML. |
91
+
92
+ Run `swagger2drawio <cmd> --help` for the full flag set on any command.
93
+
94
+ ## Key flags on `generate`
95
+
96
+ | Flag | Purpose |
97
+ | ----------------------------- | ----------------------------------------------------------------------- |
98
+ | `--input / -i` | Path or HTTP(S) URL to the spec. |
99
+ | `--output / -o` | Destination `.drawio` file (default: `output.drawio`). |
100
+ | `--config / -c` | Explicit YAML config file (highest precedence). |
101
+ | `--theme NAME` | One of the bundled themes (`light`, `dark`, `pastel`, `high-contrast`). |
102
+ | `--group-by tag\|path\|auto` | How to group operations on the endpoints page. |
103
+ | `--layout hierarchical\|grid` | Layout strategy. Extensible via entry points. |
104
+ | `--no-validate` | Skip schema validation. |
105
+ | `--timeout` | HTTP timeout in seconds (URL input). |
106
+ | `--header / -H "Name: v"` | Extra HTTP header for URL input (repeatable). |
107
+ | `--insecure` | Skip TLS verification (self-signed certs). |
108
+
109
+ Global flags (any subcommand):
110
+
111
+ | Flag | Purpose |
112
+ | ---------------- | ------------------------------------------------ |
113
+ | `--verbose / -v` | Increase log verbosity (`-v` INFO, `-vv` DEBUG). |
114
+ | `--quiet / -q` | Suppress INFO output. |
115
+ | `--log-file` | Append a DEBUG log to this file. |
116
+ | `--version` | Print the version and exit. |
117
+
118
+ ## Configuration
119
+
120
+ The active config is resolved in this order (each layer deep-merged
121
+ onto the previous):
122
+
123
+ 1. `--config` flag
124
+ 2. `--theme` (bundled YAML)
125
+ 3. `./.swagger2drawio.yaml`
126
+ 4. `$XDG_CONFIG_HOME/swagger2drawio/config.yaml` (defaults to
127
+ `~/.config/swagger2drawio/config.yaml`)
128
+ 5. Built-in defaults
129
+
130
+ Run `swagger2drawio init` to drop a starter config in the current
131
+ folder. `swagger2drawio themes show light` prints any bundled theme
132
+ verbatim so you can copy the bits you want to tweak.
133
+
134
+ ## Shell completion
135
+
136
+ ```bash
137
+ swagger2drawio --install-completion # auto-detect shell
138
+ swagger2drawio --show-completion # print the script
139
+ ```
140
+
141
+ Works with bash, zsh, fish, and PowerShell.
142
+
143
+ ## Use as a library
144
+
145
+ ```python
146
+ from swagger2drawio.parser.openapi_parser import OpenAPIParser
147
+ from swagger2drawio.layout.graph_engine import (
148
+ build_endpoint_graph,
149
+ build_schema_graph,
150
+ )
151
+ from swagger2drawio.renderer.drawio_builder import render
152
+ from swagger2drawio.config_loader import load_config
153
+
154
+ spec = OpenAPIParser(source="petstore.yaml").parse()
155
+ cfg = load_config(None, theme="dark")
156
+ ep = build_endpoint_graph(spec, group_by="tag", layout="hierarchical")
157
+ sc = build_schema_graph(spec)
158
+ render(ep, sc, "out.drawio", cfg)
159
+ ```
160
+
161
+ For diffs:
162
+
163
+ ```python
164
+ from swagger2drawio.diff import compute_diff
165
+ from swagger2drawio.renderer.diff_renderer import render_diff
166
+
167
+ old = OpenAPIParser(source="v1.yaml").parse(validate=False)
168
+ new = OpenAPIParser(source="v2.yaml").parse(validate=False)
169
+ diff = compute_diff(old, new)
170
+ render_diff(old, new, diff, "changes.drawio")
171
+ ```
172
+
173
+ ## Exit codes
174
+
175
+ Typed exceptions map to stable per-category exit codes so CI scripts
176
+ can branch on the failure mode:
177
+
178
+ | Code | Class | Meaning |
179
+ | ---- | ---------------------- | ---------------------------------- |
180
+ | 0 | — | Success |
181
+ | 1 | `Swagger2DrawioError` | Generic / unknown internal error |
182
+ | 2 | `SpecLoadError` | File missing or URL fetch failed |
183
+ | 3 | `SpecParseError` | Malformed JSON / YAML |
184
+ | 4 | `SpecValidationError` | Fails OpenAPI / Swagger schema |
185
+ | 5 | `LayoutError` | Graph construction / layout issue |
186
+ | 6 | `RenderError` | drawpyo / XML emission failure |
187
+ | 7 | `ConfigError` | Bad theme or config YAML |
188
+
189
+ ## Development
190
+
191
+ ```bash
192
+ git clone https://github.com/Abhishek-k03/swagger2drawio
193
+ cd swagger2drawio
194
+ uv sync --all-extras
195
+ uv run pre-commit install
196
+ uv run pytest # full suite + coverage
197
+ uv run ruff check . # lint
198
+ uv run mypy --strict swagger2drawio
199
+ ```
200
+
201
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the longer setup and the
202
+ custom-layout / custom-theme extension guide.
203
+
204
+ ## Project status
205
+
206
+ Beta. Public API surface (Typer commands, exit codes, the dataclasses
207
+ in `swagger2drawio.parser.openapi_parser`) is considered stable.
208
+ Internal modules may change without notice.
209
+
210
+ ## License
211
+
212
+ MIT — see [LICENSE](LICENSE).
213
+
214
+ ## Acknowledgements
215
+
216
+ - [drawpyo](https://github.com/MerrimanInd/drawpyo) for the `.drawio`
217
+ XML writer.
218
+ - [openapi-spec-validator](https://github.com/python-openapi/openapi-spec-validator)
219
+ for the schema validation pass.
220
+ - [Typer](https://typer.tiangolo.com/) and
221
+ [Rich](https://rich.readthedocs.io/) for the CLI plumbing.