Browse Source

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

pull/12626/head
Philip Okiokio 5 months ago
committed by GitHub
parent
commit
092da9a8a3
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 30
      docs/en/docs/how-to/extending-openapi.md

30
docs/en/docs/how-to/extending-openapi.md

@ -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

Loading…
Cancel
Save