fastapi_swagger2 0.2.5__tar.gz → 0.2.6__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.
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/PKG-INFO +12 -12
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/README.md +1 -1
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/pyproject.toml +13 -17
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/scripts/format.sh +1 -1
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/scripts/lint.sh +1 -1
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/src/fastapi_swagger2/__init__.py +1 -1
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/src/fastapi_swagger2/utils.py +45 -10
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/.gitignore +0 -0
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/LICENSE +0 -0
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/requirements-dev.txt +0 -0
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/requirements.txt +0 -0
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/scripts/build.sh +0 -0
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/scripts/clean.sh +0 -0
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/scripts/publish.sh +0 -0
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/scripts/test.sh +0 -0
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/setup.cfg +0 -0
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/src/fastapi_swagger2/constants.py +0 -0
- {fastapi_swagger2-0.2.5 → fastapi_swagger2-0.2.6}/src/fastapi_swagger2/models.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastapi_swagger2
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.6
|
|
4
4
|
Summary: Swagger2 support for FastAPI framework
|
|
5
5
|
Project-URL: Homepage, https://github.com/virajkanwade/fastapi_swagger2
|
|
6
6
|
Project-URL: Documentation, https://github.com/virajkanwade/fastapi_swagger2
|
|
@@ -53,19 +53,19 @@ Classifier: Topic :: Software Development :: Libraries
|
|
|
53
53
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
54
54
|
Classifier: Typing :: Typed
|
|
55
55
|
Requires-Python: >=3.9
|
|
56
|
-
Requires-Dist: fastapi
|
|
56
|
+
Requires-Dist: fastapi<0.119.0,>=0.100.0
|
|
57
57
|
Provides-Extra: all
|
|
58
|
-
Requires-Dist: httpx>=0.
|
|
58
|
+
Requires-Dist: httpx>=0.28.1; extra == 'all'
|
|
59
59
|
Provides-Extra: dev
|
|
60
|
-
Requires-Dist: ruff==0.
|
|
60
|
+
Requires-Dist: ruff==0.14.10; extra == 'dev'
|
|
61
61
|
Provides-Extra: test
|
|
62
|
-
Requires-Dist: black==
|
|
63
|
-
Requires-Dist: coverage[toml]<8.0,>=
|
|
64
|
-
Requires-Dist: httpx
|
|
65
|
-
Requires-Dist: isort
|
|
66
|
-
Requires-Dist: mypy==1.
|
|
67
|
-
Requires-Dist: pytest<
|
|
68
|
-
Requires-Dist: ruff==0.
|
|
62
|
+
Requires-Dist: black==25.12.0; extra == 'test'
|
|
63
|
+
Requires-Dist: coverage[toml]<8.0,>=7.13.1; extra == 'test'
|
|
64
|
+
Requires-Dist: httpx>=0.28.1; extra == 'test'
|
|
65
|
+
Requires-Dist: isort>=7.0.0; extra == 'test'
|
|
66
|
+
Requires-Dist: mypy==1.19.1; extra == 'test'
|
|
67
|
+
Requires-Dist: pytest<10.0.0,>=9.0.2; extra == 'test'
|
|
68
|
+
Requires-Dist: ruff==0.14.10; extra == 'test'
|
|
69
69
|
Description-Content-Type: text/markdown
|
|
70
70
|
|
|
71
71
|
# fastapi_swagger2
|
|
@@ -96,7 +96,7 @@ Python 3.9+
|
|
|
96
96
|
* 0.0.3 - FastAPI >= 0.79.0, <= 0.98.0
|
|
97
97
|
* 0.1.1 - FastAPI >= 0.99.0, <= 0.99.1
|
|
98
98
|
* 0.2.4 - FastAPI >= 0.100.0
|
|
99
|
-
* 0.2.
|
|
99
|
+
* 0.2.6 - FastAPI >= 0.100.0, < 0.199.0 > + Pydantic v1/v2
|
|
100
100
|
|
|
101
101
|
## Installation
|
|
102
102
|
|
|
@@ -26,7 +26,7 @@ Python 3.9+
|
|
|
26
26
|
* 0.0.3 - FastAPI >= 0.79.0, <= 0.98.0
|
|
27
27
|
* 0.1.1 - FastAPI >= 0.99.0, <= 0.99.1
|
|
28
28
|
* 0.2.4 - FastAPI >= 0.100.0
|
|
29
|
-
* 0.2.
|
|
29
|
+
* 0.2.6 - FastAPI >= 0.100.0, < 0.199.0 > + Pydantic v1/v2
|
|
30
30
|
|
|
31
31
|
## Installation
|
|
32
32
|
|
|
@@ -39,7 +39,7 @@ classifiers = [
|
|
|
39
39
|
"Topic :: Internet :: WWW/HTTP",
|
|
40
40
|
]
|
|
41
41
|
dependencies = [
|
|
42
|
-
"fastapi >=0.100.0",
|
|
42
|
+
"fastapi >=0.100.0,<0.119.0",
|
|
43
43
|
]
|
|
44
44
|
dynamic = ["version"]
|
|
45
45
|
|
|
@@ -49,19 +49,19 @@ Documentation = "https://github.com/virajkanwade/fastapi_swagger2"
|
|
|
49
49
|
|
|
50
50
|
[project.optional-dependencies]
|
|
51
51
|
test = [
|
|
52
|
-
"pytest >=
|
|
53
|
-
"coverage[toml] >=
|
|
54
|
-
"mypy ==1.
|
|
55
|
-
"ruff ==0.
|
|
56
|
-
"black ==
|
|
57
|
-
"isort >=
|
|
58
|
-
"httpx >=0.
|
|
52
|
+
"pytest >=9.0.2,<10.0.0",
|
|
53
|
+
"coverage[toml] >= 7.13.1,< 8.0",
|
|
54
|
+
"mypy ==1.19.1",
|
|
55
|
+
"ruff ==0.14.10",
|
|
56
|
+
"black == 25.12.0",
|
|
57
|
+
"isort >=7.0.0",
|
|
58
|
+
"httpx >=0.28.1",
|
|
59
59
|
]
|
|
60
60
|
dev = [
|
|
61
|
-
"ruff ==0.
|
|
61
|
+
"ruff ==0.14.10",
|
|
62
62
|
]
|
|
63
63
|
all = [
|
|
64
|
-
"httpx >=0.
|
|
64
|
+
"httpx >=0.28.1",
|
|
65
65
|
]
|
|
66
66
|
|
|
67
67
|
[tool.hatch.version]
|
|
@@ -74,7 +74,7 @@ known_third_party = ["fastapi", "pydantic", "starlette"]
|
|
|
74
74
|
[tool.mypy]
|
|
75
75
|
strict = true
|
|
76
76
|
|
|
77
|
-
[tool.ruff]
|
|
77
|
+
[tool.ruff.lint]
|
|
78
78
|
select = [
|
|
79
79
|
"E", # pycodestyle errors
|
|
80
80
|
"W", # pycodestyle warnings
|
|
@@ -88,9 +88,5 @@ ignore = [
|
|
|
88
88
|
"B008", # do not perform function calls in argument defaults
|
|
89
89
|
"C901", # too complex
|
|
90
90
|
]
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
"__init__.py" = ["F401"]
|
|
94
|
-
|
|
95
|
-
[tool.ruff.isort]
|
|
96
|
-
known-third-party = ["fastapi", "pydantic", "starlette"]
|
|
91
|
+
per-file-ignores = { "__init__.py" = ["F401"] }
|
|
92
|
+
isort = { known-third-party = ["fastapi", "pydantic", "starlette"] }
|
|
@@ -54,7 +54,6 @@ else:
|
|
|
54
54
|
) -> Dict[str, Any]:
|
|
55
55
|
definitions: Dict[str, Dict[str, Any]] = {}
|
|
56
56
|
for model in flat_models:
|
|
57
|
-
print(REF_PREFIX)
|
|
58
57
|
m_schema, m_definitions, m_nested_models = model_process_schema(
|
|
59
58
|
model, model_name_map=model_name_map, ref_prefix=REF_PREFIX
|
|
60
59
|
)
|
|
@@ -249,7 +248,10 @@ def get_swagger2_operation_parameters(
|
|
|
249
248
|
}
|
|
250
249
|
schema: Dict[str, Any] = param_schema
|
|
251
250
|
if field_info.in_.value == "body":
|
|
252
|
-
|
|
251
|
+
if "$ref" in schema:
|
|
252
|
+
parameter["schema"] = {"$ref", schema["$ref"]}
|
|
253
|
+
else:
|
|
254
|
+
parameter["schema"] = schema
|
|
253
255
|
else:
|
|
254
256
|
parameter.update({k: v for (k, v) in schema.items() if k != "title"})
|
|
255
257
|
if field_info.description:
|
|
@@ -287,7 +289,14 @@ def get_swagger2_operation_request_body(
|
|
|
287
289
|
if required:
|
|
288
290
|
request_body_oai["required"] = required
|
|
289
291
|
|
|
290
|
-
request_media_content: Dict[str, Any] = {
|
|
292
|
+
request_media_content: Dict[str, Any] = {}
|
|
293
|
+
if "$ref" in body_schema:
|
|
294
|
+
request_media_content["schema"] = {"$ref": body_schema["$ref"]}
|
|
295
|
+
request_media_content.update(
|
|
296
|
+
{k: v for (k, v) in body_schema.items() if k != "$ref"}
|
|
297
|
+
)
|
|
298
|
+
else:
|
|
299
|
+
request_media_content["schema"] = body_schema
|
|
291
300
|
if field_info.example != Undefined:
|
|
292
301
|
request_media_content["example"] = jsonable_encoder(field_info.example)
|
|
293
302
|
# request_body_oai["content"] = {request_media_type: request_media_content}
|
|
@@ -342,6 +351,7 @@ def get_swagger2_path(
|
|
|
342
351
|
model_name_map=model_name_map,
|
|
343
352
|
field_mapping=field_mapping,
|
|
344
353
|
)
|
|
354
|
+
|
|
345
355
|
parameters.extend(operation_parameters)
|
|
346
356
|
if parameters:
|
|
347
357
|
all_parameters = {
|
|
@@ -550,6 +560,14 @@ def get_swagger2(
|
|
|
550
560
|
if result:
|
|
551
561
|
path, security_schemes, path_definitions = result
|
|
552
562
|
|
|
563
|
+
for k, v in path.items():
|
|
564
|
+
for param in v["parameters"]:
|
|
565
|
+
if "$ref" in param and "in" in param and param["in"] != "body":
|
|
566
|
+
definition = definitions[param.pop("$ref").split("/")[2]]
|
|
567
|
+
param.update(
|
|
568
|
+
{k: v for (k, v) in definition.items() if k != "title"}
|
|
569
|
+
)
|
|
570
|
+
|
|
553
571
|
if path:
|
|
554
572
|
paths.setdefault(route.path_format, {}).update(path)
|
|
555
573
|
|
|
@@ -569,16 +587,33 @@ def get_swagger2(
|
|
|
569
587
|
for k in sorted(definitions):
|
|
570
588
|
properties = definitions[k].get("properties", [])
|
|
571
589
|
for p in properties:
|
|
572
|
-
if "anyOf" in properties[p]
|
|
590
|
+
if "anyOf" in properties[p]:
|
|
573
591
|
any_of = properties[p].pop("anyOf")
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
592
|
+
|
|
593
|
+
if len(any_of) == 1:
|
|
594
|
+
# Single item - just use it directly
|
|
595
|
+
properties[p].update(any_of[0])
|
|
596
|
+
elif len(any_of) == 2:
|
|
597
|
+
# Handle the 2-item case (type + null)
|
|
598
|
+
ref_item = None
|
|
599
|
+
has_null = False
|
|
600
|
+
|
|
601
|
+
for item in any_of:
|
|
602
|
+
if item == {"type": "null"}:
|
|
603
|
+
has_null = True
|
|
604
|
+
elif "$ref" in item:
|
|
605
|
+
ref_item = item
|
|
578
606
|
else:
|
|
579
|
-
properties[p].update(
|
|
607
|
+
properties[p].update(item)
|
|
608
|
+
|
|
609
|
+
if ref_item and has_null:
|
|
610
|
+
properties[p]["allOf"] = [ref_item]
|
|
611
|
+
properties[p]["x-nullable"] = True
|
|
612
|
+
elif has_null:
|
|
613
|
+
properties[p]["x-nullable"] = True
|
|
580
614
|
else:
|
|
581
|
-
|
|
615
|
+
# Fallback for complex anyOf cases (len > 2) or empty (len == 0)
|
|
616
|
+
properties[p]["type"] = "string"
|
|
582
617
|
logger.warning(
|
|
583
618
|
f"fastapi_swagger2: Unable to handle anyOf in definitions {any_of}, defaulting to string type."
|
|
584
619
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|