params.py 26 KB

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