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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastapi_swagger2
3
- Version: 0.2.5
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>=0.100.0
56
+ Requires-Dist: fastapi<0.119.0,>=0.100.0
57
57
  Provides-Extra: all
58
- Requires-Dist: httpx>=0.23.0; extra == 'all'
58
+ Requires-Dist: httpx>=0.28.1; extra == 'all'
59
59
  Provides-Extra: dev
60
- Requires-Dist: ruff==0.0.272; extra == 'dev'
60
+ Requires-Dist: ruff==0.14.10; extra == 'dev'
61
61
  Provides-Extra: test
62
- Requires-Dist: black==23.3.0; extra == 'test'
63
- Requires-Dist: coverage[toml]<8.0,>=6.5.0; extra == 'test'
64
- Requires-Dist: httpx<0.24.0,>=0.23.0; extra == 'test'
65
- Requires-Dist: isort<6.0.0,>=5.0.6; extra == 'test'
66
- Requires-Dist: mypy==1.3.0; extra == 'test'
67
- Requires-Dist: pytest<8.0.0,>=7.1.3; extra == 'test'
68
- Requires-Dist: ruff==0.0.272; extra == 'test'
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.5 - FastAPI >= 0.100.0 + Pydantic v1/v2
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.5 - FastAPI >= 0.100.0 + Pydantic v1/v2
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 >=7.1.3,<8.0.0",
53
- "coverage[toml] >= 6.5.0,< 8.0",
54
- "mypy ==1.3.0",
55
- "ruff ==0.0.272",
56
- "black == 23.3.0",
57
- "isort >=5.0.6,<6.0.0",
58
- "httpx >=0.23.0,<0.24.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.0.272",
61
+ "ruff ==0.14.10",
62
62
  ]
63
63
  all = [
64
- "httpx >=0.23.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
- [tool.ruff.per-file-ignores]
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"] }
@@ -1,6 +1,6 @@
1
1
  #!/bin/sh -e
2
2
  set -x
3
3
 
4
- ruff src/fastapi_swagger2 tests scripts --fix
4
+ ruff check src/fastapi_swagger2 tests scripts --fix
5
5
  black src/fastapi_swagger2 tests scripts
6
6
  isort src/fastapi_swagger2 tests scripts
@@ -4,6 +4,6 @@ set -e
4
4
  set -x
5
5
 
6
6
  mypy src/fastapi_swagger2
7
- ruff src/fastapi_swagger2 tests scripts
7
+ ruff check src/fastapi_swagger2 tests scripts
8
8
  black src/fastapi_swagger2 tests --check
9
9
  isort src/fastapi_swagger2 tests scripts --check-only
@@ -1,4 +1,4 @@
1
- __version__ = "0.2.5"
1
+ __version__ = "0.2.6"
2
2
 
3
3
  from typing import Any, Dict, List, Optional, TypeVar
4
4
 
@@ -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
- parameter["schema"] = schema
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] = {"schema": body_schema}
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].keys():
590
+ if "anyOf" in properties[p]:
573
591
  any_of = properties[p].pop("anyOf")
574
- if len(any_of) <= 2:
575
- for _any_of in any_of:
576
- if _any_of == {"type": "null"}:
577
- properties[p]["x-nullable"] = True
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(_any_of)
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
- properties[p].update({"type": "string"})
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
  )