fastapi_swagger2 0.2.6__tar.gz → 0.3.0__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.
Files changed (40) hide show
  1. fastapi_swagger2-0.3.0/.flake8 +2 -0
  2. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0}/PKG-INFO +4 -3
  3. fastapi_swagger2-0.3.0/README.md +92 -0
  4. fastapi_swagger2-0.3.0/fastapi_0.100.0/.git +1 -0
  5. fastapi_swagger2-0.3.0/fastapi_0.100.0/.gitignore +163 -0
  6. fastapi_swagger2-0.3.0/fastapi_0.100.0/LICENSE +21 -0
  7. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0/fastapi_0.100.0}/README.md +1 -1
  8. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0/fastapi_0.100.0}/src/fastapi_swagger2/__init__.py +1 -1
  9. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0/fastapi_0.100.0}/src/fastapi_swagger2/models.py +107 -22
  10. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0/fastapi_0.100.0}/src/fastapi_swagger2/utils.py +57 -10
  11. fastapi_swagger2-0.3.0/pyproject.toml +95 -0
  12. fastapi_swagger2-0.3.0/requirements-dev.txt +1 -0
  13. fastapi_swagger2-0.3.0/requirements.txt +1 -0
  14. fastapi_swagger2-0.3.0/scripts/build.sh +3 -0
  15. fastapi_swagger2-0.3.0/scripts/clean.sh +8 -0
  16. fastapi_swagger2-0.3.0/scripts/format.sh +6 -0
  17. fastapi_swagger2-0.3.0/scripts/lint.sh +9 -0
  18. fastapi_swagger2-0.3.0/scripts/publish.sh +5 -0
  19. fastapi_swagger2-0.3.0/scripts/test.sh +9 -0
  20. fastapi_swagger2-0.3.0/setup.cfg +3 -0
  21. fastapi_swagger2-0.3.0/src/fastapi_swagger2/__init__.py +346 -0
  22. fastapi_swagger2-0.3.0/src/fastapi_swagger2/models.py +26 -0
  23. fastapi_swagger2-0.3.0/src/fastapi_swagger2/utils.py +535 -0
  24. fastapi_swagger2-0.3.0/src/fastapi_swagger2_old/__init__.py +145 -0
  25. fastapi_swagger2-0.3.0/src/fastapi_swagger2_old/constants.py +2 -0
  26. fastapi_swagger2-0.3.0/src/fastapi_swagger2_old/models.py +425 -0
  27. fastapi_swagger2-0.3.0/src/fastapi_swagger2_old/utils.py +673 -0
  28. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0}/.gitignore +0 -0
  29. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0}/LICENSE +0 -0
  30. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0/fastapi_0.100.0}/pyproject.toml +0 -0
  31. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0/fastapi_0.100.0}/requirements-dev.txt +0 -0
  32. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0/fastapi_0.100.0}/requirements.txt +0 -0
  33. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0/fastapi_0.100.0}/scripts/build.sh +0 -0
  34. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0/fastapi_0.100.0}/scripts/clean.sh +0 -0
  35. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0/fastapi_0.100.0}/scripts/format.sh +0 -0
  36. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0/fastapi_0.100.0}/scripts/lint.sh +0 -0
  37. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0/fastapi_0.100.0}/scripts/publish.sh +0 -0
  38. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0/fastapi_0.100.0}/scripts/test.sh +0 -0
  39. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0/fastapi_0.100.0}/setup.cfg +0 -0
  40. {fastapi_swagger2-0.2.6 → fastapi_swagger2-0.3.0/fastapi_0.100.0}/src/fastapi_swagger2/constants.py +0 -0
@@ -0,0 +1,2 @@
1
+ [flake8]
2
+ max-line-length = 88
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastapi_swagger2
3
- Version: 0.2.6
3
+ Version: 0.3.0
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,7 +53,7 @@ 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.119.0,>=0.100.0
56
+ Requires-Dist: fastapi<=0.123.8,>=0.119.0
57
57
  Provides-Extra: all
58
58
  Requires-Dist: httpx>=0.28.1; extra == 'all'
59
59
  Provides-Extra: dev
@@ -96,7 +96,8 @@ 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.6 - FastAPI >= 0.100.0, < 0.199.0 > + Pydantic v1/v2
99
+ * 0.2.7 - FastAPI >= 0.100.0, < 0.119.0 + Pydantic v1/v2
100
+ * 0.3.0 - FastAPI >= 0.119.0, <= 0.123.8 + Pydantic v1/v2
100
101
 
