Skip to content

📝 Fix docs issues reported in pinned discussion - #16407

Open
YuriiMotov wants to merge 20 commits into
masterfrom
fix-docs-issues
Open

YuriiMotov wants to merge 20 commits into
masterfrom
fix-docs-issues

Conversation

@YuriiMotov

@YuriiMotov YuriiMotov commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

This PR addresses docs issues reported in pinned discussion: #15849

It's probably easier to review this PR commit by commit - every commit is one fix.

@YuriiMotov YuriiMotov added the docs Documentation about how to use FastAPI label Sep 28, 2026
@codspeed

codspeed Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 24 untouched benchmarks


Comparing fix-docs-issues (7755ec3) with master (79d42b2)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (c30032a) during the generation of this report, so 79d42b2 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

📝 Docs preview

Last commit 7755ec3 at: https://a1e56705.fastapitiangolo.pages.dev

Modified Pages

First, let's quickly see the parts that change from the examples in the main **Tutorial - User Guide** for [OAuth2 with Password (and hashing), Bearer with JWT tokens](../../tutorial/security/oauth2-jwt.md). Now using OAuth2 scopes:

{* ../../docs_src/security/tutorial005_an_py310.py hl[5,9,13,47,65,106,108:116,122:126,130:136,141,157] *}
{* ../../docs_src/security/tutorial005_an_py310.py hl[5,9,13,47,67,109,111:114,118,125:128,133:139,144,160,175,180:182] *}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked it matches the real diff between tutorial004_an_py310.py and tutorial005_an_py310.py except adding one more item in fake_users_db, which is unrelated change


In this case, it requires the scope `me` (it could require more than one scope).

The `/status/` *path operation* uses `Depends(get_current_user)` without declaring any scopes. It requires a valid token, but no specific permissions.

@YuriiMotov YuriiMotov Sep 28, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the diff wasn't explained, so I added a small note about it here and one more sentence below in Verify the scopes

The `scopes` parameter receives a `dict` with each scope as a key and the description as the value:

{* ../../docs_src/security/tutorial005_an_py310.py hl[63:66] *}
{* ../../docs_src/security/tutorial005_an_py310.py ln[65:68] hl[67] *}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also specified ln[...] in all code includes except the first one (in Global view) - to make it more readable

Create a response as described in [Return a Response Directly](response-directly.md) and pass the headers as an additional parameter:

{* ../../docs_src/response_headers/tutorial001_py310.py hl[10:12] *}
{* ../../docs_src/response_headers/tutorial001_py310.py hl[10:11] *}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some highlights specified lines numbers that are out-of-range. See commit b2cea45

Coming from the previous example, your `config.py` file could look like:

{* ../../docs_src/settings/app02_an_py310/config.py hl[10] *}
{* ../../docs_src/settings/app02_an_py310/config.py *}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No such line and no need to highlight anything. See preview

In this example, it would link to a CSS file at `static/styles.css` with:

```CSS hl_lines="4"
```CSS

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No such line and no need to highlight anything. See preview

///

## Await for messages and send messages { #await-for-messages-and-send-messages }
## Await messages and send messages { #await-messages-and-send-messages }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"await for something" is incorrect. It should be either "await something" or "wait for something"

Create a utility function to generate a new access token.

{* ../../docs_src/security/tutorial004_an_py310.py hl[4,7,13:15,29:31,82:90] *}
{* ../../docs_src/security/tutorial004_an_py310.py ln[4:9,11:15,29:31,82:90] hl[4,7,13:15,29:31,82:90] *}

@YuriiMotov YuriiMotov Sep 28, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hid the unrelated lines in code examples. Left the first code example unfolded.
Page preview: https://24b58251.fastapitiangolo.pages.dev/tutorial/security/simple-oauth2/

Comment on lines +181 to +188
/// note

FastAPI uses Pydantic for data validation. In Pydantic v2, regular expressions use Rust's `regex` library by default. Its syntax and behavior have some differences from Python's `re` module.

You can read more in the [Pydantic migration guide](https://pydantic.dev/docs/validation/latest/get-started/migration/#patterns--regex-on-strings).

///

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +427 to +429
Then with `random.choice()` we can get a **random value** from the list, so, we get a tuple with `(id, item)`. It will be something like `("imdb-tt0371724", "The Hitchhiker's Guide to the Galaxy")`.

Then we **assign those two values** of the tuple to the variables `id` and `name`.
Then we **assign those two values** of the tuple to the variables `id` and `item`.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In code example the name of the variable is item:

@app.get("/items/")
async def read_items(
id: Annotated[str | None, AfterValidator(check_valid_id)] = None,
):
if id:
item = data.get(id)
else:
id, item = random.choice(list(data.items()))
return {"id": id, "name": item}

Comment thread docs/en/docs/index.md

* Declaration of **parameters** from other different places such as: **headers**, **cookies**, **form fields** and **files**.
* How to set **validation constraints** such as `maximum_length` or `regex`.
* How to set **validation constraints** such as `max_length` or `pattern`.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maximum_length was probably a typo, and regex has been deprecated

detail="Incorrect username or password",
headers={"WWW-Authenticate": "Bearer"},
)
raise HTTPException(status_code=400, detail="Incorrect username or password")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In tutorial 5 we already use status code 400 for this. And 400 is correct here.

@app.post("/token")
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()],
) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(status_code=400, detail="Incorrect username or password")

@YuriiMotov
YuriiMotov marked this pull request as ready for review September 28, 2026 19:47

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation about how to use FastAPI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants