fastapi 0.99.1__py3-none-any.whl → 0.100.0__py3-none-any.whl
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.
Potentially problematic release.
This version of fastapi might be problematic. Click here for more details.
- fastapi/__init__.py +1 -1
- fastapi/_compat.py +616 -0
- fastapi/applications.py +21 -22
- fastapi/datastructures.py +31 -4
- fastapi/dependencies/models.py +1 -1
- fastapi/dependencies/utils.py +76 -120
- fastapi/encoders.py +90 -12
- fastapi/exceptions.py +20 -8
- fastapi/openapi/constants.py +1 -0
- fastapi/openapi/models.py +196 -53
- fastapi/openapi/utils.py +84 -40
- fastapi/param_functions.py +247 -16
- fastapi/params.py +347 -34
- fastapi/routing.py +84 -47
- fastapi/security/oauth2.py +16 -12
- fastapi/types.py +9 -1
- fastapi/utils.py +66 -60
- {fastapi-0.99.1.dist-info → fastapi-0.100.0.dist-info}/METADATA +7 -3
- {fastapi-0.99.1.dist-info → fastapi-0.100.0.dist-info}/RECORD +21 -20
- {fastapi-0.99.1.dist-info → fastapi-0.100.0.dist-info}/WHEEL +0 -0
- {fastapi-0.99.1.dist-info → fastapi-0.100.0.dist-info}/licenses/LICENSE +0 -0
fastapi/exceptions.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from typing import Any, Dict, Optional, Sequence, Type
|
|
2
2
|
|
|
3
|
-
from pydantic import BaseModel,
|
|
4
|
-
from pydantic.error_wrappers import ErrorList
|
|
3
|
+
from pydantic import BaseModel, create_model
|
|
5
4
|
from starlette.exceptions import HTTPException as StarletteHTTPException
|
|
6
5
|
from starlette.exceptions import WebSocketException as WebSocketException # noqa: F401
|
|
7
6
|
|
|
@@ -26,12 +25,25 @@ class FastAPIError(RuntimeError):
|
|
|
26
25
|
"""
|
|
27
26
|
|
|
28
27
|
|
|
29
|
-
class
|
|
30
|
-
def __init__(self, errors: Sequence[
|
|
28
|
+
class ValidationException(Exception):
|
|
29
|
+
def __init__(self, errors: Sequence[Any]) -> None:
|
|
30
|
+
self._errors = errors
|
|
31
|
+
|
|
32
|
+
def errors(self) -> Sequence[Any]:
|
|
33
|
+
return self._errors
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class RequestValidationError(ValidationException):
|
|
37
|
+
def __init__(self, errors: Sequence[Any], *, body: Any = None) -> None:
|
|
38
|
+
super().__init__(errors)
|
|
31
39
|
self.body = body
|
|
32
|
-
super().__init__(errors, RequestErrorModel)
|
|
33
40
|
|
|
34
41
|
|
|
35
|
-
class WebSocketRequestValidationError(
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
class WebSocketRequestValidationError(ValidationException):
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ResponseValidationError(ValidationException):
|
|
47
|
+
def __init__(self, errors: Sequence[Any], *, body: Any = None) -> None:
|
|
48
|
+
super().__init__(errors)
|
|
49
|
+
self.body = body
|
fastapi/openapi/constants.py
CHANGED
fastapi/openapi/models.py
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
from enum import Enum
|
|
2
|
-
from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Union
|
|
3
|
-
|
|
2
|
+
from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Type, Union
|
|
3
|
+
|
|
4
|
+
from fastapi._compat import (
|
|
5
|
+
PYDANTIC_V2,
|
|
6
|
+
CoreSchema,
|
|
7
|
+
GetJsonSchemaHandler,
|
|
8
|
+
JsonSchemaValue,
|
|
9
|
+
_model_rebuild,
|
|
10
|
+
general_plain_validator_function,
|
|
11
|
+
)
|
|
4
12
|
from fastapi.logger import logger
|
|
5
13
|
from pydantic import AnyUrl, BaseModel, Field
|
|
6
14
|
from typing_extensions import Annotated, Literal
|
|
7
15
|
from typing_extensions import deprecated as typing_deprecated
|
|
8
16
|
|
|
9
17
|
try:
|
|
10
|
-
import email_validator
|
|
18
|
+
import email_validator
|
|
11
19
|
|
|
12
20
|
assert email_validator # make autoflake ignore the unused import
|
|
13
21
|
from pydantic import EmailStr
|
|
@@ -26,14 +34,39 @@ except ImportError: # pragma: no cover
|
|
|
26
34
|
)
|
|
27
35
|
return str(v)
|
|
28
36
|
|
|
37
|
+
@classmethod
|
|
38
|
+
def _validate(cls, __input_value: Any, _: Any) -> str:
|
|
39
|
+
logger.warning(
|
|
40
|
+
"email-validator not installed, email fields will be treated as str.\n"
|
|
41
|
+
"To install, run: pip install email-validator"
|
|
42
|
+
)
|
|
43
|
+
return str(__input_value)
|
|
44
|
+
|
|
45
|
+
@classmethod
|
|
46
|
+
def __get_pydantic_json_schema__(
|
|
47
|
+
cls, core_schema: CoreSchema, handler: GetJsonSchemaHandler
|
|
48
|
+
) -> JsonSchemaValue:
|
|
49
|
+
return {"type": "string", "format": "email"}
|
|
50
|
+
|
|
51
|
+
@classmethod
|
|
52
|
+
def __get_pydantic_core_schema__(
|
|
53
|
+
cls, source: Type[Any], handler: Callable[[Any], CoreSchema]
|
|
54
|
+
) -> CoreSchema:
|
|
55
|
+
return general_plain_validator_function(cls._validate)
|
|
56
|
+
|
|
29
57
|
|
|
30
58
|
class Contact(BaseModel):
|
|
31
59
|
name: Optional[str] = None
|
|
32
60
|
url: Optional[AnyUrl] = None
|
|
33
61
|
email: Optional[EmailStr] = None
|
|
34
62
|
|
|
35
|
-
|
|
36
|
-
|
|
63
|
+
if PYDANTIC_V2:
|
|
64
|
+
model_config = {"extra": "allow"}
|
|
65
|
+
|
|
66
|
+
else:
|
|
67
|
+
|
|
68
|
+
class Config:
|
|
69
|
+
extra = "allow"
|
|
37
70
|
|
|
38
71
|
|
|
39
72
|
class License(BaseModel):
|
|
@@ -41,8 +74,13 @@ class License(BaseModel):
|
|
|
41
74
|
identifier: Optional[str] = None
|
|
42
75
|
url: Optional[AnyUrl] = None
|
|
43
76
|
|
|
44
|
-
|
|
45
|
-
|
|
77
|
+
if PYDANTIC_V2:
|
|
78
|
+
model_config = {"extra": "allow"}
|
|
79
|
+
|
|
80
|
+
else:
|
|
81
|
+
|
|
82
|
+
class Config:
|
|
83
|
+
extra = "allow"
|
|
46
84
|
|
|
47
85
|
|
|
48
86
|
class Info(BaseModel):
|
|
@@ -54,17 +92,27 @@ class Info(BaseModel):
|
|
|
54
92
|
license: Optional[License] = None
|
|
55
93
|
version: str
|
|
56
94
|
|
|
57
|
-
|
|
58
|
-
|
|
95
|
+
if PYDANTIC_V2:
|
|
96
|
+
model_config = {"extra": "allow"}
|
|
97
|
+
|
|
98
|
+
else:
|
|
99
|
+
|
|
100
|
+
class Config:
|
|
101
|
+
extra = "allow"
|
|
59
102
|
|
|
60
103
|
|
|
61
104
|
class ServerVariable(BaseModel):
|
|
62
|
-
enum: Annotated[Optional[List[str]], Field(
|
|
105
|
+
enum: Annotated[Optional[List[str]], Field(min_length=1)] = None
|
|
63
106
|
default: str
|
|
64
107
|
description: Optional[str] = None
|
|
65
108
|
|
|
66
|
-
|
|
67
|
-
|
|
109
|
+
if PYDANTIC_V2:
|
|
110
|
+
model_config = {"extra": "allow"}
|
|
111
|
+
|
|
112
|
+
else:
|
|
113
|
+
|
|
114
|
+
class Config:
|
|
115
|
+
extra = "allow"
|
|
68
116
|
|
|
69
117
|
|
|
70
118
|
class Server(BaseModel):
|
|
@@ -72,8 +120,13 @@ class Server(BaseModel):
|
|
|
72
120
|
description: Optional[str] = None
|
|
73
121
|
variables: Optional[Dict[str, ServerVariable]] = None
|
|
74
122
|
|
|
75
|
-
|
|
76
|
-
|
|
123
|
+
if PYDANTIC_V2:
|
|
124
|
+
model_config = {"extra": "allow"}
|
|
125
|
+
|
|
126
|
+
else:
|
|
127
|
+
|
|
128
|
+
class Config:
|
|
129
|
+
extra = "allow"
|
|
77
130
|
|
|
78
131
|
|
|
79
132
|
class Reference(BaseModel):
|
|
@@ -92,16 +145,26 @@ class XML(BaseModel):
|
|
|
92
145
|
attribute: Optional[bool] = None
|
|
93
146
|
wrapped: Optional[bool] = None
|
|
94
147
|
|
|
95
|
-
|
|
96
|
-
|
|
148
|
+
if PYDANTIC_V2:
|
|
149
|
+
model_config = {"extra": "allow"}
|
|
150
|
+
|
|
151
|
+
else:
|
|
152
|
+
|
|
153
|
+
class Config:
|
|
154
|
+
extra = "allow"
|
|
97
155
|
|
|
98
156
|
|
|
99
157
|
class ExternalDocumentation(BaseModel):
|
|
100
158
|
description: Optional[str] = None
|
|
101
159
|
url: AnyUrl
|
|
102
160
|
|
|
103
|
-
|
|
104
|
-
|
|
161
|
+
if PYDANTIC_V2:
|
|
162
|
+
model_config = {"extra": "allow"}
|
|
163
|
+
|
|
164
|
+
else:
|
|
165
|
+
|
|
166
|
+
class Config:
|
|
167
|
+
extra = "allow"
|
|
105
168
|
|
|
106
169
|
|
|
107
170
|
class Schema(BaseModel):
|
|
@@ -190,8 +253,13 @@ class Schema(BaseModel):
|
|
|
190
253
|
),
|
|
191
254
|
] = None
|
|
192
255
|
|
|
193
|
-
|
|
194
|
-
|
|
256
|
+
if PYDANTIC_V2:
|
|
257
|
+
model_config = {"extra": "allow"}
|
|
258
|
+
|
|
259
|
+
else:
|
|
260
|
+
|
|
261
|
+
class Config:
|
|
262
|
+
extra = "allow"
|
|
195
263
|
|
|
196
264
|
|
|
197
265
|
# Ref: https://json-schema.org/draft/2020-12/json-schema-core.html#name-json-schema-documents
|
|
@@ -205,8 +273,13 @@ class Example(BaseModel):
|
|
|
205
273
|
value: Optional[Any] = None
|
|
206
274
|
externalValue: Optional[AnyUrl] = None
|
|
207
275
|
|
|
208
|
-
|
|
209
|
-
|
|
276
|
+
if PYDANTIC_V2:
|
|
277
|
+
model_config = {"extra": "allow"}
|
|
278
|
+
|
|
279
|
+
else:
|
|
280
|
+
|
|
281
|
+
class Config:
|
|
282
|
+
extra = "allow"
|
|
210
283
|
|
|
211
284
|
|
|
212
285
|
class ParameterInType(Enum):
|
|
@@ -223,8 +296,13 @@ class Encoding(BaseModel):
|
|
|
223
296
|
explode: Optional[bool] = None
|
|
224
297
|
allowReserved: Optional[bool] = None
|
|
225
298
|
|
|
226
|
-
|
|
227
|
-
|
|
299
|
+
if PYDANTIC_V2:
|
|
300
|
+
model_config = {"extra": "allow"}
|
|
301
|
+
|
|
302
|
+
else:
|
|
303
|
+
|
|
304
|
+
class Config:
|
|
305
|
+
extra = "allow"
|
|
228
306
|
|
|
229
307
|
|
|
230
308
|
class MediaType(BaseModel):
|
|
@@ -233,8 +311,13 @@ class MediaType(BaseModel):
|
|
|
233
311
|
examples: Optional[Dict[str, Union[Example, Reference]]] = None
|
|
234
312
|
encoding: Optional[Dict[str, Encoding]] = None
|
|
235
313
|
|
|
236
|
-
|
|
237
|
-
|
|
314
|
+
if PYDANTIC_V2:
|
|
315
|
+
model_config = {"extra": "allow"}
|
|
316
|
+
|
|
317
|
+
else:
|
|
318
|
+
|
|
319
|
+
class Config:
|
|
320
|
+
extra = "allow"
|
|
238
321
|
|
|
239
322
|
|
|
240
323
|
class ParameterBase(BaseModel):
|
|
@@ -251,8 +334,13 @@ class ParameterBase(BaseModel):
|
|
|
251
334
|
# Serialization rules for more complex scenarios
|
|
252
335
|
content: Optional[Dict[str, MediaType]] = None
|
|
253
336
|
|
|
254
|
-
|
|
255
|
-
|
|
337
|
+
if PYDANTIC_V2:
|
|
338
|
+
model_config = {"extra": "allow"}
|
|
339
|
+
|
|
340
|
+
else:
|
|
341
|
+
|
|
342
|
+
class Config:
|
|
343
|
+
extra = "allow"
|
|
256
344
|
|
|
257
345
|
|
|
258
346
|
class Parameter(ParameterBase):
|
|
@@ -269,8 +357,13 @@ class RequestBody(BaseModel):
|
|
|
269
357
|
content: Dict[str, MediaType]
|
|
270
358
|
required: Optional[bool] = None
|
|
271
359
|
|
|
272
|
-
|
|
273
|
-
|
|
360
|
+
if PYDANTIC_V2:
|
|
361
|
+
model_config = {"extra": "allow"}
|
|
362
|
+
|
|
363
|
+
else:
|
|
364
|
+
|
|
365
|
+
class Config:
|
|
366
|
+
extra = "allow"
|
|
274
367
|
|
|
275
368
|
|
|
276
369
|
class Link(BaseModel):
|
|
@@ -281,8 +374,13 @@ class Link(BaseModel):
|
|
|
281
374
|
description: Optional[str] = None
|
|
282
375
|
server: Optional[Server] = None
|
|
283
376
|
|
|
284
|
-
|
|
285
|
-
|
|
377
|
+
if PYDANTIC_V2:
|
|
378
|
+
model_config = {"extra": "allow"}
|
|
379
|
+
|
|
380
|
+
else:
|
|
381
|
+
|
|
382
|
+
class Config:
|
|
383
|
+
extra = "allow"
|
|
286
384
|
|
|
287
385
|
|
|
288
386
|
class Response(BaseModel):
|
|
@@ -291,8 +389,13 @@ class Response(BaseModel):
|
|
|
291
389
|
content: Optional[Dict[str, MediaType]] = None
|
|
292
390
|
links: Optional[Dict[str, Union[Link, Reference]]] = None
|
|
293
391
|
|
|
294
|
-
|
|
295
|
-
|
|
392
|
+
if PYDANTIC_V2:
|
|
393
|
+
model_config = {"extra": "allow"}
|
|
394
|
+
|
|
395
|
+
else:
|
|
396
|
+
|
|
397
|
+
class Config:
|
|
398
|
+
extra = "allow"
|
|
296
399
|
|
|
297
400
|
|
|
298
401
|
class Operation(BaseModel):
|
|
@@ -310,8 +413,13 @@ class Operation(BaseModel):
|
|
|
310
413
|
security: Optional[List[Dict[str, List[str]]]] = None
|
|
311
414
|
servers: Optional[List[Server]] = None
|
|
312
415
|
|
|
313
|
-
|
|
314
|
-
|
|
416
|
+
if PYDANTIC_V2:
|
|
417
|
+
model_config = {"extra": "allow"}
|
|
418
|
+
|
|
419
|
+
else:
|
|
420
|
+
|
|
421
|
+
class Config:
|
|
422
|
+
extra = "allow"
|
|
315
423
|
|
|
316
424
|
|
|
317
425
|
class PathItem(BaseModel):
|
|
@@ -329,8 +437,13 @@ class PathItem(BaseModel):
|
|
|
329
437
|
servers: Optional[List[Server]] = None
|
|
330
438
|
parameters: Optional[List[Union[Parameter, Reference]]] = None
|
|
331
439
|
|
|
332
|
-
|
|
333
|
-
|
|
440
|
+
if PYDANTIC_V2:
|
|
441
|
+
model_config = {"extra": "allow"}
|
|
442
|
+
|
|
443
|
+
else:
|
|
444
|
+
|
|
445
|
+
class Config:
|
|
446
|
+
extra = "allow"
|
|
334
447
|
|
|
335
448
|
|
|
336
449
|
class SecuritySchemeType(Enum):
|
|
@@ -344,8 +457,13 @@ class SecurityBase(BaseModel):
|
|
|
344
457
|
type_: SecuritySchemeType = Field(alias="type")
|
|
345
458
|
description: Optional[str] = None
|
|
346
459
|
|
|
347
|
-
|
|
348
|
-
|
|
460
|
+
if PYDANTIC_V2:
|
|
461
|
+
model_config = {"extra": "allow"}
|
|
462
|
+
|
|
463
|
+
else:
|
|
464
|
+
|
|
465
|
+
class Config:
|
|
466
|
+
extra = "allow"
|
|
349
467
|
|
|
350
468
|
|
|
351
469
|
class APIKeyIn(Enum):
|
|
@@ -374,8 +492,13 @@ class OAuthFlow(BaseModel):
|
|
|
374
492
|
refreshUrl: Optional[str] = None
|
|
375
493
|
scopes: Dict[str, str] = {}
|
|
376
494
|
|
|
377
|
-
|
|
378
|
-
|
|
495
|
+
if PYDANTIC_V2:
|
|
496
|
+
model_config = {"extra": "allow"}
|
|
497
|
+
|
|
498
|
+
else:
|
|
499
|
+
|
|
500
|
+
class Config:
|
|
501
|
+
extra = "allow"
|
|
379
502
|
|
|
380
503
|
|
|
381
504
|
class OAuthFlowImplicit(OAuthFlow):
|
|
@@ -401,8 +524,13 @@ class OAuthFlows(BaseModel):
|
|
|
401
524
|
clientCredentials: Optional[OAuthFlowClientCredentials] = None
|
|
402
525
|
authorizationCode: Optional[OAuthFlowAuthorizationCode] = None
|
|
403
526
|
|
|
404
|
-
|
|
405
|
-
|
|
527
|
+
if PYDANTIC_V2:
|
|
528
|
+
model_config = {"extra": "allow"}
|
|
529
|
+
|
|
530
|
+
else:
|
|
531
|
+
|
|
532
|
+
class Config:
|
|
533
|
+
extra = "allow"
|
|
406
534
|
|
|
407
535
|
|
|
408
536
|
class OAuth2(SecurityBase):
|
|
@@ -433,8 +561,13 @@ class Components(BaseModel):
|
|
|
433
561
|
callbacks: Optional[Dict[str, Union[Dict[str, PathItem], Reference, Any]]] = None
|
|
434
562
|
pathItems: Optional[Dict[str, Union[PathItem, Reference]]] = None
|
|
435
563
|
|
|
436
|
-
|
|
437
|
-
|
|
564
|
+
if PYDANTIC_V2:
|
|
565
|
+
model_config = {"extra": "allow"}
|
|
566
|
+
|
|
567
|
+
else:
|
|
568
|
+
|
|
569
|
+
class Config:
|
|
570
|
+
extra = "allow"
|
|
438
571
|
|
|
439
572
|
|
|
440
573
|
class Tag(BaseModel):
|
|
@@ -442,8 +575,13 @@ class Tag(BaseModel):
|
|
|
442
575
|
description: Optional[str] = None
|
|
443
576
|
externalDocs: Optional[ExternalDocumentation] = None
|
|
444
577
|
|
|
445
|
-
|
|
446
|
-
|
|
578
|
+
if PYDANTIC_V2:
|
|
579
|
+
model_config = {"extra": "allow"}
|
|
580
|
+
|
|
581
|
+
else:
|
|
582
|
+
|
|
583
|
+
class Config:
|
|
584
|
+
extra = "allow"
|
|
447
585
|
|
|
448
586
|
|
|
449
587
|
class OpenAPI(BaseModel):
|
|
@@ -459,10 +597,15 @@ class OpenAPI(BaseModel):
|
|
|
459
597
|
tags: Optional[List[Tag]] = None
|
|
460
598
|
externalDocs: Optional[ExternalDocumentation] = None
|
|
461
599
|
|
|
462
|
-
|
|
463
|
-
|
|
600
|
+
if PYDANTIC_V2:
|
|
601
|
+
model_config = {"extra": "allow"}
|
|
602
|
+
|
|
603
|
+
else:
|
|
604
|
+
|
|
605
|
+
class Config:
|
|
606
|
+
extra = "allow"
|
|
464
607
|
|
|
465
608
|
|
|
466
|
-
Schema
|
|
467
|
-
Operation
|
|
468
|
-
Encoding
|
|
609
|
+
_model_rebuild(Schema)
|
|
610
|
+
_model_rebuild(Operation)
|
|
611
|
+
_model_rebuild(Encoding)
|