---
source: crates/ruff_linter/src/rules/fastapi/mod.rs
---
FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_0.py:24:5
   |
22 | @app.get("/items/")
23 | def get_items(
24 |     current_user: User = Depends(get_current_user),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25 |     some_security_param: str = Security(get_oauth2_user),
26 | ):
   |
help: Replace with `typing_extensions.Annotated`
   |
14 | from pydantic import BaseModel
15 + from typing_extensions import Annotated
16 |
--------------------------------------------------------------------------------
24 | def get_items(
   -     current_user: User = Depends(get_current_user),
25 +     current_user: Annotated[User, Depends(get_current_user)],
26 |     some_security_param: str = Security(get_oauth2_user),
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_0.py:25:5
   |
23 | def get_items(
24 |     current_user: User = Depends(get_current_user),
25 |     some_security_param: str = Security(get_oauth2_user),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26 | ):
27 |     pass
   |
help: Replace with `typing_extensions.Annotated`
   |
14 | from pydantic import BaseModel
15 + from typing_extensions import Annotated
16 |
--------------------------------------------------------------------------------
25 |     current_user: User = Depends(get_current_user),
   -     some_security_param: str = Security(get_oauth2_user),
26 +     some_security_param: Annotated[str, Security(get_oauth2_user)],
27 | ):
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_0.py:32:5
   |
30 | @app.post("/stuff/")
31 | def do_stuff(
32 |     some_path_param: str = Path(),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33 |     some_cookie_param: str = Cookie(),
34 |     some_file_param: UploadFile = File(),
   |
help: Replace with `typing_extensions.Annotated`
   |
14 | from pydantic import BaseModel
15 + from typing_extensions import Annotated
16 |
--------------------------------------------------------------------------------
32 | def do_stuff(
   -     some_path_param: str = Path(),
33 +     some_path_param: Annotated[str, Path()],
34 |     some_cookie_param: str = Cookie(),
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_0.py:33:5
   |
31 | def do_stuff(
32 |     some_path_param: str = Path(),
33 |     some_cookie_param: str = Cookie(),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34 |     some_file_param: UploadFile = File(),
35 |     some_form_param: str = Form(),
   |
help: Replace with `typing_extensions.Annotated`
   |
14 | from pydantic import BaseModel
15 + from typing_extensions import Annotated
16 |
--------------------------------------------------------------------------------
33 |     some_path_param: str = Path(),
   -     some_cookie_param: str = Cookie(),
34 +     some_cookie_param: Annotated[str, Cookie()],
35 |     some_file_param: UploadFile = File(),
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_0.py:34:5
   |
32 |     some_path_param: str = Path(),
33 |     some_cookie_param: str = Cookie(),
34 |     some_file_param: UploadFile = File(),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
35 |     some_form_param: str = Form(),
36 |     some_query_param: str | None = Query(default=None),
   |
help: Replace with `typing_extensions.Annotated`
   |
14 | from pydantic import BaseModel
15 + from typing_extensions import Annotated
16 |
--------------------------------------------------------------------------------
34 |     some_cookie_param: str = Cookie(),
   -     some_file_param: UploadFile = File(),
35 +     some_file_param: Annotated[UploadFile, File()],
36 |     some_form_param: str = Form(),
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_0.py:35:5
   |
33 |     some_cookie_param: str = Cookie(),
34 |     some_file_param: UploadFile = File(),
35 |     some_form_param: str = Form(),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36 |     some_query_param: str | None = Query(default=None),
37 |     some_body_param: str = Body("foo"),
   |
help: Replace with `typing_extensions.Annotated`
   |
14 | from pydantic import BaseModel
15 + from typing_extensions import Annotated
16 |
--------------------------------------------------------------------------------
35 |     some_file_param: UploadFile = File(),
   -     some_form_param: str = Form(),
36 +     some_form_param: Annotated[str, Form()],
37 |     some_query_param: str | None = Query(default=None),
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_0.py:36:5
   |
34 |     some_file_param: UploadFile = File(),
35 |     some_form_param: str = Form(),
36 |     some_query_param: str | None = Query(default=None),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37 |     some_body_param: str = Body("foo"),
38 |     some_header_param: int = Header(default=5),
   |
help: Replace with `typing_extensions.Annotated`
   |
14 | from pydantic import BaseModel
15 + from typing_extensions import Annotated
16 |
--------------------------------------------------------------------------------
36 |     some_form_param: str = Form(),
   -     some_query_param: str | None = Query(default=None),
37 +     some_query_param: Annotated[str | None, Query()] = None,
38 |     some_body_param: str = Body("foo"),
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_0.py:37:5
   |
35 |     some_form_param: str = Form(),
36 |     some_query_param: str | None = Query(default=None),
37 |     some_body_param: str = Body("foo"),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38 |     some_header_param: int = Header(default=5),
39 | ):
   |
help: Replace with `typing_extensions.Annotated`
   |
14 | from pydantic import BaseModel
15 + from typing_extensions import Annotated
16 |
--------------------------------------------------------------------------------
37 |     some_query_param: str | None = Query(default=None),
   -     some_body_param: str = Body("foo"),
38 +     some_body_param: Annotated[str, Body()] = "foo",
39 |     some_header_param: int = Header(default=5),
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_0.py:38:5
   |
36 |     some_query_param: str | None = Query(default=None),
37 |     some_body_param: str = Body("foo"),
38 |     some_header_param: int = Header(default=5),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39 | ):
40 |     # do stuff
   |
help: Replace with `typing_extensions.Annotated`
   |
14 | from pydantic import BaseModel
15 + from typing_extensions import Annotated
16 |
--------------------------------------------------------------------------------
38 |     some_body_param: str = Body("foo"),
   -     some_header_param: int = Header(default=5),
39 +     some_header_param: Annotated[int, Header()] = 5,
40 | ):
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_0.py:47:5
   |
