📝 Fix docs issues reported in pinned discussion - #16407
YuriiMotov wants to merge 20 commits into
Conversation
| 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] *} |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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] *} |
There was a problem hiding this comment.
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] *} |
There was a problem hiding this comment.
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 *} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
"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] *} |
There was a problem hiding this comment.
Hid the unrelated lines in code examples. Left the first code example unfolded.
Page preview: https://24b58251.fastapitiangolo.pages.dev/tutorial/security/simple-oauth2/
| /// 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). | ||
|
|
||
| /// | ||
|
|
| 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`. |
There was a problem hiding this comment.
In code example the name of the variable is item:
fastapi/docs_src/query_params_str_validations/tutorial015_an_py310.py
Lines 22 to 30 in a3d205b
|
|
||
| * 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`. |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
In tutorial 5 we already use status code 400 for this. And 400 is correct here.
fastapi/docs_src/security/tutorial005_an_py310.py
Lines 151 to 157 in a3d205b
bb1aaa6 to
0c91857
Compare
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.