Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

2361 lignes
62 KiB

  1. from typing import Any, Callable, Dict, List, Optional, Sequence, Union
  2. from fastapi import params
  3. from fastapi._compat import Undefined
  4. from fastapi.openapi.models import Example
  5. from typing_extensions import Annotated, Doc, deprecated
  6. _Unset: Any = Undefined
  7. def Path( # noqa: N802
  8. default: Annotated[
  9. Any,
  10. Doc(
  11. """
  12. Default value if the parameter field is not set.
  13. This doesn't affect `Path` parameters as the value is always required.
  14. The parameter is available only for compatibility.
  15. """
  16. ),
  17. ] = ...,
  18. *,
  19. default_factory: Annotated[
  20. Union[Callable[[], Any], None],
  21. Doc(
  22. """
  23. A callable to generate the default value.
  24. This doesn't affect `Path` parameters as the value is always required.
  25. The parameter is available only for compatibility.
  26. """
  27. ),
  28. ] = _Unset,
  29. alias: Annotated[
  30. Optional[str],
  31. Doc(
  32. """
  33. An alternative name for the parameter field.
  34. This will be used to extract the data and for the generated OpenAPI.
  35. It is particularly useful when you can't use the name you want because it
  36. is a Python reserved keyword or similar.
  37. """
  38. ),
  39. ] = None,
  40. alias_priority: Annotated[
  41. Union[int, None],
  42. Doc(
  43. """
  44. Priority of the alias. This affects whether an alias generator is used.
  45. """
  46. ),
  47. ] = _Unset,
  48. # TODO: update when deprecating Pydantic v1, import these types
  49. # validation_alias: str | AliasPath | AliasChoices | None
  50. validation_alias: Annotated[
  51. Union[str, None],
  52. Doc(
  53. """
  54. 'Whitelist' validation step. The parameter field will be the single one
  55. allowed by the alias or set of aliases defined.
  56. """
  57. ),
  58. ] = None,
  59. serialization_alias: Annotated[
  60. Union[str, None],
  61. Doc(
  62. """
  63. 'Blacklist' validation step. The vanilla parameter field will be the
  64. single one of the alias' or set of aliases' fields and all the other
  65. fields will be ignored at serialization time.
  66. """
  67. ),
  68. ] = None,
  69. title: Annotated[
  70. Optional[str],
  71. Doc(
  72. """
  73. Human-readable title.
  74. """
  75. ),
  76. ] = None,
  77. description: Annotated[
  78. Optional[str],
  79. Doc(
  80. """
  81. Human-readable description.
  82. """
  83. ),
  84. ] = None,
  85. gt: Annotated[
  86. Optional[float],
  87. Doc(
  88. """
  89. Greater than. If set, value must be greater than this. Only applicable to
  90. numbers.
  91. """
  92. ),
  93. ] = None,
  94. ge: Annotated[
  95. Optional[float],
  96. Doc(
  97. """
  98. Greater than or equal. If set, value must be greater than or equal to
  99. this. Only applicable to numbers.
  100. """
  101. ),
  102. ] = None,
  103. lt: Annotated[
  104. Optional[float],
  105. Doc(
  106. """
  107. Less than. If set, value must be less than this. Only applicable to numbers.
  108. """
  109. ),
  110. ] = None,
  111. le: Annotated[
  112. Optional[float],
  113. Doc(
  114. """
  115. Less than or equal. If set, value must be less than or equal to this.
  116. Only applicable to numbers.
  117. """
  118. ),
  119. ] = None,
  120. min_length: Annotated[
  121. Optional[int],
  122. Doc(
  123. """
  124. Minimum length for strings.
  125. """
  126. ),
  127. ] = None,
  128. max_length: Annotated[
  129. Optional[int],
  130. Doc(
  131. """
  132. Maximum length for strings.
  133. """
  134. ),
  135. ] = None,
  136. pattern: Annotated[
  137. Optional[str],
  138. Doc(
  139. """
  140. RegEx pattern for strings.
  141. """
  142. ),
  143. ] = None,
  144. regex: Annotated[
  145. Optional[str],
  146. Doc(
  147. """
  148. RegEx pattern for strings.
  149. """
  150. ),
  151. deprecated(
  152. "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
  153. ),
  154. ] = None,
  155. discriminator: Annotated[
  156. Union[str, None],
  157. Doc(
  158. """
  159. Parameter field name for discriminating the type in a tagged union.
  160. """
  161. ),
  162. ] = None,
  163. strict: Annotated[
  164. Union[bool, None],
  165. Doc(
  166. """
  167. If `True`, strict validation is applied to the field.
  168. """
  169. ),
  170. ] = _Unset,
  171. multiple_of: Annotated[
  172. Union[float, None],
  173. Doc(
  174. """
  175. Value must be a multiple of this. Only applicable to numbers.
  176. """
  177. ),
  178. ] = _Unset,
  179. allow_inf_nan: Annotated[
  180. Union[bool, None],
  181. Doc(
  182. """
  183. Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
  184. """
  185. ),
  186. ] = _Unset,
  187. max_digits: Annotated[
  188. Union[int, None],
  189. Doc(
  190. """
  191. Maximum number of allow digits for strings.
  192. """
  193. ),
  194. ] = _Unset,
  195. decimal_places: Annotated[
  196. Union[int, None],
  197. Doc(
  198. """
  199. Maximum number of decimal places allowed for numbers.
  200. """
  201. ),
  202. ] = _Unset,
  203. examples: Annotated[
  204. Optional[List[Any]],
  205. Doc(
  206. """
  207. Example values for this field.
  208. """
  209. ),
  210. ] = None,
  211. example: Annotated[
  212. Optional[Any],
  213. deprecated(
  214. "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
  215. "although still supported. Use examples instead."
  216. ),
  217. ] = _Unset,
  218. openapi_examples: Annotated[
  219. Optional[Dict[str, Example]],
  220. Doc(
  221. """
  222. OpenAPI-specific examples.
  223. It will be added to the generated OpenAPI (e.g. visible at `/docs`).
  224. Swagger UI (that provides the `/docs` interface) has better support for the
  225. OpenAPI-specific examples than the JSON Schema `examples`, that's the main
  226. use case for this.
  227. Read more about it in the
  228. [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
  229. """
  230. ),
  231. ] = None,
  232. deprecated: Annotated[
  233. Union[deprecated, str, bool, None],
  234. Doc(
  235. """
  236. Mark this parameter field as deprecated.
  237. It will affect the generated OpenAPI (e.g. visible at `/docs`).
  238. """
  239. ),
  240. ] = None,
  241. include_in_schema: Annotated[
  242. bool,
  243. Doc(
  244. """
  245. To include (or not) this parameter field in the generated OpenAPI.
  246. You probably don't need it, but it's available.
  247. This affects the generated OpenAPI (e.g. visible at `/docs`).
  248. """
  249. ),
  250. ] = True,
  251. json_schema_extra: Annotated[
  252. Union[Dict[str, Any], None],
  253. Doc(
  254. """
  255. Any additional JSON schema data.
  256. """
  257. ),
  258. ] = None,
  259. **extra: Annotated[
  260. Any,
  261. Doc(
  262. """
  263. Include extra fields used by the JSON Schema.
  264. """
  265. ),
  266. deprecated(
  267. """
  268. The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
  269. """
  270. ),
  271. ],
  272. ) -> Any:
  273. """
  274. Declare a path parameter for a *path operation*.
  275. Read more about it in the
  276. [FastAPI docs for Path Parameters and Numeric Validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/).
  277. ```python
  278. from typing import Annotated
  279. from fastapi import FastAPI, Path
  280. app = FastAPI()
  281. @app.get("/items/{item_id}")
  282. async def read_items(
  283. item_id: Annotated[int, Path(title="The ID of the item to get")],
  284. ):
  285. return {"item_id": item_id}
  286. ```
  287. """
  288. return params.Path(
  289. default=default,
  290. default_factory=default_factory,
  291. alias=alias,
  292. alias_priority=alias_priority,
  293. validation_alias=validation_alias,
  294. serialization_alias=serialization_alias,
  295. title=title,
  296. description=description,
  297. gt=gt,
  298. ge=ge,
  299. lt=lt,
  300. le=le,
  301. min_length=min_length,
  302. max_length=max_length,
  303. pattern=pattern,
  304. regex=regex,
  305. discriminator=discriminator,
  306. strict=strict,
  307. multiple_of=multiple_of,
  308. allow_inf_nan=allow_inf_nan,
  309. max_digits=max_digits,
  310. decimal_places=decimal_places,
  311. example=example,
  312. examples=examples,
  313. openapi_examples=openapi_examples,
  314. deprecated=deprecated,
  315. include_in_schema=include_in_schema,
  316. json_schema_extra=json_schema_extra,
  317. **extra,
  318. )
  319. def Query( # noqa: N802
  320. default: Annotated[
  321. Any,
  322. Doc(
  323. """
  324. Default value if the parameter field is not set.
  325. """
  326. ),
  327. ] = Undefined,
  328. *,
  329. default_factory: Annotated[
  330. Union[Callable[[], Any], None],
  331. Doc(
  332. """
  333. A callable to generate the default value.
  334. This doesn't affect `Path` parameters as the value is always required.
  335. The parameter is available only for compatibility.
  336. """
  337. ),
  338. ] = _Unset,
  339. alias: Annotated[
  340. Optional[str],
  341. Doc(
  342. """
  343. An alternative name for the parameter field.
  344. This will be used to extract the data and for the generated OpenAPI.
  345. It is particularly useful when you can't use the name you want because it
  346. is a Python reserved keyword or similar.
  347. """
  348. ),
  349. ] = None,
  350. alias_priority: Annotated[
  351. Union[int, None],
  352. Doc(
  353. """
  354. Priority of the alias. This affects whether an alias generator is used.
  355. """
  356. ),
  357. ] = _Unset,
  358. # TODO: update when deprecating Pydantic v1, import these types
  359. # validation_alias: str | AliasPath | AliasChoices | None
  360. validation_alias: Annotated[
  361. Union[str, None],
  362. Doc(
  363. """
  364. 'Whitelist' validation step. The parameter field will be the single one
  365. allowed by the alias or set of aliases defined.
  366. """
  367. ),
  368. ] = None,
  369. serialization_alias: Annotated[
  370. Union[str, None],
  371. Doc(
  372. """
  373. 'Blacklist' validation step. The vanilla parameter field will be the
  374. single one of the alias' or set of aliases' fields and all the other
  375. fields will be ignored at serialization time.
  376. """
  377. ),
  378. ] = None,
  379. title: Annotated[
  380. Optional[str],
  381. Doc(
  382. """
  383. Human-readable title.
  384. """
  385. ),
  386. ] = None,
  387. description: Annotated[
  388. Optional[str],
  389. Doc(
  390. """
  391. Human-readable description.
  392. """
  393. ),
  394. ] = None,
  395. gt: Annotated[
  396. Optional[float],
  397. Doc(
  398. """
  399. Greater than. If set, value must be greater than this. Only applicable to
  400. numbers.
  401. """
  402. ),
  403. ] = None,
  404. ge: Annotated[
  405. Optional[float],
  406. Doc(
  407. """
  408. Greater than or equal. If set, value must be greater than or equal to
  409. this. Only applicable to numbers.
  410. """
  411. ),
  412. ] = None,
  413. lt: Annotated[
  414. Optional[float],
  415. Doc(
  416. """
  417. Less than. If set, value must be less than this. Only applicable to numbers.
  418. """
  419. ),
  420. ] = None,
  421. le: Annotated[
  422. Optional[float],
  423. Doc(
  424. """
  425. Less than or equal. If set, value must be less than or equal to this.
  426. Only applicable to numbers.
  427. """
  428. ),
  429. ] = None,
  430. min_length: Annotated[
  431. Optional[int],
  432. Doc(
  433. """
  434. Minimum length for strings.
  435. """
  436. ),
  437. ] = None,
  438. max_length: Annotated[
  439. Optional[int],
  440. Doc(
  441. """
  442. Maximum length for strings.
  443. """
  444. ),
  445. ] = None,
  446. pattern: Annotated[
  447. Optional[str],
  448. Doc(
  449. """
  450. RegEx pattern for strings.
  451. """
  452. ),
  453. ] = None,
  454. regex: Annotated[
  455. Optional[str],
  456. Doc(
  457. """
  458. RegEx pattern for strings.
  459. """
  460. ),
  461. deprecated(
  462. "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
  463. ),
  464. ] = None,
  465. discriminator: Annotated[
  466. Union[str, None],
  467. Doc(
  468. """
  469. Parameter field name for discriminating the type in a tagged union.
  470. """
  471. ),
  472. ] = None,
  473. strict: Annotated[
  474. Union[bool, None],
  475. Doc(
  476. """
  477. If `True`, strict validation is applied to the field.
  478. """
  479. ),
  480. ] = _Unset,
  481. multiple_of: Annotated[
  482. Union[float, None],
  483. Doc(
  484. """
  485. Value must be a multiple of this. Only applicable to numbers.
  486. """
  487. ),
  488. ] = _Unset,
  489. allow_inf_nan: Annotated[
  490. Union[bool, None],
  491. Doc(
  492. """
  493. Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
  494. """
  495. ),
  496. ] = _Unset,
  497. max_digits: Annotated[
  498. Union[int, None],
  499. Doc(
  500. """
  501. Maximum number of allow digits for strings.
  502. """
  503. ),
  504. ] = _Unset,
  505. decimal_places: Annotated[
  506. Union[int, None],
  507. Doc(
  508. """
  509. Maximum number of decimal places allowed for numbers.
  510. """
  511. ),
  512. ] = _Unset,
  513. examples: Annotated[
  514. Optional[List[Any]],
  515. Doc(
  516. """
  517. Example values for this field.
  518. """
  519. ),
  520. ] = None,
  521. example: Annotated[
  522. Optional[Any],
  523. deprecated(
  524. "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
  525. "although still supported. Use examples instead."
  526. ),
  527. ] = _Unset,
  528. openapi_examples: Annotated[
  529. Optional[Dict[str, Example]],
  530. Doc(
  531. """
  532. OpenAPI-specific examples.
  533. It will be added to the generated OpenAPI (e.g. visible at `/docs`).
  534. Swagger UI (that provides the `/docs` interface) has better support for the
  535. OpenAPI-specific examples than the JSON Schema `examples`, that's the main
  536. use case for this.
  537. Read more about it in the
  538. [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
  539. """
  540. ),
  541. ] = None,
  542. deprecated: Annotated[
  543. Union[deprecated, str, bool, None],
  544. Doc(
  545. """
  546. Mark this parameter field as deprecated.
  547. It will affect the generated OpenAPI (e.g. visible at `/docs`).
  548. """
  549. ),
  550. ] = None,
  551. include_in_schema: Annotated[
  552. bool,
  553. Doc(
  554. """
  555. To include (or not) this parameter field in the generated OpenAPI.
  556. You probably don't need it, but it's available.
  557. This affects the generated OpenAPI (e.g. visible at `/docs`).
  558. """
  559. ),
  560. ] = True,
  561. json_schema_extra: Annotated[
  562. Union[Dict[str, Any], None],
  563. Doc(
  564. """
  565. Any additional JSON schema data.
  566. """
  567. ),
  568. ] = None,
  569. **extra: Annotated[
  570. Any,
  571. Doc(
  572. """
  573. Include extra fields used by the JSON Schema.
  574. """
  575. ),
  576. deprecated(
  577. """
  578. The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
  579. """
  580. ),
  581. ],
  582. ) -> Any:
  583. return params.Query(
  584. default=default,
  585. default_factory=default_factory,
  586. alias=alias,
  587. alias_priority=alias_priority,
  588. validation_alias=validation_alias,
  589. serialization_alias=serialization_alias,
  590. title=title,
  591. description=description,
  592. gt=gt,
  593. ge=ge,
  594. lt=lt,
  595. le=le,
  596. min_length=min_length,
  597. max_length=max_length,
  598. pattern=pattern,
  599. regex=regex,
  600. discriminator=discriminator,
  601. strict=strict,
  602. multiple_of=multiple_of,
  603. allow_inf_nan=allow_inf_nan,
  604. max_digits=max_digits,
  605. decimal_places=decimal_places,
  606. example=example,
  607. examples=examples,
  608. openapi_examples=openapi_examples,
  609. deprecated=deprecated,
  610. include_in_schema=include_in_schema,
  611. json_schema_extra=json_schema_extra,
  612. **extra,
  613. )
  614. def Header( # noqa: N802
  615. default: Annotated[
  616. Any,
  617. Doc(
  618. """
  619. Default value if the parameter field is not set.
  620. """
  621. ),
  622. ] = Undefined,
  623. *,
  624. default_factory: Annotated[
  625. Union[Callable[[], Any], None],
  626. Doc(
  627. """
  628. A callable to generate the default value.
  629. This doesn't affect `Path` parameters as the value is always required.
  630. The parameter is available only for compatibility.
  631. """
  632. ),
  633. ] = _Unset,
  634. alias: Annotated[
  635. Optional[str],
  636. Doc(
  637. """
  638. An alternative name for the parameter field.
  639. This will be used to extract the data and for the generated OpenAPI.
  640. It is particularly useful when you can't use the name you want because it
  641. is a Python reserved keyword or similar.
  642. """
  643. ),
  644. ] = None,
  645. alias_priority: Annotated[
  646. Union[int, None],
  647. Doc(
  648. """
  649. Priority of the alias. This affects whether an alias generator is used.
  650. """
  651. ),
  652. ] = _Unset,
  653. # TODO: update when deprecating Pydantic v1, import these types
  654. # validation_alias: str | AliasPath | AliasChoices | None
  655. validation_alias: Annotated[
  656. Union[str, None],
  657. Doc(
  658. """
  659. 'Whitelist' validation step. The parameter field will be the single one
  660. allowed by the alias or set of aliases defined.
  661. """
  662. ),
  663. ] = None,
  664. serialization_alias: Annotated[
  665. Union[str, None],
  666. Doc(
  667. """
  668. 'Blacklist' validation step. The vanilla parameter field will be the
  669. single one of the alias' or set of aliases' fields and all the other
  670. fields will be ignored at serialization time.
  671. """
  672. ),
  673. ] = None,
  674. convert_underscores: Annotated[
  675. bool,
  676. Doc(
  677. """
  678. Automatically convert underscores to hyphens in the parameter field name.
  679. Read more about it in the
  680. [FastAPI docs for Header Parameters](https://fastapi.tiangolo.com/tutorial/header-params/#automatic-conversion)
  681. """
  682. ),
  683. ] = True,
  684. title: Annotated[
  685. Optional[str],
  686. Doc(
  687. """
  688. Human-readable title.
  689. """
  690. ),
  691. ] = None,
  692. description: Annotated[
  693. Optional[str],
  694. Doc(
  695. """
  696. Human-readable description.
  697. """
  698. ),
  699. ] = None,
  700. gt: Annotated[
  701. Optional[float],
  702. Doc(
  703. """
  704. Greater than. If set, value must be greater than this. Only applicable to
  705. numbers.
  706. """
  707. ),
  708. ] = None,
  709. ge: Annotated[
  710. Optional[float],
  711. Doc(
  712. """
  713. Greater than or equal. If set, value must be greater than or equal to
  714. this. Only applicable to numbers.
  715. """
  716. ),
  717. ] = None,
  718. lt: Annotated[
  719. Optional[float],
  720. Doc(
  721. """
  722. Less than. If set, value must be less than this. Only applicable to numbers.
  723. """
  724. ),
  725. ] = None,
  726. le: Annotated[
  727. Optional[float],
  728. Doc(
  729. """
  730. Less than or equal. If set, value must be less than or equal to this.
  731. Only applicable to numbers.
  732. """
  733. ),
  734. ] = None,
  735. min_length: Annotated[
  736. Optional[int],
  737. Doc(
  738. """
  739. Minimum length for strings.
  740. """
  741. ),
  742. ] = None,
  743. max_length: Annotated[
  744. Optional[int],
  745. Doc(
  746. """
  747. Maximum length for strings.
  748. """
  749. ),
  750. ] = None,
  751. pattern: Annotated[
  752. Optional[str],
  753. Doc(
  754. """
  755. RegEx pattern for strings.
  756. """
  757. ),
  758. ] = None,
  759. regex: Annotated[
  760. Optional[str],
  761. Doc(
  762. """
  763. RegEx pattern for strings.
  764. """
  765. ),
  766. deprecated(
  767. "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
  768. ),
  769. ] = None,
  770. discriminator: Annotated[
  771. Union[str, None],
  772. Doc(
  773. """
  774. Parameter field name for discriminating the type in a tagged union.
  775. """
  776. ),
  777. ] = None,
  778. strict: Annotated[
  779. Union[bool, None],
  780. Doc(
  781. """
  782. If `True`, strict validation is applied to the field.
  783. """
  784. ),
  785. ] = _Unset,
  786. multiple_of: Annotated[
  787. Union[float, None],
  788. Doc(
  789. """
  790. Value must be a multiple of this. Only applicable to numbers.
  791. """
  792. ),
  793. ] = _Unset,
  794. allow_inf_nan: Annotated[
  795. Union[bool, None],
  796. Doc(
  797. """
  798. Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
  799. """
  800. ),
  801. ] = _Unset,
  802. max_digits: Annotated[
  803. Union[int, None],
  804. Doc(
  805. """
  806. Maximum number of allow digits for strings.
  807. """
  808. ),
  809. ] = _Unset,
  810. decimal_places: Annotated[
  811. Union[int, None],
  812. Doc(
  813. """
  814. Maximum number of decimal places allowed for numbers.
  815. """
  816. ),
  817. ] = _Unset,
  818. examples: Annotated[
  819. Optional[List[Any]],
  820. Doc(
  821. """
  822. Example values for this field.
  823. """
  824. ),
  825. ] = None,
  826. example: Annotated[
  827. Optional[Any],
  828. deprecated(
  829. "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
  830. "although still supported. Use examples instead."
  831. ),
  832. ] = _Unset,
  833. openapi_examples: Annotated[
  834. Optional[Dict[str, Example]],
  835. Doc(
  836. """
  837. OpenAPI-specific examples.
  838. It will be added to the generated OpenAPI (e.g. visible at `/docs`).
  839. Swagger UI (that provides the `/docs` interface) has better support for the
  840. OpenAPI-specific examples than the JSON Schema `examples`, that's the main
  841. use case for this.
  842. Read more about it in the
  843. [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
  844. """
  845. ),
  846. ] = None,
  847. deprecated: Annotated[
  848. Union[deprecated, str, bool, None],
  849. Doc(
  850. """
  851. Mark this parameter field as deprecated.
  852. It will affect the generated OpenAPI (e.g. visible at `/docs`).
  853. """
  854. ),
  855. ] = None,
  856. include_in_schema: Annotated[
  857. bool,
  858. Doc(
  859. """
  860. To include (or not) this parameter field in the generated OpenAPI.
  861. You probably don't need it, but it's available.
  862. This affects the generated OpenAPI (e.g. visible at `/docs`).
  863. """
  864. ),
  865. ] = True,
  866. json_schema_extra: Annotated[
  867. Union[Dict[str, Any], None],
  868. Doc(
  869. """
  870. Any additional JSON schema data.
  871. """
  872. ),
  873. ] = None,
  874. **extra: Annotated[
  875. Any,
  876. Doc(
  877. """
  878. Include extra fields used by the JSON Schema.
  879. """
  880. ),
  881. deprecated(
  882. """
  883. The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
  884. """
  885. ),
  886. ],
  887. ) -> Any:
  888. return params.Header(
  889. default=default,
  890. default_factory=default_factory,
  891. alias=alias,
  892. alias_priority=alias_priority,
  893. validation_alias=validation_alias,
  894. serialization_alias=serialization_alias,
  895. convert_underscores=convert_underscores,
  896. title=title,
  897. description=description,
  898. gt=gt,
  899. ge=ge,
  900. lt=lt,
  901. le=le,
  902. min_length=min_length,
  903. max_length=max_length,
  904. pattern=pattern,
  905. regex=regex,
  906. discriminator=discriminator,
  907. strict=strict,
  908. multiple_of=multiple_of,
  909. allow_inf_nan=allow_inf_nan,
  910. max_digits=max_digits,
  911. decimal_places=decimal_places,
  912. example=example,
  913. examples=examples,
  914. openapi_examples=openapi_examples,
  915. deprecated=deprecated,
  916. include_in_schema=include_in_schema,
  917. json_schema_extra=json_schema_extra,
  918. **extra,
  919. )
  920. def Cookie( # noqa: N802
  921. default: Annotated[
  922. Any,
  923. Doc(
  924. """
  925. Default value if the parameter field is not set.
  926. """
  927. ),
  928. ] = Undefined,
  929. *,
  930. default_factory: Annotated[
  931. Union[Callable[[], Any], None],
  932. Doc(
  933. """
  934. A callable to generate the default value.
  935. This doesn't affect `Path` parameters as the value is always required.
  936. The parameter is available only for compatibility.
  937. """
  938. ),
  939. ] = _Unset,
  940. alias: Annotated[
  941. Optional[str],
  942. Doc(
  943. """
  944. An alternative name for the parameter field.
  945. This will be used to extract the data and for the generated OpenAPI.
  946. It is particularly useful when you can't use the name you want because it
  947. is a Python reserved keyword or similar.
  948. """
  949. ),
  950. ] = None,
  951. alias_priority: Annotated[
  952. Union[int, None],
  953. Doc(
  954. """
  955. Priority of the alias. This affects whether an alias generator is used.
  956. """
  957. ),
  958. ] = _Unset,
  959. # TODO: update when deprecating Pydantic v1, import these types
  960. # validation_alias: str | AliasPath | AliasChoices | None
  961. validation_alias: Annotated[
  962. Union[str, None],
  963. Doc(
  964. """
  965. 'Whitelist' validation step. The parameter field will be the single one
  966. allowed by the alias or set of aliases defined.
  967. """
  968. ),
  969. ] = None,
  970. serialization_alias: Annotated[
  971. Union[str, None],
  972. Doc(
  973. """
  974. 'Blacklist' validation step. The vanilla parameter field will be the
  975. single one of the alias' or set of aliases' fields and all the other
  976. fields will be ignored at serialization time.
  977. """
  978. ),
  979. ] = None,
  980. title: Annotated[
  981. Optional[str],
  982. Doc(
  983. """
  984. Human-readable title.
  985. """
  986. ),
  987. ] = None,
  988. description: Annotated[
  989. Optional[str],
  990. Doc(
  991. """
  992. Human-readable description.
  993. """
  994. ),
  995. ] = None,
  996. gt: Annotated[
  997. Optional[float],
  998. Doc(
  999. """
  1000. Greater than. If set, value must be greater than this. Only applicable to
  1001. numbers.
  1002. """
  1003. ),
  1004. ] = None,
  1005. ge: Annotated[
  1006. Optional[float],
  1007. Doc(
  1008. """
  1009. Greater than or equal. If set, value must be greater than or equal to
  1010. this. Only applicable to numbers.
  1011. """
  1012. ),
  1013. ] = None,
  1014. lt: Annotated[
  1015. Optional[float],
  1016. Doc(
  1017. """
  1018. Less than. If set, value must be less than this. Only applicable to numbers.
  1019. """
  1020. ),
  1021. ] = None,
  1022. le: Annotated[
  1023. Optional[float],
  1024. Doc(
  1025. """
  1026. Less than or equal. If set, value must be less than or equal to this.
  1027. Only applicable to numbers.
  1028. """
  1029. ),
  1030. ] = None,
  1031. min_length: Annotated[
  1032. Optional[int],
  1033. Doc(
  1034. """
  1035. Minimum length for strings.
  1036. """
  1037. ),
  1038. ] = None,
  1039. max_length: Annotated[
  1040. Optional[int],
  1041. Doc(
  1042. """
  1043. Maximum length for strings.
  1044. """
  1045. ),
  1046. ] = None,
  1047. pattern: Annotated[
  1048. Optional[str],
  1049. Doc(
  1050. """
  1051. RegEx pattern for strings.
  1052. """
  1053. ),
  1054. ] = None,
  1055. regex: Annotated[
  1056. Optional[str],
  1057. Doc(
  1058. """
  1059. RegEx pattern for strings.
  1060. """
  1061. ),
  1062. deprecated(
  1063. "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
  1064. ),
  1065. ] = None,
  1066. discriminator: Annotated[
  1067. Union[str, None],
  1068. Doc(
  1069. """
  1070. Parameter field name for discriminating the type in a tagged union.
  1071. """
  1072. ),
  1073. ] = None,
  1074. strict: Annotated[
  1075. Union[bool, None],
  1076. Doc(
  1077. """
  1078. If `True`, strict validation is applied to the field.
  1079. """
  1080. ),
  1081. ] = _Unset,
  1082. multiple_of: Annotated[
  1083. Union[float, None],
  1084. Doc(
  1085. """
  1086. Value must be a multiple of this. Only applicable to numbers.
  1087. """
  1088. ),
  1089. ] = _Unset,
  1090. allow_inf_nan: Annotated[
  1091. Union[bool, None],
  1092. Doc(
  1093. """
  1094. Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
  1095. """
  1096. ),
  1097. ] = _Unset,
  1098. max_digits: Annotated[
  1099. Union[int, None],
  1100. Doc(
  1101. """
  1102. Maximum number of allow digits for strings.
  1103. """
  1104. ),
  1105. ] = _Unset,
  1106. decimal_places: Annotated[
  1107. Union[int, None],
  1108. Doc(
  1109. """
  1110. Maximum number of decimal places allowed for numbers.
  1111. """
  1112. ),
  1113. ] = _Unset,
  1114. examples: Annotated[
  1115. Optional[List[Any]],
  1116. Doc(
  1117. """
  1118. Example values for this field.
  1119. """
  1120. ),
  1121. ] = None,
  1122. example: Annotated[
  1123. Optional[Any],
  1124. deprecated(
  1125. "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
  1126. "although still supported. Use examples instead."
  1127. ),
  1128. ] = _Unset,
  1129. openapi_examples: Annotated[
  1130. Optional[Dict[str, Example]],
  1131. Doc(
  1132. """
  1133. OpenAPI-specific examples.
  1134. It will be added to the generated OpenAPI (e.g. visible at `/docs`).
  1135. Swagger UI (that provides the `/docs` interface) has better support for the
  1136. OpenAPI-specific examples than the JSON Schema `examples`, that's the main
  1137. use case for this.
  1138. Read more about it in the
  1139. [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
  1140. """
  1141. ),
  1142. ] = None,
  1143. deprecated: Annotated[
  1144. Union[deprecated, str, bool, None],
  1145. Doc(
  1146. """
  1147. Mark this parameter field as deprecated.
  1148. It will affect the generated OpenAPI (e.g. visible at `/docs`).
  1149. """
  1150. ),
  1151. ] = None,
  1152. include_in_schema: Annotated[
  1153. bool,
  1154. Doc(
  1155. """
  1156. To include (or not) this parameter field in the generated OpenAPI.
  1157. You probably don't need it, but it's available.
  1158. This affects the generated OpenAPI (e.g. visible at `/docs`).
  1159. """
  1160. ),
  1161. ] = True,
  1162. json_schema_extra: Annotated[
  1163. Union[Dict[str, Any], None],
  1164. Doc(
  1165. """
  1166. Any additional JSON schema data.
  1167. """
  1168. ),
  1169. ] = None,
  1170. **extra: Annotated[
  1171. Any,
  1172. Doc(
  1173. """
  1174. Include extra fields used by the JSON Schema.
  1175. """
  1176. ),
  1177. deprecated(
  1178. """
  1179. The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
  1180. """
  1181. ),
  1182. ],
  1183. ) -> Any:
  1184. return params.Cookie(
  1185. default=default,
  1186. default_factory=default_factory,
  1187. alias=alias,
  1188. alias_priority=alias_priority,
  1189. validation_alias=validation_alias,
  1190. serialization_alias=serialization_alias,
  1191. title=title,
  1192. description=description,
  1193. gt=gt,
  1194. ge=ge,
  1195. lt=lt,
  1196. le=le,
  1197. min_length=min_length,
  1198. max_length=max_length,
  1199. pattern=pattern,
  1200. regex=regex,
  1201. discriminator=discriminator,
  1202. strict=strict,
  1203. multiple_of=multiple_of,
  1204. allow_inf_nan=allow_inf_nan,
  1205. max_digits=max_digits,
  1206. decimal_places=decimal_places,
  1207. example=example,
  1208. examples=examples,
  1209. openapi_examples=openapi_examples,
  1210. deprecated=deprecated,
  1211. include_in_schema=include_in_schema,
  1212. json_schema_extra=json_schema_extra,
  1213. **extra,
  1214. )
  1215. def Body( # noqa: N802
  1216. default: Annotated[
  1217. Any,
  1218. Doc(
  1219. """
  1220. Default value if the parameter field is not set.
  1221. """
  1222. ),
  1223. ] = Undefined,
  1224. *,
  1225. default_factory: Annotated[
  1226. Union[Callable[[], Any], None],
  1227. Doc(
  1228. """
  1229. A callable to generate the default value.
  1230. This doesn't affect `Path` parameters as the value is always required.
  1231. The parameter is available only for compatibility.
  1232. """
  1233. ),
  1234. ] = _Unset,
  1235. embed: Annotated[
  1236. Union[bool, None],
  1237. Doc(
  1238. """
  1239. When `embed` is `True`, the parameter will be expected in a JSON body as a
  1240. key instead of being the JSON body itself.
  1241. This happens automatically when more than one `Body` parameter is declared.
  1242. Read more about it in the
  1243. [FastAPI docs for Body - Multiple Parameters](https://fastapi.tiangolo.com/tutorial/body-multiple-params/#embed-a-single-body-parameter).
  1244. """
  1245. ),
  1246. ] = None,
  1247. media_type: Annotated[
  1248. str,
  1249. Doc(
  1250. """
  1251. The media type of this parameter field. Changing it would affect the
  1252. generated OpenAPI, but currently it doesn't affect the parsing of the data.
  1253. """
  1254. ),
  1255. ] = "application/json",
  1256. alias: Annotated[
  1257. Optional[str],
  1258. Doc(
  1259. """
  1260. An alternative name for the parameter field.
  1261. This will be used to extract the data and for the generated OpenAPI.
  1262. It is particularly useful when you can't use the name you want because it
  1263. is a Python reserved keyword or similar.
  1264. """
  1265. ),
  1266. ] = None,
  1267. alias_priority: Annotated[
  1268. Union[int, None],
  1269. Doc(
  1270. """
  1271. Priority of the alias. This affects whether an alias generator is used.
  1272. """
  1273. ),
  1274. ] = _Unset,
  1275. # TODO: update when deprecating Pydantic v1, import these types
  1276. # validation_alias: str | AliasPath | AliasChoices | None
  1277. validation_alias: Annotated[
  1278. Union[str, None],
  1279. Doc(
  1280. """
  1281. 'Whitelist' validation step. The parameter field will be the single one
  1282. allowed by the alias or set of aliases defined.
  1283. """
  1284. ),
  1285. ] = None,
  1286. serialization_alias: Annotated[
  1287. Union[str, None],
  1288. Doc(
  1289. """
  1290. 'Blacklist' validation step. The vanilla parameter field will be the
  1291. single one of the alias' or set of aliases' fields and all the other
  1292. fields will be ignored at serialization time.
  1293. """
  1294. ),
  1295. ] = None,
  1296. title: Annotated[
  1297. Optional[str],
  1298. Doc(
  1299. """
  1300. Human-readable title.
  1301. """
  1302. ),
  1303. ] = None,
  1304. description: Annotated[
  1305. Optional[str],
  1306. Doc(
  1307. """
  1308. Human-readable description.
  1309. """
  1310. ),
  1311. ] = None,
  1312. gt: Annotated[
  1313. Optional[float],
  1314. Doc(
  1315. """
  1316. Greater than. If set, value must be greater than this. Only applicable to
  1317. numbers.
  1318. """
  1319. ),
  1320. ] = None,
  1321. ge: Annotated[
  1322. Optional[float],
  1323. Doc(
  1324. """
  1325. Greater than or equal. If set, value must be greater than or equal to
  1326. this. Only applicable to numbers.
  1327. """
  1328. ),
  1329. ] = None,
  1330. lt: Annotated[
  1331. Optional[float],
  1332. Doc(
  1333. """
  1334. Less than. If set, value must be less than this. Only applicable to numbers.
  1335. """
  1336. ),
  1337. ] = None,
  1338. le: Annotated[
  1339. Optional[float],
  1340. Doc(
  1341. """
  1342. Less than or equal. If set, value must be less than or equal to this.
  1343. Only applicable to numbers.
  1344. """
  1345. ),
  1346. ] = None,
  1347. min_length: Annotated[
  1348. Optional[int],
  1349. Doc(
  1350. """
  1351. Minimum length for strings.
  1352. """
  1353. ),
  1354. ] = None,
  1355. max_length: Annotated[
  1356. Optional[int],
  1357. Doc(
  1358. """
  1359. Maximum length for strings.
  1360. """
  1361. ),
  1362. ] = None,
  1363. pattern: Annotated[
  1364. Optional[str],
  1365. Doc(
  1366. """
  1367. RegEx pattern for strings.
  1368. """
  1369. ),
  1370. ] = None,
  1371. regex: Annotated[
  1372. Optional[str],
  1373. Doc(
  1374. """
  1375. RegEx pattern for strings.
  1376. """
  1377. ),
  1378. deprecated(
  1379. "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
  1380. ),
  1381. ] = None,
  1382. discriminator: Annotated[
  1383. Union[str, None],
  1384. Doc(
  1385. """
  1386. Parameter field name for discriminating the type in a tagged union.
  1387. """
  1388. ),
  1389. ] = None,
  1390. strict: Annotated[
  1391. Union[bool, None],
  1392. Doc(
  1393. """
  1394. If `True`, strict validation is applied to the field.
  1395. """
  1396. ),
  1397. ] = _Unset,
  1398. multiple_of: Annotated[
  1399. Union[float, None],
  1400. Doc(
  1401. """
  1402. Value must be a multiple of this. Only applicable to numbers.
  1403. """
  1404. ),
  1405. ] = _Unset,
  1406. allow_inf_nan: Annotated[
  1407. Union[bool, None],
  1408. Doc(
  1409. """
  1410. Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
  1411. """
  1412. ),
  1413. ] = _Unset,
  1414. max_digits: Annotated[
  1415. Union[int, None],
  1416. Doc(
  1417. """
  1418. Maximum number of allow digits for strings.
  1419. """
  1420. ),
  1421. ] = _Unset,
  1422. decimal_places: Annotated[
  1423. Union[int, None],
  1424. Doc(
  1425. """
  1426. Maximum number of decimal places allowed for numbers.
  1427. """
  1428. ),
  1429. ] = _Unset,
  1430. examples: Annotated[
  1431. Optional[List[Any]],
  1432. Doc(
  1433. """
  1434. Example values for this field.
  1435. """
  1436. ),
  1437. ] = None,
  1438. example: Annotated[
  1439. Optional[Any],
  1440. deprecated(
  1441. "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
  1442. "although still supported. Use examples instead."
  1443. ),
  1444. ] = _Unset,
  1445. openapi_examples: Annotated[
  1446. Optional[Dict[str, Example]],
  1447. Doc(
  1448. """
  1449. OpenAPI-specific examples.
  1450. It will be added to the generated OpenAPI (e.g. visible at `/docs`).
  1451. Swagger UI (that provides the `/docs` interface) has better support for the
  1452. OpenAPI-specific examples than the JSON Schema `examples`, that's the main
  1453. use case for this.
  1454. Read more about it in the
  1455. [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
  1456. """
  1457. ),
  1458. ] = None,
  1459. deprecated: Annotated[
  1460. Union[deprecated, str, bool, None],
  1461. Doc(
  1462. """
  1463. Mark this parameter field as deprecated.
  1464. It will affect the generated OpenAPI (e.g. visible at `/docs`).
  1465. """
  1466. ),
  1467. ] = None,
  1468. include_in_schema: Annotated[
  1469. bool,
  1470. Doc(
  1471. """
  1472. To include (or not) this parameter field in the generated OpenAPI.
  1473. You probably don't need it, but it's available.
  1474. This affects the generated OpenAPI (e.g. visible at `/docs`).
  1475. """
  1476. ),
  1477. ] = True,
  1478. json_schema_extra: Annotated[
  1479. Union[Dict[str, Any], None],
  1480. Doc(
  1481. """
  1482. Any additional JSON schema data.
  1483. """
  1484. ),
  1485. ] = None,
  1486. **extra: Annotated[
  1487. Any,
  1488. Doc(
  1489. """
  1490. Include extra fields used by the JSON Schema.
  1491. """
  1492. ),
  1493. deprecated(
  1494. """
  1495. The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
  1496. """
  1497. ),
  1498. ],
  1499. ) -> Any:
  1500. return params.Body(
  1501. default=default,
  1502. default_factory=default_factory,
  1503. embed=embed,
  1504. media_type=media_type,
  1505. alias=alias,
  1506. alias_priority=alias_priority,
  1507. validation_alias=validation_alias,
  1508. serialization_alias=serialization_alias,
  1509. title=title,
  1510. description=description,
  1511. gt=gt,
  1512. ge=ge,
  1513. lt=lt,
  1514. le=le,
  1515. min_length=min_length,
  1516. max_length=max_length,
  1517. pattern=pattern,
  1518. regex=regex,
  1519. discriminator=discriminator,
  1520. strict=strict,
  1521. multiple_of=multiple_of,
  1522. allow_inf_nan=allow_inf_nan,
  1523. max_digits=max_digits,
  1524. decimal_places=decimal_places,
  1525. example=example,
  1526. examples=examples,
  1527. openapi_examples=openapi_examples,
  1528. deprecated=deprecated,
  1529. include_in_schema=include_in_schema,
  1530. json_schema_extra=json_schema_extra,
  1531. **extra,
  1532. )
  1533. def Form( # noqa: N802
  1534. default: Annotated[
  1535. Any,
  1536. Doc(
  1537. """
  1538. Default value if the parameter field is not set.
  1539. """
  1540. ),
  1541. ] = Undefined,
  1542. *,
  1543. default_factory: Annotated[
  1544. Union[Callable[[], Any], None],
  1545. Doc(
  1546. """
  1547. A callable to generate the default value.
  1548. This doesn't affect `Path` parameters as the value is always required.
  1549. The parameter is available only for compatibility.
  1550. """
  1551. ),
  1552. ] = _Unset,
  1553. media_type: Annotated[
  1554. str,
  1555. Doc(
  1556. """
  1557. The media type of this parameter field. Changing it would affect the
  1558. generated OpenAPI, but currently it doesn't affect the parsing of the data.
  1559. """
  1560. ),
  1561. ] = "application/x-www-form-urlencoded",
  1562. alias: Annotated[
  1563. Optional[str],
  1564. Doc(
  1565. """
  1566. An alternative name for the parameter field.
  1567. This will be used to extract the data and for the generated OpenAPI.
  1568. It is particularly useful when you can't use the name you want because it
  1569. is a Python reserved keyword or similar.
  1570. """
  1571. ),
  1572. ] = None,
  1573. alias_priority: Annotated[
  1574. Union[int, None],
  1575. Doc(
  1576. """
  1577. Priority of the alias. This affects whether an alias generator is used.
  1578. """
  1579. ),
  1580. ] = _Unset,
  1581. # TODO: update when deprecating Pydantic v1, import these types
  1582. # validation_alias: str | AliasPath | AliasChoices | None
  1583. validation_alias: Annotated[
  1584. Union[str, None],
  1585. Doc(
  1586. """
  1587. 'Whitelist' validation step. The parameter field will be the single one
  1588. allowed by the alias or set of aliases defined.
  1589. """
  1590. ),
  1591. ] = None,
  1592. serialization_alias: Annotated[
  1593. Union[str, None],
  1594. Doc(
  1595. """
  1596. 'Blacklist' validation step. The vanilla parameter field will be the
  1597. single one of the alias' or set of aliases' fields and all the other
  1598. fields will be ignored at serialization time.
  1599. """
  1600. ),
  1601. ] = None,
  1602. title: Annotated[
  1603. Optional[str],
  1604. Doc(
  1605. """
  1606. Human-readable title.
  1607. """
  1608. ),
  1609. ] = None,
  1610. description: Annotated[
  1611. Optional[str],
  1612. Doc(
  1613. """
  1614. Human-readable description.
  1615. """
  1616. ),
  1617. ] = None,
  1618. gt: Annotated[
  1619. Optional[float],
  1620. Doc(
  1621. """
  1622. Greater than. If set, value must be greater than this. Only applicable to
  1623. numbers.
  1624. """
  1625. ),
  1626. ] = None,
  1627. ge: Annotated[
  1628. Optional[float],
  1629. Doc(
  1630. """
  1631. Greater than or equal. If set, value must be greater than or equal to
  1632. this. Only applicable to numbers.
  1633. """
  1634. ),
  1635. ] = None,
  1636. lt: Annotated[
  1637. Optional[float],
  1638. Doc(
  1639. """
  1640. Less than. If set, value must be less than this. Only applicable to numbers.
  1641. """
  1642. ),
  1643. ] = None,
  1644. le: Annotated[
  1645. Optional[float],
  1646. Doc(
  1647. """
  1648. Less than or equal. If set, value must be less than or equal to this.
  1649. Only applicable to numbers.
  1650. """
  1651. ),
  1652. ] = None,
  1653. min_length: Annotated[
  1654. Optional[int],
  1655. Doc(
  1656. """
  1657. Minimum length for strings.
  1658. """
  1659. ),
  1660. ] = None,
  1661. max_length: Annotated[
  1662. Optional[int],
  1663. Doc(
  1664. """
  1665. Maximum length for strings.
  1666. """
  1667. ),
  1668. ] = None,
  1669. pattern: Annotated[
  1670. Optional[str],
  1671. Doc(
  1672. """
  1673. RegEx pattern for strings.
  1674. """
  1675. ),
  1676. ] = None,
  1677. regex: Annotated[
  1678. Optional[str],
  1679. Doc(
  1680. """
  1681. RegEx pattern for strings.
  1682. """
  1683. ),
  1684. deprecated(
  1685. "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
  1686. ),
  1687. ] = None,
  1688. discriminator: Annotated[
  1689. Union[str, None],
  1690. Doc(
  1691. """
  1692. Parameter field name for discriminating the type in a tagged union.
  1693. """
  1694. ),
  1695. ] = None,
  1696. strict: Annotated[
  1697. Union[bool, None],
  1698. Doc(
  1699. """
  1700. If `True`, strict validation is applied to the field.
  1701. """
  1702. ),
  1703. ] = _Unset,
  1704. multiple_of: Annotated[
  1705. Union[float, None],
  1706. Doc(
  1707. """
  1708. Value must be a multiple of this. Only applicable to numbers.
  1709. """
  1710. ),
  1711. ] = _Unset,
  1712. allow_inf_nan: Annotated[
  1713. Union[bool, None],
  1714. Doc(
  1715. """
  1716. Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
  1717. """
  1718. ),
  1719. ] = _Unset,
  1720. max_digits: Annotated[
  1721. Union[int, None],
  1722. Doc(
  1723. """
  1724. Maximum number of allow digits for strings.
  1725. """
  1726. ),
  1727. ] = _Unset,
  1728. decimal_places: Annotated[
  1729. Union[int, None],
  1730. Doc(
  1731. """
  1732. Maximum number of decimal places allowed for numbers.
  1733. """
  1734. ),
  1735. ] = _Unset,
  1736. examples: Annotated[
  1737. Optional[List[Any]],
  1738. Doc(
  1739. """
  1740. Example values for this field.
  1741. """
  1742. ),
  1743. ] = None,
  1744. example: Annotated[
  1745. Optional[Any],
  1746. deprecated(
  1747. "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
  1748. "although still supported. Use examples instead."
  1749. ),
  1750. ] = _Unset,
  1751. openapi_examples: Annotated[
  1752. Optional[Dict[str, Example]],
  1753. Doc(
  1754. """
  1755. OpenAPI-specific examples.
  1756. It will be added to the generated OpenAPI (e.g. visible at `/docs`).
  1757. Swagger UI (that provides the `/docs` interface) has better support for the
  1758. OpenAPI-specific examples than the JSON Schema `examples`, that's the main
  1759. use case for this.
  1760. Read more about it in the
  1761. [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
  1762. """
  1763. ),
  1764. ] = None,
  1765. deprecated: Annotated[
  1766. Union[deprecated, str, bool, None],
  1767. Doc(
  1768. """
  1769. Mark this parameter field as deprecated.
  1770. It will affect the generated OpenAPI (e.g. visible at `/docs`).
  1771. """
  1772. ),
  1773. ] = None,
  1774. include_in_schema: Annotated[
  1775. bool,
  1776. Doc(
  1777. """
  1778. To include (or not) this parameter field in the generated OpenAPI.
  1779. You probably don't need it, but it's available.
  1780. This affects the generated OpenAPI (e.g. visible at `/docs`).
  1781. """
  1782. ),
  1783. ] = True,
  1784. json_schema_extra: Annotated[
  1785. Union[Dict[str, Any], None],
  1786. Doc(
  1787. """
  1788. Any additional JSON schema data.
  1789. """
  1790. ),
  1791. ] = None,
  1792. **extra: Annotated[
  1793. Any,
  1794. Doc(
  1795. """
  1796. Include extra fields used by the JSON Schema.
  1797. """
  1798. ),
  1799. deprecated(
  1800. """
  1801. The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
  1802. """
  1803. ),
  1804. ],
  1805. ) -> Any:
  1806. return params.Form(
  1807. default=default,
  1808. default_factory=default_factory,
  1809. media_type=media_type,
  1810. alias=alias,
  1811. alias_priority=alias_priority,
  1812. validation_alias=validation_alias,
  1813. serialization_alias=serialization_alias,
  1814. title=title,
  1815. description=description,
  1816. gt=gt,
  1817. ge=ge,
  1818. lt=lt,
  1819. le=le,
  1820. min_length=min_length,
  1821. max_length=max_length,
  1822. pattern=pattern,
  1823. regex=regex,
  1824. discriminator=discriminator,
  1825. strict=strict,
  1826. multiple_of=multiple_of,
  1827. allow_inf_nan=allow_inf_nan,
  1828. max_digits=max_digits,
  1829. decimal_places=decimal_places,
  1830. example=example,
  1831. examples=examples,
  1832. openapi_examples=openapi_examples,
  1833. deprecated=deprecated,
  1834. include_in_schema=include_in_schema,
  1835. json_schema_extra=json_schema_extra,
  1836. **extra,
  1837. )
  1838. def File( # noqa: N802
  1839. default: Annotated[
  1840. Any,
  1841. Doc(
  1842. """
  1843. Default value if the parameter field is not set.
  1844. """
  1845. ),
  1846. ] = Undefined,
  1847. *,
  1848. default_factory: Annotated[
  1849. Union[Callable[[], Any], None],
  1850. Doc(
  1851. """
  1852. A callable to generate the default value.
  1853. This doesn't affect `Path` parameters as the value is always required.
  1854. The parameter is available only for compatibility.
  1855. """
  1856. ),
  1857. ] = _Unset,
  1858. media_type: Annotated[
  1859. str,
  1860. Doc(
  1861. """
  1862. The media type of this parameter field. Changing it would affect the
  1863. generated OpenAPI, but currently it doesn't affect the parsing of the data.
  1864. """
  1865. ),
  1866. ] = "multipart/form-data",
  1867. alias: Annotated[
  1868. Optional[str],
  1869. Doc(
  1870. """
  1871. An alternative name for the parameter field.
  1872. This will be used to extract the data and for the generated OpenAPI.
  1873. It is particularly useful when you can't use the name you want because it
  1874. is a Python reserved keyword or similar.
  1875. """
  1876. ),
  1877. ] = None,
  1878. alias_priority: Annotated[
  1879. Union[int, None],
  1880. Doc(
  1881. """
  1882. Priority of the alias. This affects whether an alias generator is used.
  1883. """
  1884. ),
  1885. ] = _Unset,
  1886. # TODO: update when deprecating Pydantic v1, import these types
  1887. # validation_alias: str | AliasPath | AliasChoices | None
  1888. validation_alias: Annotated[
  1889. Union[str, None],
  1890. Doc(
  1891. """
  1892. 'Whitelist' validation step. The parameter field will be the single one
  1893. allowed by the alias or set of aliases defined.
  1894. """
  1895. ),
  1896. ] = None,
  1897. serialization_alias: Annotated[
  1898. Union[str, None],
  1899. Doc(
  1900. """
  1901. 'Blacklist' validation step. The vanilla parameter field will be the
  1902. single one of the alias' or set of aliases' fields and all the other
  1903. fields will be ignored at serialization time.
  1904. """
  1905. ),
  1906. ] = None,
  1907. title: Annotated[
  1908. Optional[str],
  1909. Doc(
  1910. """
  1911. Human-readable title.
  1912. """
  1913. ),
  1914. ] = None,
  1915. description: Annotated[
  1916. Optional[str],
  1917. Doc(
  1918. """
  1919. Human-readable description.
  1920. """
  1921. ),
  1922. ] = None,
  1923. gt: Annotated[
  1924. Optional[float],
  1925. Doc(
  1926. """
  1927. Greater than. If set, value must be greater than this. Only applicable to
  1928. numbers.
  1929. """
  1930. ),
  1931. ] = None,
  1932. ge: Annotated[
  1933. Optional[float],
  1934. Doc(
  1935. """
  1936. Greater than or equal. If set, value must be greater than or equal to
  1937. this. Only applicable to numbers.
  1938. """
  1939. ),
  1940. ] = None,
  1941. lt: Annotated[
  1942. Optional[float],
  1943. Doc(
  1944. """
  1945. Less than. If set, value must be less than this. Only applicable to numbers.
  1946. """
  1947. ),
  1948. ] = None,
  1949. le: Annotated[
  1950. Optional[float],
  1951. Doc(
  1952. """
  1953. Less than or equal. If set, value must be less than or equal to this.
  1954. Only applicable to numbers.
  1955. """
  1956. ),
  1957. ] = None,
  1958. min_length: Annotated[
  1959. Optional[int],
  1960. Doc(
  1961. """
  1962. Minimum length for strings.
  1963. """
  1964. ),
  1965. ] = None,
  1966. max_length: Annotated[
  1967. Optional[int],
  1968. Doc(
  1969. """
  1970. Maximum length for strings.
  1971. """
  1972. ),
  1973. ] = None,
  1974. pattern: Annotated[
  1975. Optional[str],
  1976. Doc(
  1977. """
  1978. RegEx pattern for strings.
  1979. """
  1980. ),
  1981. ] = None,
  1982. regex: Annotated[
  1983. Optional[str],
  1984. Doc(
  1985. """
  1986. RegEx pattern for strings.
  1987. """
  1988. ),
  1989. deprecated(
  1990. "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
  1991. ),
  1992. ] = None,
  1993. discriminator: Annotated[
  1994. Union[str, None],
  1995. Doc(
  1996. """
  1997. Parameter field name for discriminating the type in a tagged union.
  1998. """
  1999. ),
  2000. ] = None,
  2001. strict: Annotated[
  2002. Union[bool, None],
  2003. Doc(
  2004. """
  2005. If `True`, strict validation is applied to the field.
  2006. """
  2007. ),
  2008. ] = _Unset,
  2009. multiple_of: Annotated[
  2010. Union[float, None],
  2011. Doc(
  2012. """
  2013. Value must be a multiple of this. Only applicable to numbers.
  2014. """
  2015. ),
  2016. ] = _Unset,
  2017. allow_inf_nan: Annotated[
  2018. Union[bool, None],
  2019. Doc(
  2020. """
  2021. Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
  2022. """
  2023. ),
  2024. ] = _Unset,
  2025. max_digits: Annotated[
  2026. Union[int, None],
  2027. Doc(
  2028. """
  2029. Maximum number of allow digits for strings.
  2030. """
  2031. ),
  2032. ] = _Unset,
  2033. decimal_places: Annotated[
  2034. Union[int, None],
  2035. Doc(
  2036. """
  2037. Maximum number of decimal places allowed for numbers.
  2038. """
  2039. ),
  2040. ] = _Unset,
  2041. examples: Annotated[
  2042. Optional[List[Any]],
  2043. Doc(
  2044. """
  2045. Example values for this field.
  2046. """
  2047. ),
  2048. ] = None,
  2049. example: Annotated[
  2050. Optional[Any],
  2051. deprecated(
  2052. "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
  2053. "although still supported. Use examples instead."
  2054. ),
  2055. ] = _Unset,
  2056. openapi_examples: Annotated[
  2057. Optional[Dict[str, Example]],
  2058. Doc(
  2059. """
  2060. OpenAPI-specific examples.
  2061. It will be added to the generated OpenAPI (e.g. visible at `/docs`).
  2062. Swagger UI (that provides the `/docs` interface) has better support for the
  2063. OpenAPI-specific examples than the JSON Schema `examples`, that's the main
  2064. use case for this.
  2065. Read more about it in the
  2066. [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
  2067. """
  2068. ),
  2069. ] = None,
  2070. deprecated: Annotated[
  2071. Union[deprecated, str, bool, None],
  2072. Doc(
  2073. """
  2074. Mark this parameter field as deprecated.
  2075. It will affect the generated OpenAPI (e.g. visible at `/docs`).
  2076. """
  2077. ),
  2078. ] = None,
  2079. include_in_schema: Annotated[
  2080. bool,
  2081. Doc(
  2082. """
  2083. To include (or not) this parameter field in the generated OpenAPI.
  2084. You probably don't need it, but it's available.
  2085. This affects the generated OpenAPI (e.g. visible at `/docs`).
  2086. """
  2087. ),
  2088. ] = True,
  2089. json_schema_extra: Annotated[
  2090. Union[Dict[str, Any], None],
  2091. Doc(
  2092. """
  2093. Any additional JSON schema data.
  2094. """
  2095. ),
  2096. ] = None,
  2097. **extra: Annotated[
  2098. Any,
  2099. Doc(
  2100. """
  2101. Include extra fields used by the JSON Schema.
  2102. """
  2103. ),
  2104. deprecated(
  2105. """
  2106. The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
  2107. """
  2108. ),
  2109. ],
  2110. ) -> Any:
  2111. return params.File(
  2112. default=default,
  2113. default_factory=default_factory,
  2114. media_type=media_type,
  2115. alias=alias,
  2116. alias_priority=alias_priority,
  2117. validation_alias=validation_alias,
  2118. serialization_alias=serialization_alias,
  2119. title=title,
  2120. description=description,
  2121. gt=gt,
  2122. ge=ge,
  2123. lt=lt,
  2124. le=le,
  2125. min_length=min_length,
  2126. max_length=max_length,
  2127. pattern=pattern,
  2128. regex=regex,
  2129. discriminator=discriminator,
  2130. strict=strict,
  2131. multiple_of=multiple_of,
  2132. allow_inf_nan=allow_inf_nan,
  2133. max_digits=max_digits,
  2134. decimal_places=decimal_places,
  2135. example=example,
  2136. examples=examples,
  2137. openapi_examples=openapi_examples,
  2138. deprecated=deprecated,
  2139. include_in_schema=include_in_schema,
  2140. json_schema_extra=json_schema_extra,
  2141. **extra,
  2142. )
  2143. def Depends( # noqa: N802
  2144. dependency: Annotated[
  2145. Optional[Callable[..., Any]],
  2146. Doc(
  2147. """
  2148. A "dependable" callable (like a function).
  2149. Don't call it directly, FastAPI will call it for you, just pass the object
  2150. directly.
  2151. """
  2152. ),
  2153. ] = None,
  2154. *,
  2155. use_cache: Annotated[
  2156. bool,
  2157. Doc(
  2158. """
  2159. By default, after a dependency is called the first time in a request, if
  2160. the dependency is declared again for the rest of the request (for example
  2161. if the dependency is needed by several dependencies), the value will be
  2162. re-used for the rest of the request.
  2163. Set `use_cache` to `False` to disable this behavior and ensure the
  2164. dependency is called again (if declared more than once) in the same request.
  2165. """
  2166. ),
  2167. ] = True,
  2168. ) -> Any:
  2169. """
  2170. Declare a FastAPI dependency.
  2171. It takes a single "dependable" callable (like a function).
  2172. Don't call it directly, FastAPI will call it for you.
  2173. Read more about it in the
  2174. [FastAPI docs for Dependencies](https://fastapi.tiangolo.com/tutorial/dependencies/).
  2175. **Example**
  2176. ```python
  2177. from typing import Annotated
  2178. from fastapi import Depends, FastAPI
  2179. app = FastAPI()
  2180. async def common_parameters(q: str | None = None, skip: int = 0, limit: int = 100):
  2181. return {"q": q, "skip": skip, "limit": limit}
  2182. @app.get("/items/")
  2183. async def read_items(commons: Annotated[dict, Depends(common_parameters)]):
  2184. return commons
  2185. ```
  2186. """
  2187. return params.Depends(dependency=dependency, use_cache=use_cache)
  2188. def Security( # noqa: N802
  2189. dependency: Annotated[
  2190. Optional[Callable[..., Any]],
  2191. Doc(
  2192. """
  2193. A "dependable" callable (like a function).
  2194. Don't call it directly, FastAPI will call it for you, just pass the object
  2195. directly.
  2196. """
  2197. ),
  2198. ] = None,
  2199. *,
  2200. scopes: Annotated[
  2201. Optional[Sequence[str]],
  2202. Doc(
  2203. """
  2204. OAuth2 scopes required for the *path operation* that uses this Security
  2205. dependency.
  2206. The term "scope" comes from the OAuth2 specification, it seems to be
  2207. intentionally vague and interpretable. It normally refers to permissions,
  2208. in cases to roles.
  2209. These scopes are integrated with OpenAPI (and the API docs at `/docs`).
  2210. So they are visible in the OpenAPI specification.
  2211. )
  2212. """
  2213. ),
  2214. ] = None,
  2215. use_cache: Annotated[
  2216. bool,
  2217. Doc(
  2218. """
  2219. By default, after a dependency is called the first time in a request, if
  2220. the dependency is declared again for the rest of the request (for example
  2221. if the dependency is needed by several dependencies), the value will be
  2222. re-used for the rest of the request.
  2223. Set `use_cache` to `False` to disable this behavior and ensure the
  2224. dependency is called again (if declared more than once) in the same request.
  2225. """
  2226. ),
  2227. ] = True,
  2228. ) -> Any:
  2229. """
  2230. Declare a FastAPI Security dependency.
  2231. The only difference with a regular dependency is that it can declare OAuth2
  2232. scopes that will be integrated with OpenAPI and the automatic UI docs (by default
  2233. at `/docs`).
  2234. It takes a single "dependable" callable (like a function).
  2235. Don't call it directly, FastAPI will call it for you.
  2236. Read more about it in the
  2237. [FastAPI docs for Security](https://fastapi.tiangolo.com/tutorial/security/) and
  2238. in the
  2239. [FastAPI docs for OAuth2 scopes](https://fastapi.tiangolo.com/advanced/security/oauth2-scopes/).
  2240. **Example**
  2241. ```python
  2242. from typing import Annotated
  2243. from fastapi import Security, FastAPI
  2244. from .db import User
  2245. from .security import get_current_active_user
  2246. app = FastAPI()
  2247. @app.get("/users/me/items/")
  2248. async def read_own_items(
  2249. current_user: Annotated[User, Security(get_current_active_user, scopes=["items"])]
  2250. ):
  2251. return [{"item_id": "Foo", "owner": current_user.username}]
  2252. ```
  2253. """
  2254. return params.Security(dependency=dependency, scopes=scopes, use_cache=use_cache)