45 |     skip: int,
46 |     limit: int,
47 |     current_user: User = Depends(get_current_user),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
48 | ):
49 |     pass
   |
help: Replace with `typing_extensions.Annotated`
   |
14 | from pydantic import BaseModel
15 + from typing_extensions import Annotated
16 |
--------------------------------------------------------------------------------
47 |     limit: int,
   -     current_user: User = Depends(get_current_user),
48 +     current_user: Annotated[User, Depends(get_current_user)],
49 | ):
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_0.py:53:5
   |
51 | @app.get("/users/")
52 | def get_users(
53 |     current_user: User = Depends(get_current_user),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54 |     skip: int = 0,
55 |     limit: int = 10,
   |
help: Replace with `typing_extensions.Annotated`
   |
14 | from pydantic import BaseModel
15 + from typing_extensions import Annotated
16 |
--------------------------------------------------------------------------------
53 | def get_users(
   -     current_user: User = Depends(get_current_user),
54 +     current_user: Annotated[User, Depends(get_current_user)],
55 |     skip: int = 0,
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_0.py:61:25
   |
60 | @app.get("/items/{item_id}")
61 | async def read_items(*, item_id: int = Path(title="The ID of the item to get"), q: str):
   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
62 |     pass
   |
help: Replace with `typing_extensions.Annotated`
   |
14 | from pydantic import BaseModel
15 + from typing_extensions import Annotated
16 |
--------------------------------------------------------------------------------
61 | @app.get("/items/{item_id}")
   - async def read_items(*, item_id: int = Path(title="The ID of the item to get"), q: str):
62 + async def read_items(*, item_id: Annotated[int, Path(title="The ID of the item to get")], q: str):
63 |     pass
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 FastAPI dependency without `Annotated`
  --> FAST002_0.py:70:5
   |
68 |     skip: int = 0,
69 |     limit: int = 10,
70 |     current_user: User = Depends(get_current_user),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
71 | ):
72 |     pass
   |
help: Replace with `typing_extensions.Annotated`
info: Automatic fix is unavailable because a required parameter would follow an optional parameter. Consider reordering arguments to enable the fix.
