Skip to content

Commit 2efa55b

Browse files
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>
1 parent 88f230a commit 2efa55b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ 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(ValueError, match="Swagger 2.0 specifications are not supported"):
62+
OpenAPIV3DocumentationHandler({"swagger": "2.0", "info": {}, "paths": {}})
63+
64+
5565
@pytest.mark.parametrize(
5666
"input,expected_result",
5767
[

0 commit comments

Comments
 (0)