📝 Update includes in `docs/en/docs/how-to/extending-openapi.md` (#12562)

This commit is contained in:
Philip Okiokio 2024-10-27 16:15:05 +01:00 committed by GitHub
parent 128c96dc9a
commit 092da9a8a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 15 deletions

View File

@ -43,25 +43,24 @@ For example, let's add <a href="https://github.com/Rebilly/ReDoc/blob/master/doc
First, write all your **FastAPI** application as normally:
```Python hl_lines="1 4 7-9"
{!../../docs_src/extending_openapi/tutorial001.py!}
```
{* ../../docs_src/extending_openapi/tutorial001.py hl[1,4,7:9] *}
### Generate the OpenAPI schema
Then, use the same utility function to generate the OpenAPI schema, inside a `custom_openapi()` function:
```Python hl_lines="2 15-21"
{!../../docs_src/extending_openapi/tutorial001.py!}
```
{* ../../docs_src/extending_openapi/tutorial001.py hl[2,15:21] *}
### Modify the OpenAPI schema
Now you can add the ReDoc extension, adding a custom `x-logo` to the `info` "object" in the OpenAPI schema:
```Python hl_lines="22-24"
{!../../docs_src/extending_openapi/tutorial001.py!}
```
{* ../../docs_src/extending_openapi/tutorial001.py hl[22:24] *}
### Cache the OpenAPI schema
@ -71,17 +70,18 @@ That way, your application won't have to generate the schema every time a user o
It will be generated only once, and then the same cached schema will be used for the next requests.
```Python hl_lines="13-14 25-26"
{!../../docs_src/extending_openapi/tutorial001.py!}
```
{* ../../docs_src/extending_openapi/tutorial001.py hl[13:14,25:26] *}
### Override the method
Now you can replace the `.openapi()` method with your new function.
```Python hl_lines="29"
{!../../docs_src/extending_openapi/tutorial001.py!}
```
{* ../../docs_src/extending_openapi/tutorial001.py hl[29] *}
### Check it