101
102
  ## Installation
102
103
 
@@ -0,0 +1,92 @@
1
+ # fastapi_swagger2
2
+ <p align="center">
3
+ Swagger2 support for FastAPI
4
+ </p>
5
+ <p align="center">
6
+ <a href="https://pypi.org/project/fastapi_swagger2" target="_blank">
7
+ <img src="https://img.shields.io/pypi/v/fastapi_swagger2?color=%2334D058&label=pypi%20package" alt="Package version">
8
+ </a>
9
+ <a href="https://pypi.org/project/fastapi_swagger2" target="_blank">
10
+ <img src="https://img.shields.io/pypi/pyversions/fastapi_swagger2.svg?color=%2334D058" alt="Supported Python versions">
11
+ </a>
12
+ </p>
13
+
14
+ ---
15
+
16
+ _Reason behind this library:_
17
+
18
+ Few API GW services like Google Cloud API GW still support only Swagger 2.0 spec. Since FastAPI only supports OAS3, it is a challenge. Converting from OAS3 to Swagger 2.0 requires some manual steps which would hinder CI/CD.
19
+
20
+ ---
21
+
22
+ ## Requirements
23
+
24
+ Python 3.9+
25
+
26
+ * 0.0.3 - FastAPI >= 0.79.0, <= 0.98.0
27
+ * 0.1.1 - FastAPI >= 0.99.0, <= 0.99.1
28
+ * 0.2.4 - FastAPI >= 0.100.0
29
+ * 0.2.7 - FastAPI >= 0.100.0, < 0.119.0 + Pydantic v1/v2
30
+ * 0.3.0 - FastAPI >= 0.119.0, <= 0.123.8 + Pydantic v1/v2
31
+
32
+ ## Installation
33
+
34
+ <div class="termy">
35
+
36
+ ```console
37
+ $ pip install fastapi_swagger2
38
+ ```
39
+
40
+ </div>
41
+
42
+ ## Example
43
+
44
+ ```Python
45
+ from typing import Union
46
+
47
+ from fastapi import FastAPI
48
+ from fastapi_swagger2 import FastAPISwagger2
49
+
50
+ app = FastAPI()
51
+ FastAPISwagger2(app)
52
+
53
+
54
+ @app.get("/")
55
+ def read_root():
56
+ return {"Hello": "World"}
57
+
58
+
59
+ @app.get("/items/{item_id}")
60
+ def read_item(item_id: int, q: Union[str, None] = None):
61
+ return {"item_id": item_id, "q": q}
62
+ ```
63
+
64
+ This adds following endpoints:
65
+ * http://localhost:8000/swagger2.json
66
+ * http://localhost:8000/swagger2/docs
67
+ * http://localhost:8000/swagger2/redoc
68
+
69
+ ## Generate spec for CI/CD
70
+
71
+ ```Python
72
+ import os
73
+
74
+ import yaml
75
+
76
+ from app.main import app
77
+
78
+ URL = os.environ["CLOUD_RUN_URL"]
79
+
80
+ app.servers.append(URL)
81
+
82
+ spec = app.swagger2()
83
+ spec['x-google-backend'] = {'address': URL}
84
+
85
+ print(yaml.dump(spec))
86
+ ```
87
+
88
+ ## Development
89
+
90
+ ```console
91
+ $ pip install "/path/to/fastapi_swagger2/repo[test,all]"
92
+ ```
@@ -0,0 +1 @@
1
+ gitdir: /Users/vkanwade/Work/open_source/fastapi_swagger2/.git/worktrees/fastapi_0.100.0
@@ -0,0 +1,163 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
161
+
162
+
163
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Viraj Kanwade
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -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.6 - FastAPI >= 0.100.0, < 0.199.0 > + Pydantic v1/v2
29
+ * 0.2.7 - FastAPI >= 0.100.0, < 0.119.0 > + Pydantic v1/v2
30
30
 
31
31
  ## Installation
32
32
 
@@ -1,4 +1,4 @@
1
- __version__ = "0.2.6"
1
+ __version__ = "0.2.7"
2
2
 
3
3
  from typing import Any, Dict, List, Optional, TypeVar
4
4
 
