---
source: crates/ruff_linter/src/rules/fastapi/mod.rs
---
FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_2.py:14:5
   |
12 | async def test_ellipsis_query(
13 |     # This should become: param: Annotated[str, Query(description="Test param")]
14 |     param: str = Query(..., description="Test param"),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15 | ) -> str:
16 |     return param
   |
help: Replace with `typing_extensions.Annotated`
   |
3  | from fastapi import Body, Cookie, FastAPI, Header, Query
4  + from typing_extensions import Annotated
5  |
--------------------------------------------------------------------------------
14 |     # This should become: param: Annotated[str, Query(description="Test param")]
   -     param: str = Query(..., description="Test param"),
15 +     param: Annotated[str, Query(description="Test param")],
16 | ) -> str:
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_2.py:22:5
   |
20 | async def test_ellipsis_header(
21 |     # This should become: auth: Annotated[str, Header(description="Auth header")]
22 |     auth: str = Header(..., description="Auth header"),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23 | ) -> str:
24 |     return auth
   |
help: Replace with `typing_extensions.Annotated`
   |
3  | from fastapi import Body, Cookie, FastAPI, Header, Query
4  + from typing_extensions import Annotated
5  |
--------------------------------------------------------------------------------
22 |     # This should become: auth: Annotated[str, Header(description="Auth header")]
   -     auth: str = Header(..., description="Auth header"),
23 +     auth: Annotated[str, Header(description="Auth header")],
24 | ) -> str:
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_2.py:30:5
   |
28 | async def test_ellipsis_body(
29 |     # This should become: data: Annotated[dict, Body(description="Request body")]
30 |     data: dict = Body(..., description="Request body"),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31 | ) -> dict:
32 |     return data
   |
help: Replace with `typing_extensions.Annotated`
   |
3  | from fastapi import Body, Cookie, FastAPI, Header, Query
4  + from typing_extensions import Annotated
5  |
--------------------------------------------------------------------------------
30 |     # This should become: data: Annotated[dict, Body(description="Request body")]
   -     data: dict = Body(..., description="Request body"),
31 +     data: Annotated[dict, Body(description="Request body")],
32 | ) -> dict:
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_2.py:38:5
   |
36 | async def test_ellipsis_cookie(
37 |     # This should become: session: Annotated[str, Cookie(description="Session ID")]
38 |     session: str = Cookie(..., description="Session ID"),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39 | ) -> str:
40 |     return session
   |
help: Replace with `typing_extensions.Annotated`
   |
3  | from fastapi import Body, Cookie, FastAPI, Header, Query
4  + from typing_extensions import Annotated
5  |
--------------------------------------------------------------------------------
38 |     # This should become: session: Annotated[str, Cookie(description="Session ID")]
   -     session: str = Cookie(..., description="Session ID"),
39 +     session: Annotated[str, Cookie(description="Session ID")],
40 | ) -> str:
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_2.py:46:5
   |
44 | async def test_simple_ellipsis(
45 |     # This should become: id: Annotated[str, Query()]
46 |     id: str = Query(...),
   |     ^^^^^^^^^^^^^^^^^^^^
47 | ) -> str:
48 |     return id
   |
help: Replace with `typing_extensions.Annotated`
   |
3  | from fastapi import Body, Cookie, FastAPI, Header, Query
4  + from typing_extensions import Annotated
5  |
--------------------------------------------------------------------------------
46 |     # This should become: id: Annotated[str, Query()]
   -     id: str = Query(...),
47 +     id: Annotated[str, Query()],
48 | ) -> str:
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_2.py:54:5
   |
52 | async def test_multiple_kwargs_with_ellipsis(
53 |     # This should become: param: Annotated[str, Query(description="Test", min_length=1, max_length=10)]
54 |     param: str = Query(..., description="Test", min_length=1, max_length=10),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55 | ) -> str:
56 |     return param
   |
help: Replace with `typing_extensions.Annotated`
   |
