Coverage for fastapi/params.py: 100%
103 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1import warnings 1deabc
2from enum import Enum 1deabc
3from typing import Any, Callable, Dict, List, Optional, Sequence, Union 1deabc
5from fastapi.openapi.models import Example 1deabc
6from pydantic.fields import FieldInfo 1deabc
7from typing_extensions import Annotated, deprecated 1deabc
9from ._compat import PYDANTIC_V2, PYDANTIC_VERSION, Undefined 1deabc
11_Unset: Any = Undefined 1deabc
14class ParamTypes(Enum): 1deabc
15 query = "query" 1deabc
16 header = "header" 1deabc
17 path = "path" 1deabc
18 cookie = "cookie" 1deabc
21class Param(FieldInfo): 1deabc
22 in_: ParamTypes 1deabc
24 def __init__( 1deabc
25 self,
26 default: Any = Undefined,
27 *,
28 default_factory: Union[Callable[[], Any], None] = _Unset,
29 annotation: Optional[Any] = None,
30 alias: Optional[str] = None,
31 alias_priority: Union[int, None] = _Unset,
32 # TODO: update when deprecating Pydantic v1, import these types
33 # validation_alias: str | AliasPath | AliasChoices | None
34 validation_alias: Union[str, None] = None,
35 serialization_alias: Union[str, None] = None,
36 title: Optional[str] = None,
37 description: Optional[str] = None,
38 gt: Optional[float] = None,
39 ge: Optional[float] = None,
40 lt: Optional[float] = None,
41 le: Optional[float] = None,
42 min_length: Optional[int] = None,
43 max_length: Optional[int] = None,
44 pattern: Optional[str] = None,
45 regex: Annotated[
46 Optional[str],
47 deprecated(
48 "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
49 ),
50 ] = None,
51 discriminator: Union[str, None] = None,
52 strict: Union[bool, None] = _Unset,
53 multiple_of: Union[float, None] = _Unset,
54 allow_inf_nan: Union[bool, None] = _Unset,
55 max_digits: Union[int, None] = _Unset,
56 decimal_places: Union[int, None] = _Unset,
57 examples: Optional[List[Any]] = None,
58 example: Annotated[
59 Optional[Any],
60 deprecated(
61 "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
62 "although still supported. Use examples instead."
63 ),
64 ] = _Unset,
65 openapi_examples: Optional[Dict[str, Example]] = None,
66 deprecated: Union[deprecated, str, bool, None] = None,
67 include_in_schema: bool = True,
68 json_schema_extra: Union[Dict[str, Any], None] = None,
69 **extra: Any,
70 ):
71 if example is not _Unset: 1deabc
72 warnings.warn( 1deabc
73 "`example` has been deprecated, please use `examples` instead",
74 category=DeprecationWarning,
75 stacklevel=4,
76 )
77 self.example = example 1deabc
78 self.include_in_schema = include_in_schema 1deabc
79 self.openapi_examples = openapi_examples 1deabc
80 kwargs = dict( 1deabc
81 default=default,
82 default_factory=default_factory,
83 alias=alias,
84 title=title,
85 description=description,
86 gt=gt,
87 ge=ge,
88 lt=lt,
89 le=le,
90 min_length=min_length,
91 max_length=max_length,
92 discriminator=discriminator,
93 multiple_of=multiple_of,
94 allow_nan=allow_inf_nan,
95 max_digits=max_digits,
96 decimal_places=decimal_places,
97 **extra,
98 )
99 if examples is not None: 1deabc
100 kwargs["examples"] = examples 1deabc
101 if regex is not None: 1deabc
102 warnings.warn( 1abc
103 "`regex` has been deprecated, please use `pattern` instead",
104 category=DeprecationWarning,
105 stacklevel=4,
106 )
107 current_json_schema_extra = json_schema_extra or extra 1deabc
108 if PYDANTIC_VERSION < "2.7.0": 1deabc
109 self.deprecated = deprecated 1deabc
110 else:
111 kwargs["deprecated"] = deprecated 1deabc
112 if PYDANTIC_V2: 1deabc
113 kwargs.update( 1deabc
114 {
115 "annotation": annotation,
116 "alias_priority": alias_priority,
117 "validation_alias": validation_alias,
118 "serialization_alias": serialization_alias,
119 "strict": strict,
120 "json_schema_extra": current_json_schema_extra,
121 }
122 )
123 kwargs["pattern"] = pattern or regex 1deabc
124 else:
125 kwargs["regex"] = pattern or regex 1deabc
126 kwargs.update(**current_json_schema_extra) 1deabc
127 use_kwargs = {k: v for k, v in kwargs.items() if v is not _Unset} 1deabc
129 super().__init__(**use_kwargs) 1deabc
131 def __repr__(self) -> str: 1deabc
132 return f"{self.__class__.__name__}({self.default})" 1deabc
135class Path(Param): 1deabc
136 in_ = ParamTypes.path 1deabc
138 def __init__( 1deabc
139 self,
140 default: Any = ...,
141 *,
142 default_factory: Union[Callable[[], Any], None] = _Unset,
143 annotation: Optional[Any] = None,
144 alias: Optional[str] = None,
145 alias_priority: Union[int, None] = _Unset,
146 # TODO: update when deprecating Pydantic v1, import these types
147 # validation_alias: str | AliasPath | AliasChoices | None
148 validation_alias: Union[str, None] = None,
149 serialization_alias: Union[str, None] = None,
150 title: Optional[str] = None,
151 description: Optional[str] = None,
152 gt: Optional[float] = None,
153 ge: Optional[float] = None,
154 lt: Optional[float] = None,
155 le: Optional[float] = None,
156 min_length: Optional[int] = None,
157 max_length: Optional[int] = None,
158 pattern: Optional[str] = None,
159 regex: Annotated[
160 Optional[str],
161 deprecated(
162 "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
163 ),
164 ] = None,
165 discriminator: Union[str, None] = None,
166 strict: Union[bool, None] = _Unset,
167 multiple_of: Union[float, None] = _Unset,
168 allow_inf_nan: Union[bool, None] = _Unset,
169 max_digits: Union[int, None] = _Unset,
170 decimal_places: Union[int, None] = _Unset,
171 examples: Optional[List[Any]] = None,
172 example: Annotated[
173 Optional[Any],
174 deprecated(
175 "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
176 "although still supported. Use examples instead."
177 ),
178 ] = _Unset,
179 openapi_examples: Optional[Dict[str, Example]] = None,
180 deprecated: Union[deprecated, str, bool, None] = None,
181 include_in_schema: bool = True,
182 json_schema_extra: Union[Dict[str, Any], None] = None,
183 **extra: Any,
184 ):
185 assert default is ..., "Path parameters cannot have a default value" 1deabc
186 self.in_ = self.in_ 1deabc
187 super().__init__( 1deabc
188 default=default,
189 default_factory=default_factory,
190 annotation=annotation,
191 alias=alias,
192 alias_priority=alias_priority,
193 validation_alias=validation_alias,
194 serialization_alias=serialization_alias,
195 title=title,
196 description=description,
197 gt=gt,
198 ge=ge,
199 lt=lt,
200 le=le,
201 min_length=min_length,
202 max_length=max_length,
203 pattern=pattern,
204 regex=regex,
205 discriminator=discriminator,
206 strict=strict,
207 multiple_of=multiple_of,
208 allow_inf_nan=allow_inf_nan,
209 max_digits=max_digits,
210 decimal_places=decimal_places,
211 deprecated=deprecated,
212 example=example,
213 examples=examples,
214 openapi_examples=openapi_examples,
215 include_in_schema=include_in_schema,
216 json_schema_extra=json_schema_extra,
217 **extra,
218 )
221class Query(Param): 1deabc
222 in_ = ParamTypes.query 1deabc
224 def __init__( 1deabc
225 self,
226 default: Any = Undefined,
227 *,
228 default_factory: Union[Callable[[], Any], None] = _Unset,
229 annotation: Optional[Any] = None,
230 alias: Optional[str] = None,
231 alias_priority: Union[int, None] = _Unset,
232 # TODO: update when deprecating Pydantic v1, import these types
233 # validation_alias: str | AliasPath | AliasChoices | None
234 validation_alias: Union[str, None] = None,
235 serialization_alias: Union[str, None] = None,
236 title: Optional[str] = None,
237 description: Optional[str] = None,
238 gt: Optional[float] = None,
239 ge: Optional[float] = None,
240 lt: Optional[float] = None,
241 le: Optional[float] = None,
242 min_length: Optional[int] = None,
243 max_length: Optional[int] = None,
244 pattern: Optional[str] = None,
245 regex: Annotated[
246 Optional[str],
247 deprecated(
248 "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
249 ),
250 ] = None,
251 discriminator: Union[str, None] = None,
252 strict: Union[bool, None] = _Unset,
253 multiple_of: Union[float, None] = _Unset,
254 allow_inf_nan: Union[bool, None] = _Unset,
255 max_digits: Union[int, None] = _Unset,
256 decimal_places: Union[int, None] = _Unset,
257 examples: Optional[List[Any]] = None,
258 example: Annotated[
259 Optional[Any],
260 deprecated(
261 "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
262 "although still supported. Use examples instead."
263 ),
264 ] = _Unset,
265 openapi_examples: Optional[Dict[str, Example]] = None,
266 deprecated: Union[deprecated, str, bool, None] = None,
267 include_in_schema: bool = True,
268 json_schema_extra: Union[Dict[str, Any], None] = None,
269 **extra: Any,
270 ):
271 super().__init__( 1deabc
272 default=default,
273 default_factory=default_factory,
274 annotation=annotation,
275 alias=alias,
276 alias_priority=alias_priority,
277 validation_alias=validation_alias,
278 serialization_alias=serialization_alias,
279 title=title,
280 description=description,
281 gt=gt,
282 ge=ge,
283 lt=lt,
284 le=le,
285 min_length=min_length,
286 max_length=max_length,
287 pattern=pattern,
288 regex=regex,
289 discriminator=discriminator,
290 strict=strict,
291 multiple_of=multiple_of,
292 allow_inf_nan=allow_inf_nan,
293 max_digits=max_digits,
294 decimal_places=decimal_places,
295 deprecated=deprecated,
296 example=example,
297 examples=examples,
298 openapi_examples=openapi_examples,
299 include_in_schema=include_in_schema,
300 json_schema_extra=json_schema_extra,
301 **extra,
302 )
305class Header(Param): 1deabc
306 in_ = ParamTypes.header 1deabc
308 def __init__( 1deabc
309 self,
310 default: Any = Undefined,
311 *,
312 default_factory: Union[Callable[[], Any], None] = _Unset,
313 annotation: Optional[Any] = None,
314 alias: Optional[str] = None,
315 alias_priority: Union[int, None] = _Unset,
316 # TODO: update when deprecating Pydantic v1, import these types
317 # validation_alias: str | AliasPath | AliasChoices | None
318 validation_alias: Union[str, None] = None,
319 serialization_alias: Union[str, None] = None,
320 convert_underscores: bool = True,
321 title: Optional[str] = None,
322 description: Optional[str] = None,
323 gt: Optional[float] = None,
324 ge: Optional[float] = None,
325 lt: Optional[float] = None,
326 le: Optional[float] = None,
327 min_length: Optional[int] = None,
328 max_length: Optional[int] = None,
329 pattern: Optional[str] = None,
330 regex: Annotated[
331 Optional[str],
332 deprecated(
333 "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
334 ),
335 ] = None,
336 discriminator: Union[str, None] = None,
337 strict: Union[bool, None] = _Unset,
338 multiple_of: Union[float, None] = _Unset,
339 allow_inf_nan: Union[bool, None] = _Unset,
340 max_digits: Union[int, None] = _Unset,
341 decimal_places: Union[int, None] = _Unset,
342 examples: Optional[List[Any]] = None,
343 example: Annotated[
344 Optional[Any],
345 deprecated(
346 "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
347 "although still supported. Use examples instead."
348 ),
349 ] = _Unset,
350 openapi_examples: Optional[Dict[str, Example]] = None,
351 deprecated: Union[deprecated, str, bool, None] = None,
352 include_in_schema: bool = True,
353 json_schema_extra: Union[Dict[str, Any], None] = None,
354 **extra: Any,
355 ):
356 self.convert_underscores = convert_underscores 1deabc
357 super().__init__( 1deabc
358 default=default,
359 default_factory=default_factory,
360 annotation=annotation,
361 alias=alias,
362 alias_priority=alias_priority,
363 validation_alias=validation_alias,
364 serialization_alias=serialization_alias,
365 title=title,
366 description=description,
367 gt=gt,
368 ge=ge,
369 lt=lt,
370 le=le,
371 min_length=min_length,
372 max_length=max_length,
373 pattern=pattern,
374 regex=regex,
375 discriminator=discriminator,
376 strict=strict,
377 multiple_of=multiple_of,
378 allow_inf_nan=allow_inf_nan,
379 max_digits=max_digits,
380 decimal_places=decimal_places,
381 deprecated=deprecated,
382 example=example,
383 examples=examples,
384 openapi_examples=openapi_examples,
385 include_in_schema=include_in_schema,
386 json_schema_extra=json_schema_extra,
387 **extra,
388 )
391class Cookie(Param): 1deabc
392 in_ = ParamTypes.cookie 1deabc
394 def __init__( 1deabc
395 self,
396 default: Any = Undefined,
397 *,
398 default_factory: Union[Callable[[], Any], None] = _Unset,
399 annotation: Optional[Any] = None,
400 alias: Optional[str] = None,
401 alias_priority: Union[int, None] = _Unset,
402 # TODO: update when deprecating Pydantic v1, import these types
403 # validation_alias: str | AliasPath | AliasChoices | None
404 validation_alias: Union[str, None] = None,
405 serialization_alias: Union[str, None] = None,
406 title: Optional[str] = None,
407 description: Optional[str] = None,
408 gt: Optional[float] = None,
409 ge: Optional[float] = None,
410 lt: Optional[float] = None,
411 le: Optional[float] = None,
412 min_length: Optional[int] = None,
413 max_length: Optional[int] = None,
414 pattern: Optional[str] = None,
415 regex: Annotated[
416 Optional[str],
417 deprecated(
418 "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
419 ),
420 ] = None,
421 discriminator: Union[str, None] = None,
422 strict: Union[bool, None] = _Unset,
423 multiple_of: Union[float, None] = _Unset,
424 allow_inf_nan: Union[bool, None] = _Unset,
425 max_digits: Union[int, None] = _Unset,
426 decimal_places: Union[int, None] = _Unset,
427 examples: Optional[List[Any]] = None,
428 example: Annotated[
429 Optional[Any],
430 deprecated(
431 "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
432 "although still supported. Use examples instead."
433 ),
434 ] = _Unset,
435 openapi_examples: Optional[Dict[str, Example]] = None,
436 deprecated: Union[deprecated, str, bool, None] = None,
437 include_in_schema: bool = True,
438 json_schema_extra: Union[Dict[str, Any], None] = None,
439 **extra: Any,
440 ):
441 super().__init__( 1deabc
442 default=default,
443 default_factory=default_factory,
444 annotation=annotation,
445 alias=alias,
446 alias_priority=alias_priority,
447 validation_alias=validation_alias,
448 serialization_alias=serialization_alias,
449 title=title,
450 description=description,
451 gt=gt,
452 ge=ge,
453 lt=lt,
454 le=le,
455 min_length=min_length,
456 max_length=max_length,
457 pattern=pattern,
458 regex=regex,
459 discriminator=discriminator,
460 strict=strict,
461 multiple_of=multiple_of,
462 allow_inf_nan=allow_inf_nan,
463 max_digits=max_digits,
464 decimal_places=decimal_places,
465 deprecated=deprecated,
466 example=example,
467 examples=examples,
468 openapi_examples=openapi_examples,
469 include_in_schema=include_in_schema,
470 json_schema_extra=json_schema_extra,
471 **extra,
472 )
475class Body(FieldInfo): 1deabc
476 def __init__( 1deabc
477 self,
478 default: Any = Undefined,
479 *,
480 default_factory: Union[Callable[[], Any], None] = _Unset,
481 annotation: Optional[Any] = None,
482 embed: bool = False,
483 media_type: str = "application/json",
484 alias: Optional[str] = None,
485 alias_priority: Union[int, None] = _Unset,
486 # TODO: update when deprecating Pydantic v1, import these types
487 # validation_alias: str | AliasPath | AliasChoices | None
488 validation_alias: Union[str, None] = None,
489 serialization_alias: Union[str, None] = None,
490 title: Optional[str] = None,
491 description: Optional[str] = None,
492 gt: Optional[float] = None,
493 ge: Optional[float] = None,
494 lt: Optional[float] = None,
495 le: Optional[float] = None,
496 min_length: Optional[int] = None,
497 max_length: Optional[int] = None,
498 pattern: Optional[str] = None,
499 regex: Annotated[
500 Optional[str],
501 deprecated(
502 "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
503 ),
504 ] = None,
505 discriminator: Union[str, None] = None,
506 strict: Union[bool, None] = _Unset,
507 multiple_of: Union[float, None] = _Unset,
508 allow_inf_nan: Union[bool, None] = _Unset,
509 max_digits: Union[int, None] = _Unset,
510 decimal_places: Union[int, None] = _Unset,
511 examples: Optional[List[Any]] = None,
512 example: Annotated[
513 Optional[Any],
514 deprecated(
515 "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
516 "although still supported. Use examples instead."
517 ),
518 ] = _Unset,
519 openapi_examples: Optional[Dict[str, Example]] = None,
520 deprecated: Union[deprecated, str, bool, None] = None,
521 include_in_schema: bool = True,
522 json_schema_extra: Union[Dict[str, Any], None] = None,
523 **extra: Any,
524 ):
525 self.embed = embed 1deabc
526 self.media_type = media_type 1deabc
527 if example is not _Unset: 1deabc
528 warnings.warn( 1deabc
529 "`example` has been deprecated, please use `examples` instead",
530 category=DeprecationWarning,
531 stacklevel=4,
532 )
533 self.example = example 1deabc
534 self.include_in_schema = include_in_schema 1deabc
535 self.openapi_examples = openapi_examples 1deabc
536 kwargs = dict( 1deabc
537 default=default,
538 default_factory=default_factory,
539 alias=alias,
540 title=title,
541 description=description,
542 gt=gt,
543 ge=ge,
544 lt=lt,
545 le=le,
546 min_length=min_length,
547 max_length=max_length,
548 discriminator=discriminator,
549 multiple_of=multiple_of,
550 allow_nan=allow_inf_nan,
551 max_digits=max_digits,
552 decimal_places=decimal_places,
553 **extra,
554 )
555 if examples is not None: 1deabc
556 kwargs["examples"] = examples 1deabc
557 if regex is not None: 1deabc
558 warnings.warn( 1abc
559 "`regex` has been depreacated, please use `pattern` instead",
560 category=DeprecationWarning,
561 stacklevel=4,
562 )
563 current_json_schema_extra = json_schema_extra or extra 1deabc
564 if PYDANTIC_VERSION < "2.7.0": 1deabc
565 self.deprecated = deprecated 1deabc
566 else:
567 kwargs["deprecated"] = deprecated 1deabc
568 if PYDANTIC_V2: 1deabc
569 kwargs.update( 1deabc
570 {
571 "annotation": annotation,
572 "alias_priority": alias_priority,
573 "validation_alias": validation_alias,
574 "serialization_alias": serialization_alias,
575 "strict": strict,
576 "json_schema_extra": current_json_schema_extra,
577 }
578 )
579 kwargs["pattern"] = pattern or regex 1deabc
580 else:
581 kwargs["regex"] = pattern or regex 1deabc
582 kwargs.update(**current_json_schema_extra) 1deabc
584 use_kwargs = {k: v for k, v in kwargs.items() if v is not _Unset} 1deabc
586 super().__init__(**use_kwargs) 1deabc
588 def __repr__(self) -> str: 1deabc
589 return f"{self.__class__.__name__}({self.default})" 1deabc
592class Form(Body): 1deabc
593 def __init__( 1deabc
594 self,
595 default: Any = Undefined,
596 *,
597 default_factory: Union[Callable[[], Any], None] = _Unset,
598 annotation: Optional[Any] = None,
599 media_type: str = "application/x-www-form-urlencoded",
600 alias: Optional[str] = None,
601 alias_priority: Union[int, None] = _Unset,
602 # TODO: update when deprecating Pydantic v1, import these types
603 # validation_alias: str | AliasPath | AliasChoices | None
604 validation_alias: Union[str, None] = None,
605 serialization_alias: Union[str, None] = None,
606 title: Optional[str] = None,
607 description: Optional[str] = None,
608 gt: Optional[float] = None,
609 ge: Optional[float] = None,
610 lt: Optional[float] = None,
611 le: Optional[float] = None,
612 min_length: Optional[int] = None,
613 max_length: Optional[int] = None,
614 pattern: Optional[str] = None,
615 regex: Annotated[
616 Optional[str],
617 deprecated(
618 "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
619 ),
620 ] = None,
621 discriminator: Union[str, None] = None,
622 strict: Union[bool, None] = _Unset,
623 multiple_of: Union[float, None] = _Unset,
624 allow_inf_nan: Union[bool, None] = _Unset,
625 max_digits: Union[int, None] = _Unset,
626 decimal_places: Union[int, None] = _Unset,
627 examples: Optional[List[Any]] = None,
628 example: Annotated[
629 Optional[Any],
630 deprecated(
631 "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
632 "although still supported. Use examples instead."
633 ),
634 ] = _Unset,
635 openapi_examples: Optional[Dict[str, Example]] = None,
636 deprecated: Union[deprecated, str, bool, None] = None,
637 include_in_schema: bool = True,
638 json_schema_extra: Union[Dict[str, Any], None] = None,
639 **extra: Any,
640 ):
641 super().__init__( 1deabc
642 default=default,
643 default_factory=default_factory,
644 annotation=annotation,
645 embed=True,
646 media_type=media_type,
647 alias=alias,
648 alias_priority=alias_priority,
649 validation_alias=validation_alias,
650 serialization_alias=serialization_alias,
651 title=title,
652 description=description,
653 gt=gt,
654 ge=ge,
655 lt=lt,
656 le=le,
657 min_length=min_length,
658 max_length=max_length,
659 pattern=pattern,
660 regex=regex,
661 discriminator=discriminator,
662 strict=strict,
663 multiple_of=multiple_of,
664 allow_inf_nan=allow_inf_nan,
665 max_digits=max_digits,
666 decimal_places=decimal_places,
667 deprecated=deprecated,
668 example=example,
669 examples=examples,
670 openapi_examples=openapi_examples,
671 include_in_schema=include_in_schema,
672 json_schema_extra=json_schema_extra,
673 **extra,
674 )
677class File(Form): 1deabc
678 def __init__( 1deabc
679 self,
680 default: Any = Undefined,
681 *,
682 default_factory: Union[Callable[[], Any], None] = _Unset,
683 annotation: Optional[Any] = None,
684 media_type: str = "multipart/form-data",
685 alias: Optional[str] = None,
686 alias_priority: Union[int, None] = _Unset,
687 # TODO: update when deprecating Pydantic v1, import these types
688 # validation_alias: str | AliasPath | AliasChoices | None
689 validation_alias: Union[str, None] = None,
690 serialization_alias: Union[str, None] = None,
691 title: Optional[str] = None,
692 description: Optional[str] = None,
693 gt: Optional[float] = None,
694 ge: Optional[float] = None,
695 lt: Optional[float] = None,
696 le: Optional[float] = None,
697 min_length: Optional[int] = None,
698 max_length: Optional[int] = None,
699 pattern: Optional[str] = None,
700 regex: Annotated[
701 Optional[str],
702 deprecated(
703 "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
704 ),
705 ] = None,
706 discriminator: Union[str, None] = None,
707 strict: Union[bool, None] = _Unset,
708 multiple_of: Union[float, None] = _Unset,
709 allow_inf_nan: Union[bool, None] = _Unset,
710 max_digits: Union[int, None] = _Unset,
711 decimal_places: Union[int, None] = _Unset,
712 examples: Optional[List[Any]] = None,
713 example: Annotated[
714 Optional[Any],
715 deprecated(
716 "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
717 "although still supported. Use examples instead."
718 ),
719 ] = _Unset,
720 openapi_examples: Optional[Dict[str, Example]] = None,
721 deprecated: Union[deprecated, str, bool, None] = None,
722 include_in_schema: bool = True,
723 json_schema_extra: Union[Dict[str, Any], None] = None,
724 **extra: Any,
725 ):
726 super().__init__( 1deabc
727 default=default,
728 default_factory=default_factory,
729 annotation=annotation,
730 media_type=media_type,
731 alias=alias,
732 alias_priority=alias_priority,
733 validation_alias=validation_alias,
734 serialization_alias=serialization_alias,
735 title=title,
736 description=description,
737 gt=gt,
738 ge=ge,
739 lt=lt,
740 le=le,
741 min_length=min_length,
742 max_length=max_length,
743 pattern=pattern,
744 regex=regex,
745 discriminator=discriminator,
746 strict=strict,
747 multiple_of=multiple_of,
748 allow_inf_nan=allow_inf_nan,
749 max_digits=max_digits,
750 decimal_places=decimal_places,
751 deprecated=deprecated,
752 example=example,
753 examples=examples,
754 openapi_examples=openapi_examples,
755 include_in_schema=include_in_schema,
756 json_schema_extra=json_schema_extra,
757 **extra,
758 )
761class Depends: 1deabc
762 def __init__( 1deabc
763 self, dependency: Optional[Callable[..., Any]] = None, *, use_cache: bool = True
764 ):
765 self.dependency = dependency 1deabc
766 self.use_cache = use_cache 1deabc
768 def __repr__(self) -> str: 1deabc
769 attr = getattr(self.dependency, "__name__", type(self.dependency).__name__) 1deabc
770 cache = "" if self.use_cache else ", use_cache=False" 1deabc
771 return f"{self.__class__.__name__}({attr}{cache})" 1deabc
774class Security(Depends): 1deabc
775 def __init__( 1deabc
776 self,
777 dependency: Optional[Callable[..., Any]] = None,
778 *,
779 scopes: Optional[Sequence[str]] = None,
780 use_cache: bool = True,
781 ):
782 super().__init__(dependency=dependency, use_cache=use_cache) 1deabc
783 self.scopes = scopes or [] 1deabc