@@ -1,9 +1,12 @@
1
1
  from enum import Enum
2
2
  from typing import Any, Callable, Dict, Iterable, List, Optional, Union
3
3
 
4
- from fastapi._compat import _model_rebuild
4
+ from fastapi._compat import PYDANTIC_V2, _model_rebuild
5
5
  from fastapi.logger import logger
6
- from pydantic import AnyUrl, BaseModel, Field
6
+ from pydantic import AnyUrl, BaseModel, Extra, Field
7
+
8
+ if PYDANTIC_V2:
9
+ from pydantic import ConfigDict
7
10
 
8
11
  try:
9
12
  import email_validator # type: ignore
@@ -31,14 +34,24 @@ class Contact(BaseModel):
31
34
  url: Optional[AnyUrl] = None
32
35
  email: Optional[EmailStr] = None
33
36
 
34
- model_config = {"extra": "allow"}
37
+ if PYDANTIC_V2:
38
+ model_config = ConfigDict(extra=Extra.allow)
39
+ else:
40
+
41
+ class Config:
42
+ extra = "allow"
35
43
 
36
44
 
37
45
  class License(BaseModel):
38
46
  name: str
39
47
  url: Optional[AnyUrl] = None
40
48
 
41
- model_config = {"extra": "allow"}
49
+ if PYDANTIC_V2:
50
+ model_config = ConfigDict(extra=Extra.allow)
51
+ else:
52
+
53
+ class Config:
54
+ extra = "allow"
42
55
 
43
56
 
44
57
  class Info(BaseModel):
@@ -49,7 +62,12 @@ class Info(BaseModel):
49
62
  license: Optional[License] = None
50
63
  version: str
51
64
 
52
- model_config = {"extra": "allow"}
65
+ if PYDANTIC_V2:
66
+ model_config = ConfigDict(extra=Extra.allow)
67
+ else:
68
+
69
+ class Config:
70
+ extra = "allow"
53
71
 
54
72
 
55
73
  # class URLHost(Field)
@@ -76,7 +94,12 @@ class ExternalDocumentation(BaseModel):
76
94
  description: Optional[str] = None
77
95
  url: AnyUrl
78
96
 
79
- model_config = {"extra": "allow"}
97
+ if PYDANTIC_V2:
98
+ model_config = ConfigDict(extra=Extra.allow)
99
+ else:
100
+
101
+ class Config:
102
+ extra = "allow"
80
103
 
81
104
 
82
105
  class Reference(BaseModel):
@@ -90,7 +113,12 @@ class XML(BaseModel):
90
113
  attribute: Optional[bool] = None
91
114
  wrapped: Optional[bool] = None
92
115
 
93
- model_config = {"extra": "allow"}
116
+ if PYDANTIC_V2:
117
+ model_config = ConfigDict(extra=Extra.allow)
118
+ else:
119
+
120
+ class Config:
121
+ extra = "allow"
94
122
 
95
123
 
96
124
  class Schema(BaseModel):
@@ -128,8 +156,12 @@ class Schema(BaseModel):
128
156
  externalDocs: Optional[ExternalDocumentation] = None
129
157
  example: Optional[Any] = None
130
158
 
131
- class Config:
132
- extra: str = "allow"
159
+ if PYDANTIC_V2:
160
+ model_config = ConfigDict(extra=Extra.allow)
161
+ else:
162
+
163
+ class Config:
164
+ extra = "allow"
133
165
 
134
166
 
135
167
  class _Schema2(BaseModel):
@@ -151,15 +183,23 @@ class _Schema2(BaseModel):
151
183
  enum: Optional[List[Any]] = None
152
184
  multipleOf: Optional[float] = None
153
185
 
154
- class Config:
155
- extra: str = "allow"
186
+ if PYDANTIC_V2:
187
+ model_config = ConfigDict(extra=Extra.allow)
188
+ else:
189
+
190
+ class Config:
191
+ extra = "allow"
156
192
 
157
193
 
158
194
  class ParameterSchema(_Schema2):
159
195
  allowEmptyValue: bool = False
160
196
 
161
- class Config:
162
- extra: str = "allow"
197
+ if PYDANTIC_V2:
198
+ model_config = ConfigDict(extra=Extra.allow)
199
+ else:
200
+
201
+ class Config:
202
+ extra = "allow"
163
203
 
164
204
 
165
205
  class ParameterInType(Enum):