3  | from fastapi import Body, Cookie, FastAPI, Header, Query
4  + from typing_extensions import Annotated
5  |
--------------------------------------------------------------------------------
54 |     # This should become: param: Annotated[str, Query(description="Test", min_length=1, max_length=10)]
   -     param: str = Query(..., description="Test", min_length=1, max_length=10),
55 +     param: Annotated[str, Query(description="Test", min_length=1, max_length=10)],
56 | ) -> str:
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_2.py:65:5
   |
63 | async def test_with_default_value(
64 |     # This should become: param: Annotated[str, Query(description="Test")] = "default"
65 |     param: str = Query("default", description="Test"),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66 | ) -> str:
67 |     return param
   |
help: Replace with `typing_extensions.Annotated`
   |
3  | from fastapi import Body, Cookie, FastAPI, Header, Query
4  + from typing_extensions import Annotated
5  |
--------------------------------------------------------------------------------
65 |     # This should become: param: Annotated[str, Query(description="Test")] = "default"
   -     param: str = Query("default", description="Test"),
66 +     param: Annotated[str, Query(description="Test")] = "default",
67 | ) -> str:
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_2.py:73:5
   |
71 | async def test_with_default_none(
72 |     # This should become: param: Annotated[str | None, Query(description="Test")] = None
73 |     param: str | None = Query(None, description="Test"),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
74 | ) -> str:
75 |     return param or "empty"
   |
help: Replace with `typing_extensions.Annotated`
   |
3  | from fastapi import Body, Cookie, FastAPI, Header, Query
4  + from typing_extensions import Annotated
5  |
--------------------------------------------------------------------------------
73 |     # This should become: param: Annotated[str | None, Query(description="Test")] = None
   -     param: str | None = Query(None, description="Test"),
74 +     param: Annotated[str | None, Query(description="Test")] = None,
75 | ) -> str:
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_2.py:81:5
   |
79 | async def test_mixed_parameters(
80 |     # First param should be fixed with default preserved  
81 |     optional_param: str = Query("default", description="Optional"),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82 |     # Second param should not be fixed because of the preceding default
83 |     required_param: str = Query(..., description="Required"),
   |
help: Replace with `typing_extensions.Annotated`
   |
3  | from fastapi import Body, Cookie, FastAPI, Header, Query
4  + from typing_extensions import Annotated
5  |
--------------------------------------------------------------------------------
81 |     # First param should be fixed with default preserved  
   -     optional_param: str = Query("default", description="Optional"),
82 +     optional_param: Annotated[str, Query(description="Optional")] = "default",
83 |     # Second param should not be fixed because of the preceding default
   |
note: This is an unsafe fix and may change runtime behavior

FAST002 FastAPI dependency without `Annotated`
  --> FAST002_2.py:83:5
   |
81 |     optional_param: str = Query("default", description="Optional"),
82 |     # Second param should not be fixed because of the preceding default
83 |     required_param: str = Query(..., description="Required"),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
84 |     # Third param should be fixed with default preserved
85 |     another_optional_param: int = Query(42, description="Another optional"),
   |
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.

FAST002 [*] FastAPI dependency without `Annotated`
  --> FAST002_2.py:85:5
   |
83 |     required_param: str = Query(..., description="Required"),
84 |     # Third param should be fixed with default preserved
85 |     another_optional_param: int = Query(42, description="Another optional"),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86 | ) -> str:
87 |     return f"{required_param}-{optional_param}-{another_optional_param}"
   |
help: Replace with `typing_extensions.Annotated`
   |
3  | from fastapi import Body, Cookie, FastAPI, Header, Query
4  + from typing_extensions import Annotated
5  |
--------------------------------------------------------------------------------
85 |     # Third param should be fixed with default preserved
   -     another_optional_param: int = Query(42, description="Another optional"),
86 +     another_optional_param: Annotated[int, Query(description="Another optional")] = 42,
87 | ) -> str:
   |
note: This is an unsafe fix and may change runtime behavior
