Skip to content

Commit 9eb7114

Browse files
Fix #30 (#67)
* Raise clear error for Swagger 2.0 specs (issue #30) Instead of silently producing empty output, detect swagger: '2.0' in normalize_data and raise a ValueError with a link to https://converter.swagger.io/ so users know how to proceed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update CHANGELOG.md * Update test_mk_v3.py --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 88f230a commit 9eb7114

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Add OAS 3.1 support, cross-version warnings, and fix nullable spacing, by @dcode.
1111
- Fix MARKDOWN style table separators to use minimum 3 hyphens (issue #39), reported by @michael-nok.
1212
- Fix [#45](https://github.com/Neoteroi/essentials-openapi/issues/45): add support for displaying descriptions of schema properties, reported by @Maia-Everett.
13+
- Fix [#30](https://github.com/Neoteroi/essentials-openapi/issues/30): raise an error
14+
when trying to generate output from an older Swagger v2 specification file (these were
15+
never supported as there was never a `/mk/v2/` namespace, intentionally).
1316

1417
## [1.3.0] - 2025-11-19
1518

openapidocs/mk/v3/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ def normalize_data(self, data):
237237
$ref fields MUST be used in the specification to reference those parts as
238238
follows from the JSON Schema definitions.
239239
"""
240+
if isinstance(data.get("swagger"), str) and data["swagger"].startswith("2"):
241+
raise ValueError(
242+
"Swagger 2.0 specifications are not supported. "
243+
"Please convert your specification to OpenAPI 3.x first. "
244+
"You can use the online converter at https://converter.swagger.io/"
245+
)
246+
240247
if "components" not in data:
241248
data["components"] = {}
242249

tests/test_mk_v3.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ def test_file_ref_raises_for_missing_file():
5252
)
5353

5454

55+
def test_swagger2_raises_not_supported():
56+
"""
57+
Regression test for https://github.com/Neoteroi/essentials-openapi/issues/30
58+
Swagger 2.0 specs should raise a clear ValueError instead of silently
59+
producing empty output.
60+
"""
61+
with pytest.raises(
62+
ValueError, match="Swagger 2.0 specifications are not supported"
63+
):
64+
OpenAPIV3DocumentationHandler({"swagger": "2.0", "info": {}, "paths": {}})
65+
66+
5567
@pytest.mark.parametrize(
5668
"input,expected_result",
5769
[

0 commit comments

Comments
 (0)