fastapi_swagger2 0.2.4__tar.gz → 0.2.5__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
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: fastapi_swagger2
3
- Version: 0.2.4
3
+ Version: 0.2.5
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
@@ -40,10 +40,11 @@ Classifier: Operating System :: OS Independent
40
40
  Classifier: Programming Language :: Python
41
41
  Classifier: Programming Language :: Python :: 3
42
42
  Classifier: Programming Language :: Python :: 3 :: Only
43
- Classifier: Programming Language :: Python :: 3.8
44
43
  Classifier: Programming Language :: Python :: 3.9
45
44
  Classifier: Programming Language :: Python :: 3.10
46
45
  Classifier: Programming Language :: Python :: 3.11
46
+ Classifier: Programming Language :: Python :: 3.12
47
+ Classifier: Programming Language :: Python :: 3.13
47
48
  Classifier: Topic :: Internet
48
49
  Classifier: Topic :: Internet :: WWW/HTTP
49
50
  Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
@@ -51,7 +52,7 @@ Classifier: Topic :: Software Development
51
52
  Classifier: Topic :: Software Development :: Libraries
52
53
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
53
54
  Classifier: Typing :: Typed
54
- Requires-Python: >=3.8
55
+ Requires-Python: >=3.9
55
56
  Requires-Dist: fastapi>=0.100.0
56
57
  Provides-Extra: all
57
58
  Requires-Dist: httpx>=0.23.0; extra == 'all'
@@ -90,11 +91,12 @@ Few API GW services like Google Cloud API GW still support only Swagger 2.0 spec
90
91
 
91
92
  ## Requirements
92
93
 
93
- Python 3.8+
94
+ Python 3.9+
94
95
 
95
96
  * 0.0.3 - FastAPI >= 0.79.0, <= 0.98.0
96
97
  * 0.1.1 - FastAPI >= 0.99.0, <= 0.99.1
97
98
  * 0.2.4 - FastAPI >= 0.100.0
99
+ * 0.2.5 - FastAPI >= 0.100.0 + Pydantic v1/v2
98
100
 
99
101
  ## Installation
100
102
 
@@ -21,11 +21,12 @@ Few API GW services like Google Cloud API GW still support only Swagger 2.0 spec
21
21
 
22
22
  ## Requirements
23
23
 
24
- Python 3.8+
24
+ Python 3.9+
25
25
 
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
30
 
30
31
  ## Installation
31
32
 
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
  name = "fastapi_swagger2"
7
7
  description = "Swagger2 support for FastAPI framework"
8
8
  readme = "README.md"
9
- requires-python = ">=3.8"
9
+ requires-python = ">=3.9"
10
10
  license = { file="LICENSE" }