@@ -176,7 +216,12 @@ class ParameterBase(BaseModel):
176
216
  description: Optional[str] = None
177
217
  required: Optional[bool] = None
178
218
 
179
- model_config = {"extra": "allow"}
219
+ if PYDANTIC_V2:
220
+ model_config = ConfigDict(extra=Extra.allow)
221
+ else:
222
+
223
+ class Config:
224
+ extra = "allow"
180
225
 
181
226
 
182
227
  class ParameterBody(ParameterBase):
@@ -188,7 +233,12 @@ class ParameterBody(ParameterBase):
188
233
  class ParameterNotBody(ParameterBase, ParameterSchema):
189
234
  pass
190
235
 
191
- model_config = {"extra": "allow"}
236
+ if PYDANTIC_V2:
237
+ model_config = ConfigDict(extra=Extra.allow)
238
+ else:
239
+
240
+ class Config:
241
+ extra = "allow"
192
242
 
193
243
 
194
244
  class Header(_Schema2):
@@ -201,7 +251,12 @@ class Response(BaseModel):
201
251
  headers: Optional[Dict[str, Union[Header, Reference]]] = None
202
252
  examples: Optional[Any] = None # XXX
203
253
 
204
- model_config = {"extra": "allow"}
254
+ if PYDANTIC_V2:
255
+ model_config = ConfigDict(extra=Extra.allow)
256
+ else:
257
+
258
+ class Config:
259
+ extra = "allow"
205
260
 
206
261
 
207
262
  class Operation(BaseModel):
@@ -219,7 +274,12 @@ class Operation(BaseModel):
219
274
  deprecated: Optional[bool] = None
220
275
  security: Optional[List[Dict[str, List[str]]]] = None
221
276
 
222
- model_config = {"extra": "allow"}
277
+ if PYDANTIC_V2:
278
+ model_config = ConfigDict(extra=Extra.allow)
279
+ else:
280
+
281
+ class Config:
282
+ extra = "allow"
223
283
 
224
284
 
225
285
  class PathItem(BaseModel):
@@ -233,7 +293,12 @@ class PathItem(BaseModel):
233
293
  patch: Optional[Operation] = None
234
294
  parameters: Optional[List[Union[ParameterBody, ParameterNotBody]]] = None
235
295
 
236
- model_config = {"extra": "allow"}
296
+ if PYDANTIC_V2:
297
+ model_config = ConfigDict(extra=Extra.allow)
298
+ else:
299
+
300
+ class Config:
301
+ extra = "allow"
237
302
 
238
303
 
239
304
  class SecuritySchemeType(Enum):
@@ -246,7 +311,12 @@ class SecurityBase(BaseModel):
246
311
  type_: SecuritySchemeType = Field(alias="type")
247
312
  description: Optional[str] = None
248
313
 
249
- model_config = {"extra": "allow"}
314
+ if PYDANTIC_V2:
315
+ model_config = ConfigDict(extra=Extra.allow)
316
+ else:
317
+
318
+ class Config:
319
+ extra = "allow"
250
320
 
251
321
 
252
322
  class BasicAuth(SecurityBase):
@@ -275,7 +345,12 @@ class OAuth2FlowBase(SecurityBase):
275
345
  flow: OAuth2FlowIn
276
346
  scopes: Dict[str, str] = {}
277
347
 
278
- model_config = {"extra": "allow"}
348
+ if PYDANTIC_V2:
349
+ model_config = ConfigDict(extra=Extra.allow)
350
+ else:
351
+
352
+ class Config:
353
+ extra = "allow"
279
354
 
280
355
 
281
356
  class OAuth2Implicit(OAuth2FlowBase):
@@ -310,7 +385,12 @@ class Tag(BaseModel):
310
385
  description: Optional[str] = None
311
386
  externalDocs: Optional[ExternalDocumentation] = None
312
387
 
313
- model_config = {"extra": "allow"}
388
+ if PYDANTIC_V2:
389
+ model_config = ConfigDict(extra=Extra.allow)
390
+ else:
391
+
392
+ class Config:
393
+ extra = "allow"
314
394
 
315
395
 
316
396
  class Swagger2(BaseModel):
@@ -332,7 +412,12 @@ class Swagger2(BaseModel):
332
412
  tags: Optional[List[Tag]] = None
333
413
  externalDocs: Optional[ExternalDocumentation] = None
