Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 7 additions & 121 deletions docs/en/docs/tutorial/path-operation-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,7 @@ You can pass directly the `int` code, like `404`.

But if you don't remember what each number code is for, you can use the shortcut constants in `status`:

//// tab | Python 3.10+

```Python hl_lines="1 15"
{!> ../../docs_src/path_operation_configuration/tutorial001_py310.py!}
```

////

//// tab | Python 3.9+

```Python hl_lines="3 17"
{!> ../../docs_src/path_operation_configuration/tutorial001_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="3 17"
{!> ../../docs_src/path_operation_configuration/tutorial001.py!}
```

////
{* ../../docs_src/path_operation_configuration/tutorial001_py310.py hl[1,15] *}

That status code will be used in the response and will be added to the OpenAPI schema.

Expand All @@ -54,29 +32,7 @@ You could also use `from starlette import status`.

You can add tags to your *path operation*, pass the parameter `tags` with a `list` of `str` (commonly just one `str`):

//// tab | Python 3.10+

```Python hl_lines="15 20 25"
{!> ../../docs_src/path_operation_configuration/tutorial002_py310.py!}
```

////

//// tab | Python 3.9+

```Python hl_lines="17 22 27"
{!> ../../docs_src/path_operation_configuration/tutorial002_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="17 22 27"
{!> ../../docs_src/path_operation_configuration/tutorial002.py!}
```

////
{* ../../docs_src/path_operation_configuration/tutorial002_py310.py hl[15,20,25] *}

They will be added to the OpenAPI schema and used by the automatic documentation interfaces:

Expand All @@ -90,67 +46,21 @@ In these cases, it could make sense to store the tags in an `Enum`.

**FastAPI** supports that the same way as with plain strings:

```Python hl_lines="1 8-10 13 18"
{!../../docs_src/path_operation_configuration/tutorial002b.py!}
```
{* ../../docs_src/path_operation_configuration/tutorial002b.py hl[1,8:10,13,18] *}

## Summary and description

You can add a `summary` and `description`:

//// tab | Python 3.10+

```Python hl_lines="18-19"
{!> ../../docs_src/path_operation_configuration/tutorial003_py310.py!}
```

////

//// tab | Python 3.9+

```Python hl_lines="20-21"
{!> ../../docs_src/path_operation_configuration/tutorial003_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="20-21"
{!> ../../docs_src/path_operation_configuration/tutorial003.py!}
```

////
{* ../../docs_src/path_operation_configuration/tutorial003_py310.py hl[18:19] *}

## Description from docstring

As descriptions tend to be long and cover multiple lines, you can declare the *path operation* description in the function <abbr title="a multi-line string as the first expression inside a function (not assigned to any variable) used for documentation">docstring</abbr> and **FastAPI** will read it from there.

You can write <a href="https://en.wikipedia.org/wiki/Markdown" class="external-link" target="_blank">Markdown</a> in the docstring, it will be interpreted and displayed correctly (taking into account docstring indentation).

//// tab | Python 3.10+

```Python hl_lines="17-25"
{!> ../../docs_src/path_operation_configuration/tutorial004_py310.py!}
```

////

//// tab | Python 3.9+

```Python hl_lines="19-27"
{!> ../../docs_src/path_operation_configuration/tutorial004_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="19-27"
{!> ../../docs_src/path_operation_configuration/tutorial004.py!}
```

////
{* ../../docs_src/path_operation_configuration/tutorial004_py310.py hl[17:25] *}

It will be used in the interactive docs:

Expand All @@ -160,29 +70,7 @@ It will be used in the interactive docs:

You can specify the response description with the parameter `response_description`:

//// tab | Python 3.10+

```Python hl_lines="19"
{!> ../../docs_src/path_operation_configuration/tutorial005_py310.py!}
```

////

//// tab | Python 3.9+

```Python hl_lines="21"
{!> ../../docs_src/path_operation_configuration/tutorial005_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="21"
{!> ../../docs_src/path_operation_configuration/tutorial005.py!}
```

////
{* ../../docs_src/path_operation_configuration/tutorial005_py310.py hl[19] *}

/// info

Expand All @@ -204,9 +92,7 @@ So, if you don't provide one, **FastAPI** will automatically generate one of "Su

If you need to mark a *path operation* as <abbr title="obsolete, recommended not to use it">deprecated</abbr>, but without removing it, pass the parameter `deprecated`:

```Python hl_lines="16"
{!../../docs_src/path_operation_configuration/tutorial006.py!}
```
{* ../../docs_src/path_operation_configuration/tutorial006.py hl[16] *}

It will be clearly marked as deprecated in the interactive docs:

Expand Down