11
11
  authors = [
12
12
  { name = "Viraj Kanwade", email = "virajk.oib@gmail.com" },
@@ -30,10 +30,11 @@ classifiers = [
30
30
  "Intended Audience :: Developers",
31
31
  "License :: OSI Approved :: MIT License",
32
32
  "Programming Language :: Python :: 3 :: Only",
33
- "Programming Language :: Python :: 3.8",
34
33
  "Programming Language :: Python :: 3.9",
35
34
  "Programming Language :: Python :: 3.10",
36
35
  "Programming Language :: Python :: 3.11",
36
+ "Programming Language :: Python :: 3.12",
37
+ "Programming Language :: Python :: 3.13",
37
38
  "Topic :: Internet :: WWW/HTTP :: HTTP Servers",
38
39
  "Topic :: Internet :: WWW/HTTP",
39
40
  ]
@@ -1,4 +1,4 @@
1
- __version__ = "0.2.4"
1
+ __version__ = "0.2.5"
2
2
 
3
3
  from typing import Any, Dict, List, Optional, TypeVar
4
4
 
@@ -1,17 +1,17 @@
1
1
  import http.client
2
2
  import inspect
3
+ from enum import Enum
3
4
  from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, Type, Union, cast
4
5
  from urllib.parse import ParseResult, urlparse
5
6
 
6
7
  from fastapi import routing
7
8
  from fastapi._compat import (
9
+ PYDANTIC_V2,
8
10
  GenerateJsonSchema,
9
11
  JsonSchemaValue,
10
12
  ModelField,
11
13
  Undefined,
12
14
  get_compat_model_name_map,
13
- get_definitions,
14
- get_schema_from_model_field,
15
15
  lenient_issubclass,
16
16
  )
17
17
  from fastapi.datastructures import DefaultPlaceholder
@@ -29,6 +29,7 @@ from fastapi.params import Body, Param
29
29
  from fastapi.responses import Response
30
30
  from fastapi.types import ModelNameMap
31
31
  from fastapi.utils import deep_dict_update, is_body_allowed_for_status_code
32
+ from pydantic import BaseModel
32
33
  from starlette.responses import JSONResponse
33
34
  from starlette.routing import BaseRoute
34
35
  from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY
@@ -37,6 +38,66 @@ from typing_extensions import Literal
37
38
  from fastapi_swagger2.constants import REF_PREFIX, REF_TEMPLATE
38
39
  from fastapi_swagger2.models import Swagger2
39
40
 
41
+ if PYDANTIC_V2:
42
+ from fastapi._compat import get_definitions, get_schema_from_model_field
43
+ else:
44
+ from pydantic.schema import (
45
+ field_schema,
46
+ get_flat_models_from_fields,
47
+ model_process_schema,
48
+ )
49
+
50
+ def get_model_definitions(
51
+ *,
52
+ flat_models: Set[Union[Type[BaseModel], Type[Enum]]],
53
+ model_name_map: Dict[Union[Type[BaseModel], Type[Enum]], str],
54
+ ) -> Dict[str, Any]:
55
+ definitions: Dict[str, Dict[str, Any]] = {}
56
+ for model in flat_models:
57
+ print(REF_PREFIX)
58
+ m_schema, m_definitions, m_nested_models = model_process_schema(
59
+ model, model_name_map=model_name_map, ref_prefix=REF_PREFIX
60
+ )
61
+ definitions.update(m_definitions)
62
+ model_name = model_name_map[model]
63
+ if "description" in m_schema:
64
+ m_schema["description"] = m_schema["description"].split("\f")[0]
65
+ definitions[model_name] = m_schema
66
+ return definitions
67
+
68
+ def get_definitions(
69
+ *,
70
+ fields: List[ModelField],
71
+ schema_generator: GenerateJsonSchema,
72
+ model_name_map: ModelNameMap,
73
+ separate_input_output_schemas: bool = True,
74
+ ) -> Tuple[
75
+ Dict[
76
+ Tuple[ModelField, Literal["validation", "serialization"]], JsonSchemaValue
77
+ ],
78
+ Dict[str, Dict[str, Any]],
79
+ ]:
80
+ models = get_flat_models_from_fields(fields, known_models=set())
81
+ return {}, get_model_definitions(
82
+ flat_models=models, model_name_map=model_name_map
83
+ )
84
+
85
+ def get_schema_from_model_field(
86
+ *,
87
+ field: ModelField,
88
+ schema_generator: GenerateJsonSchema,
89
+ model_name_map: ModelNameMap,
90
+ field_mapping: Dict[
91
+ Tuple[ModelField, Literal["validation", "serialization"]], JsonSchemaValue
92
+ ],
93
+ separate_input_output_schemas: bool = True,
94
+ ) -> Dict[str, Any]:
95
+ # This expects that GenerateJsonSchema was already used to generate the definitions
96
+ return field_schema( # type: ignore[no-any-return]
97
+ field, model_name_map=model_name_map, ref_prefix=REF_PREFIX
98
+ )[0]
99
+
100
+
40
101
  validation_error_definition = {
41
102
  "title": "ValidationError",
42
103
  "type": "object",