Skip to content

Commit

Permalink
🎨 Simplify docs hl_lines ranges and standardize 2 spaces between each…
Browse files Browse the repository at this point in the history
… range (fastapi#1863)
  • Loading branch information
la-mar authored Aug 29, 2020
1 parent dfdd371 commit be66905
Show file tree
Hide file tree
Showing 79 changed files with 232 additions and 232 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def read_item(item_id: int, q: Optional[str] = None):

If your code uses `async` / `await`, use `async def`:

```Python hl_lines="9 14"
```Python hl_lines="9 14"
from typing import Optional

from fastapi import FastAPI
Expand Down Expand Up @@ -245,7 +245,7 @@ Now modify the file `main.py` to receive a body from a `PUT` request.

Declare the body using standard Python types, thanks to Pydantic.

```Python hl_lines="4 9 10 11 12 25 26 27"
```Python hl_lines="4 9-12 25-27"
from typing import Optional

from fastapi import FastAPI
Expand Down
12 changes: 6 additions & 6 deletions docs/en/docs/advanced/additional-responses.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Each of those response `dict`s can have a key `model`, containing a Pydantic mod

For example, to declare another response with a status code `404` and a Pydantic model `Message`, you can write:

```Python hl_lines="18 23"
```Python hl_lines="18 23"
{!../../../docs_src/additional_responses/tutorial001.py!}
```

Expand All @@ -44,7 +44,7 @@ For example, to declare another response with a status code `404` and a Pydantic

The generated responses in the OpenAPI for this *path operation* will be:

```JSON hl_lines="3 4 5 6 7 8 9 10 11 12"
```JSON hl_lines="3-12"
{
"responses": {
"404": {
Expand Down Expand Up @@ -83,7 +83,7 @@ The generated responses in the OpenAPI for this *path operation* will be:

The schemas are referenced to another place inside the OpenAPI schema:

```JSON hl_lines="4 5 6 7 8 9 10 11 12 13 14 15 16"
```JSON hl_lines="4-16"
{
"components": {
"schemas": {
Expand Down Expand Up @@ -168,7 +168,7 @@ You can use this same `responses` parameter to add different media types for the

For example, you can add an additional media type of `image/png`, declaring that your *path operation* can return a JSON object (with media type `application/json`) or a PNG image:

```Python hl_lines="19 20 21 22 23 24 28"
```Python hl_lines="19-24 28"
{!../../../docs_src/additional_responses/tutorial002.py!}
```

Expand All @@ -192,7 +192,7 @@ For example, you can declare a response with a status code `404` that uses a Pyd

And a response with a status code `200` that uses your `response_model`, but includes a custom `example`:

```Python hl_lines="20 21 22 23 24 25 26 27 28 29 30 31"
```Python hl_lines="20-31"
{!../../../docs_src/additional_responses/tutorial003.py!}
```

Expand Down Expand Up @@ -228,7 +228,7 @@ You can use that technique to re-use some predefined responses in your *path ope

For example:

```Python hl_lines="13 14 15 16 17 26"
```Python hl_lines="13-17 26"
{!../../../docs_src/additional_responses/tutorial004.py!}
```

Expand Down
14 changes: 7 additions & 7 deletions docs/en/docs/advanced/async-sql-databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Later, for your production application, you might want to use a database server
* Create a `metadata` object.
* Create a table `notes` using the `metadata` object.

```Python hl_lines="4 14 16 17 18 19 20 21 22"
```Python hl_lines="4 14 16-22"
{!../../../docs_src/async_sql_databases/tutorial001.py!}
```

Expand All @@ -38,7 +38,7 @@ Later, for your production application, you might want to use a database server
* Create a `DATABASE_URL`.
* Create a `database` object.

```Python hl_lines="3 9 12"
```Python hl_lines="3 9 12"
{!../../../docs_src/async_sql_databases/tutorial001.py!}
```

Expand All @@ -54,7 +54,7 @@ Here, this section would run directly, right before starting your **FastAPI** ap
* Create an `engine`.
* Create all the tables from the `metadata` object.

```Python hl_lines="25 26 27 28"
```Python hl_lines="25-28"
{!../../../docs_src/async_sql_databases/tutorial001.py!}
```

Expand All @@ -65,7 +65,7 @@ Create Pydantic models for:
* Notes to be created (`NoteIn`).
* Notes to be returned (`Note`).

```Python hl_lines="31 32 33 36 37 38 39"
```Python hl_lines="31-33 36-39"
{!../../../docs_src/async_sql_databases/tutorial001.py!}
```

Expand All @@ -78,15 +78,15 @@ So, you will be able to see it all in the interactive API docs.
* Create your `FastAPI` application.
* Create event handlers to connect and disconnect from the database.

```Python hl_lines="42 45 46 47 50 51 52"
```Python hl_lines="42 45-47 50-52"
{!../../../docs_src/async_sql_databases/tutorial001.py!}
```

## Read notes

Create the *path operation function* to read notes:

```Python hl_lines="55 56 57 58"
```Python hl_lines="55-58"
{!../../../docs_src/async_sql_databases/tutorial001.py!}
```

Expand All @@ -103,7 +103,7 @@ That documents (and validates, serializes, filters) the output data, as a `list`

Create the *path operation function* to create notes:

```Python hl_lines="61 62 63 64 65"
```Python hl_lines="61-65"
{!../../../docs_src/async_sql_databases/tutorial001.py!}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/en/docs/advanced/async-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ The marker `@pytest.mark.asyncio` tells pytest that this test function should be

Then we can create an `AsyncClient` with the app, and send async requests to it, using `await`.

```Python hl_lines="9 10"
```Python hl_lines="9-10"
{!../../../docs_src/async_tests/test_main.py!}
```

Expand Down
6 changes: 3 additions & 3 deletions docs/en/docs/advanced/behind-a-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ proxy --> server

The docs UI would also need the OpenAPI schema to declare that this API `server` is located at `/api/v1` (behind the proxy). For example:

```JSON hl_lines="4 5 6 7 8"
```JSON hl_lines="4-8"
{
"openapi": "3.0.2",
// More stuff here
Expand Down Expand Up @@ -290,13 +290,13 @@ If you pass a custom list of `servers` and there's a `root_path` (because your A

For example:

```Python hl_lines="4 5 6 7"
```Python hl_lines="4-7"
{!../../../docs_src/behind_a_proxy/tutorial003.py!}
```

Will generate an OpenAPI schema like:

```JSON hl_lines="5 6 7"
```JSON hl_lines="5-7"
{
"openapi": "3.0.2",
// More stuff here
Expand Down
10 changes: 5 additions & 5 deletions docs/en/docs/advanced/custom-request-and-route.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ If there's no `gzip` in the header, it will not try to decompress the body.

That way, the same route class can handle gzip compressed or uncompressed requests.

```Python hl_lines="8 9 10 11 12 13 14 15"
```Python hl_lines="8-15"
{!../../../docs_src/custom_request_and_route/tutorial001.py!}
```

Expand All @@ -50,7 +50,7 @@ This method returns a function. And that function is what will receive a request

Here we use it to create a `GzipRequest` from the original request.

```Python hl_lines="18 19 20 21 22 23 24 25 26"
```Python hl_lines="18-26"
{!../../../docs_src/custom_request_and_route/tutorial001.py!}
```

Expand Down Expand Up @@ -84,13 +84,13 @@ We can also use this same approach to access the request body in an exception ha

All we need to do is handle the request inside a `try`/`except` block:

```Python hl_lines="13 15"
```Python hl_lines="13 15"
{!../../../docs_src/custom_request_and_route/tutorial002.py!}
```

If an exception occurs, the`Request` instance will still be in scope, so we can read and make use of the request body when handling the error:

```Python hl_lines="16 17 18"
```Python hl_lines="16-18"
{!../../../docs_src/custom_request_and_route/tutorial002.py!}
```

Expand All @@ -104,6 +104,6 @@ You can also set the `route_class` parameter of an `APIRouter`:

In this example, the *path operations* under the `router` will use the custom `TimedRoute` class, and will have an extra `X-Response-Time` header in the response with the time it took to generate the response:

```Python hl_lines="13 14 15 16 17 18 19 20"
```Python hl_lines="13-20"
{!../../../docs_src/custom_request_and_route/tutorial003.py!}
```
14 changes: 7 additions & 7 deletions docs/en/docs/advanced/custom-response.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ For example, if you are squeezing performance, you can install and use <a href="

Import the `Response` class (sub-class) you want to use and declare it in the *path operation decorator*.

```Python hl_lines="2 7"
```Python hl_lines="2 7"
{!../../../docs_src/custom_response/tutorial001b.py!}
```

Expand All @@ -42,7 +42,7 @@ To return a response with HTML directly from **FastAPI**, use `HTMLResponse`.
* Import `HTMLResponse`.
* Pass `HTMLResponse` as the parameter `content_type` of your *path operation*.

```Python hl_lines="2 7"
```Python hl_lines="2 7"
{!../../../docs_src/custom_response/tutorial002.py!}
```

Expand All @@ -59,7 +59,7 @@ As seen in [Return a Response directly](response-directly.md){.internal-link tar

The same example from above, returning an `HTMLResponse`, could look like:

```Python hl_lines="2 7 19"
```Python hl_lines="2 7 19"
{!../../../docs_src/custom_response/tutorial003.py!}
```

Expand All @@ -79,7 +79,7 @@ The `response_class` will then be used only to document the OpenAPI *path operat

For example, it could be something like:

```Python hl_lines="7 23 21"
```Python hl_lines="7 21 23"
{!../../../docs_src/custom_response/tutorial004.py!}
```

Expand Down Expand Up @@ -150,7 +150,7 @@ An alternative JSON response using <a href="https://github.com/ultrajson/ultrajs
!!! warning
`ujson` is less careful than Python's built-in implementation in how it handles some edge-cases.

```Python hl_lines="2 7"
```Python hl_lines="2 7"
{!../../../docs_src/custom_response/tutorial001.py!}
```

Expand Down Expand Up @@ -179,7 +179,7 @@ If you have a file-like object (e.g. the object returned by `open()`), you can r

This includes many libraries to interact with cloud storage, video processing, and others.

```Python hl_lines="2 10 11"
```Python hl_lines="2 10-11"
{!../../../docs_src/custom_response/tutorial008.py!}
```

Expand Down Expand Up @@ -211,7 +211,7 @@ The parameter that defines this is `default_response_class`.

In the example below, **FastAPI** will use `ORJSONResponse` by default, in all *path operations*, instead of `JSONResponse`.

```Python hl_lines="2 4"
```Python hl_lines="2 4"
{!../../../docs_src/custom_response/tutorial010.py!}
```

Expand Down
14 changes: 7 additions & 7 deletions docs/en/docs/advanced/extending-openapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ 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 8 9"
```Python hl_lines="1 4 7-9"
{!../../../docs_src/extending_openapi/tutorial001.py!}
```

### 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 16 17 18 19 20"
```Python hl_lines="2 15-20"
{!../../../docs_src/extending_openapi/tutorial001.py!}
```

### 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="21 22 23"
```Python hl_lines="21-23"
{!../../../docs_src/extending_openapi/tutorial001.py!}
```

Expand All @@ -71,7 +71,7 @@ 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 24 25"
```Python hl_lines="13-14 24-25"
{!../../../docs_src/extending_openapi/tutorial001.py!}
```

Expand Down Expand Up @@ -172,7 +172,7 @@ $ pip install aiofiles
* Import `StaticFiles`.
* "Mount" a `StaticFiles()` instance in a specific path.

```Python hl_lines="7 11"
```Python hl_lines="7 11"
{!../../../docs_src/extending_openapi/tutorial002.py!}
```

Expand Down Expand Up @@ -224,7 +224,7 @@ You can re-use FastAPI's internal functions to create the HTML pages for the doc
And similarly for ReDoc...
```Python hl_lines="2 3 4 5 6 14 15 16 17 18 19 20 21 22 25 26 27 30 31 32 33 34 35 36"
```Python hl_lines="2-6 14-22 25-27 30-36"
{!../../../docs_src/extending_openapi/tutorial002.py!}
```
Expand All @@ -239,7 +239,7 @@ And similarly for ReDoc...
Now, to be able to test that everything works, create a *path operation*:
```Python hl_lines="39 40 41"
```Python hl_lines="39-41"
{!../../../docs_src/extending_openapi/tutorial002.py!}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/en/docs/advanced/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ GraphQL is implemented with Graphene, you can check <a href="https://docs.graphe

Import `graphene` and define your GraphQL data:

```Python hl_lines="1 6 7 8 9 10"
```Python hl_lines="1 6-10"
{!../../../docs_src/graphql/tutorial001.py!}
```

## Add Starlette's `GraphQLApp`

Then import and add Starlette's `GraphQLApp`:

```Python hl_lines="3 14"
```Python hl_lines="3 14"
{!../../../docs_src/graphql/tutorial001.py!}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/en/docs/advanced/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Any incoming requests to `http` or `ws` will be redirected to the secure scheme

Enforces that all incoming requests have a correctly set `Host` header, in order to guard against HTTP Host Header attacks.

```Python hl_lines="2 6 7 8"
```Python hl_lines="2 6-8"
{!../../../docs_src/advanced_middleware/tutorial002.py!}
```

Expand Down
Loading

0 comments on commit be66905

Please sign in to comment.