334
414
 
335
- model_config = {"extra": "allow"}
415
+ if PYDANTIC_V2:
416
+ model_config = ConfigDict(extra=Extra.allow)
417
+ else:
418
+
419
+ class Config:
420
+ extra = "allow"
336
421
 
337
422
 
338
423
  _model_rebuild(Schema)
@@ -9,7 +9,6 @@ from fastapi._compat import (
9
9
  PYDANTIC_V2,
10
10
  GenerateJsonSchema,
11
11
  JsonSchemaValue,
12
- ModelField,
13
12
  Undefined,
14
13
  get_compat_model_name_map,
15
14
  lenient_issubclass,
@@ -39,8 +38,11 @@ from fastapi_swagger2.constants import REF_PREFIX, REF_TEMPLATE
39
38
  from fastapi_swagger2.models import Swagger2
40
39
 
41
40
  if PYDANTIC_V2:
42
- from fastapi._compat import get_definitions, get_schema_from_model_field
41
+ from fastapi._compat import ModelField, get_definitions, get_schema_from_model_field
43
42
  else:
43
+ from pydantic.fields import ( # type: ignore[attr-defined,no-redef,assignment,unused-ignore]
44
+ ModelField,
45
+ )
44
46
  from pydantic.schema import (
45
47
  field_schema,
46
48
  get_flat_models_from_fields,
@@ -76,7 +78,7 @@ else:
76
78
  ],
77
79
  Dict[str, Dict[str, Any]],
78
80
  ]:
79
- models = get_flat_models_from_fields(fields, known_models=set())
81
+ models = get_flat_models_from_fields(fields, known_models=set()) # type: ignore[arg-type,unused-ignore]
80
82
  return {}, get_model_definitions(
81
83
  flat_models=models, model_name_map=model_name_map
82
84
  )
@@ -92,8 +94,8 @@ else:
92
94
  separate_input_output_schemas: bool = True,
93
95
  ) -> Dict[str, Any]:
94
96
  # This expects that GenerateJsonSchema was already used to generate the definitions
95
- return field_schema( # type: ignore[no-any-return]
96
- field, model_name_map=model_name_map, ref_prefix=REF_PREFIX
97
+ return field_schema( # type: ignore[no-any-return,unused-ignore]
98
+ field, model_name_map=model_name_map, ref_prefix=REF_PREFIX # type: ignore[arg-type,unused-ignore]
97
99
  )[0]
98
100
 
99
101
 
@@ -562,11 +564,56 @@ def get_swagger2(
562
564
 
563
565
  for k, v in path.items():
564
566
  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
- )
567
+ if PYDANTIC_V2:
568
+ if "$ref" in param and param.get("in") != "body":
569
+ definition = definitions[
570
+ param.pop("$ref").split("/")[2]
571
+ ]
572
+ param.update(
573
+ {
574
+ k: v
575
+ for (k, v) in definition.items()
576
+ if k != "title"
577
+ }
578
+ )
579
+ else:
580
+ if "allOf" in param:
581
+ all_of = param.pop("allOf")
582
+ if len(all_of) > 1:
583
+ logger.warning(
584
+ f"fastapi_swagger2: Unable to handle allOf in path params {all_of}, using the first one."
585
+ )
586
+
587
+ if len(all_of) > 0:
588
+ definition = definitions[
589
+ all_of[0]["$ref"].split("/")[2]
590
+ ]
591
+ param.update(
592
+ {
593
+ k: v
594
+ for (k, v) in definition.items()
595
+ if k != "title"
596
+ }
597
+ )
598
+ if param.get("in") == "body" and "allOf" in param.get(
599
+ "schema", {}
600
+ ):
601
+ schema = param.pop("schema")
602
+ all_of = schema.pop("allOf")
603
+ if len(all_of) > 1:
604
+ logger.warning(
605
+ f"fastapi_swagger2: Unable to handle allOf in path params {all_of}, using the first one."
606
+ )
607
+
608
+ if len(all_of) > 0:
609
+ param["schema"] = {"$ref": all_of[0]["$ref"]}
610
+ param.update(
611
+ {
612
+ k: v
613
+ for (k, v) in schema.items()
614
+ if k != "title"
615
+ }
616
+ )
570
617
 
571
618
  if path:
572
619
  paths.setdefault(route.path_format, {}).update(path)