📝 Update source examples to use new JSON Schema examples field (#9776)

* 📝 Update source examples to use new JSON Schema examples field

*  Update tests for JSON Schema examples

* 📝 Update highlights in JSON Schema examples
This commit is contained in:
Sebastián Ramírez 2023-07-01 18:43:29 +02:00 committed by GitHub
parent 983f1d34db
commit 4d83f984cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 80 additions and 190 deletions

View File

@ -116,19 +116,19 @@ You can of course also pass multiple `examples`:
=== "Python 3.10+" === "Python 3.10+"
```Python hl_lines="23-49" ```Python hl_lines="23-38"
{!> ../../../docs_src/schema_extra_example/tutorial004_an_py310.py!} {!> ../../../docs_src/schema_extra_example/tutorial004_an_py310.py!}
``` ```
=== "Python 3.9+" === "Python 3.9+"
```Python hl_lines="23-49" ```Python hl_lines="23-38"
{!> ../../../docs_src/schema_extra_example/tutorial004_an_py39.py!} {!> ../../../docs_src/schema_extra_example/tutorial004_an_py39.py!}
``` ```
=== "Python 3.6+" === "Python 3.6+"
```Python hl_lines="24-50" ```Python hl_lines="24-39"
{!> ../../../docs_src/schema_extra_example/tutorial004_an.py!} {!> ../../../docs_src/schema_extra_example/tutorial004_an.py!}
``` ```
@ -137,7 +137,7 @@ You can of course also pass multiple `examples`:
!!! tip !!! tip
Prefer to use the `Annotated` version if possible. Prefer to use the `Annotated` version if possible.
```Python hl_lines="19-45" ```Python hl_lines="19-34"
{!> ../../../docs_src/schema_extra_example/tutorial004_py310.py!} {!> ../../../docs_src/schema_extra_example/tutorial004_py310.py!}
``` ```
@ -146,7 +146,7 @@ You can of course also pass multiple `examples`:
!!! tip !!! tip
Prefer to use the `Annotated` version if possible. Prefer to use the `Annotated` version if possible.
```Python hl_lines="21-47" ```Python hl_lines="21-36"
{!> ../../../docs_src/schema_extra_example/tutorial004.py!} {!> ../../../docs_src/schema_extra_example/tutorial004.py!}
``` ```

View File

@ -20,29 +20,18 @@ async def update_item(
item: Item = Body( item: Item = Body(
examples=[ examples=[
{ {
"summary": "A normal example", "name": "Foo",
"description": "A **normal** item works correctly.", "description": "A very nice Item",
"value": { "price": 35.4,
"name": "Foo", "tax": 3.2,
"description": "A very nice Item",
"price": 35.4,
"tax": 3.2,
},
}, },
{ {
"summary": "An example with converted data", "name": "Bar",
"description": "FastAPI can convert price `strings` to actual `numbers` automatically", "price": "35.4",
"value": {
"name": "Bar",
"price": "35.4",
},
}, },
{ {
"summary": "Invalid data is rejected with an error", "name": "Baz",
"value": { "price": "thirty five point four",
"name": "Baz",
"price": "thirty five point four",
},
}, },
], ],
), ),

View File

@ -23,29 +23,18 @@ async def update_item(
Body( Body(
examples=[ examples=[
{ {
"summary": "A normal example", "name": "Foo",
"description": "A **normal** item works correctly.", "description": "A very nice Item",
"value": { "price": 35.4,
"name": "Foo", "tax": 3.2,
"description": "A very nice Item",
"price": 35.4,
"tax": 3.2,
},
}, },
{ {
"summary": "An example with converted data", "name": "Bar",
"description": "FastAPI can convert price `strings` to actual `numbers` automatically", "price": "35.4",
"value": {
"name": "Bar",
"price": "35.4",
},
}, },
{ {
"summary": "Invalid data is rejected with an error", "name": "Baz",
"value": { "price": "thirty five point four",
"name": "Baz",
"price": "thirty five point four",
},
}, },
], ],
), ),

View File

@ -22,29 +22,18 @@ async def update_item(
Body( Body(
examples=[ examples=[
{ {
"summary": "A normal example", "name": "Foo",
"description": "A **normal** item works correctly.", "description": "A very nice Item",
"value": { "price": 35.4,
"name": "Foo", "tax": 3.2,
"description": "A very nice Item",
"price": 35.4,
"tax": 3.2,
},
}, },
{ {
"summary": "An example with converted data", "name": "Bar",
"description": "FastAPI can convert price `strings` to actual `numbers` automatically", "price": "35.4",
"value": {
"name": "Bar",
"price": "35.4",
},
}, },
{ {
"summary": "Invalid data is rejected with an error", "name": "Baz",
"value": { "price": "thirty five point four",
"name": "Baz",
"price": "thirty five point four",
},
}, },
], ],
), ),

View File

@ -22,29 +22,18 @@ async def update_item(
Body( Body(
examples=[ examples=[
{ {
"summary": "A normal example", "name": "Foo",
"description": "A **normal** item works correctly.", "description": "A very nice Item",
"value": { "price": 35.4,
"name": "Foo", "tax": 3.2,
"description": "A very nice Item",
"price": 35.4,
"tax": 3.2,
},
}, },
{ {
"summary": "An example with converted data", "name": "Bar",
"description": "FastAPI can convert price `strings` to actual `numbers` automatically", "price": "35.4",
"value": {
"name": "Bar",
"price": "35.4",
},
}, },
{ {
"summary": "Invalid data is rejected with an error", "name": "Baz",
"value": { "price": "thirty five point four",
"name": "Baz",
"price": "thirty five point four",
},
}, },
], ],
), ),

View File

@ -18,29 +18,18 @@ async def update_item(
item: Item = Body( item: Item = Body(
examples=[ examples=[
{ {
"summary": "A normal example", "name": "Foo",
"description": "A **normal** item works correctly.", "description": "A very nice Item",
"value": { "price": 35.4,
"name": "Foo", "tax": 3.2,
"description": "A very nice Item",
"price": 35.4,
"tax": 3.2,
},
}, },
{ {
"summary": "An example with converted data", "name": "Bar",
"description": "FastAPI can convert price `strings` to actual `numbers` automatically", "price": "35.4",
"value": {
"name": "Bar",
"price": "35.4",
},
}, },
{ {
"summary": "Invalid data is rejected with an error", "name": "Baz",
"value": { "price": "thirty five point four",
"name": "Baz",
"price": "thirty five point four",
},
}, },
], ],
), ),

View File

@ -46,26 +46,15 @@ def test_openapi_schema():
"title": "Item", "title": "Item",
"examples": [ "examples": [
{ {
"summary": "A normal example", "name": "Foo",
"description": "A **normal** item works correctly.", "description": "A very nice Item",
"value": { "price": 35.4,
"name": "Foo", "tax": 3.2,
"description": "A very nice Item",
"price": 35.4,
"tax": 3.2,
},
}, },
{"name": "Bar", "price": "35.4"},
{ {
"summary": "An example with converted data", "name": "Baz",
"description": "FastAPI can convert price `strings` to actual `numbers` automatically", "price": "thirty five point four",
"value": {"name": "Bar", "price": "35.4"},
},
{
"summary": "Invalid data is rejected with an error",
"value": {
"name": "Baz",
"price": "thirty five point four",
},
}, },
], ],
} }

View File

@ -46,26 +46,15 @@ def test_openapi_schema():
"title": "Item", "title": "Item",
"examples": [ "examples": [
{ {
"summary": "A normal example", "name": "Foo",
"description": "A **normal** item works correctly.", "description": "A very nice Item",
"value": { "price": 35.4,
"name": "Foo", "tax": 3.2,
"description": "A very nice Item",
"price": 35.4,
"tax": 3.2,
},
}, },
{"name": "Bar", "price": "35.4"},
{ {
"summary": "An example with converted data", "name": "Baz",
"description": "FastAPI can convert price `strings` to actual `numbers` automatically", "price": "thirty five point four",
"value": {"name": "Bar", "price": "35.4"},
},
{
"summary": "Invalid data is rejected with an error",
"value": {
"name": "Baz",
"price": "thirty five point four",
},
}, },
], ],
} }

View File

@ -55,26 +55,15 @@ def test_openapi_schema(client: TestClient):
"title": "Item", "title": "Item",
"examples": [ "examples": [
{ {
"summary": "A normal example", "name": "Foo",
"description": "A **normal** item works correctly.", "description": "A very nice Item",
"value": { "price": 35.4,
"name": "Foo", "tax": 3.2,
"description": "A very nice Item",
"price": 35.4,
"tax": 3.2,
},
}, },
{"name": "Bar", "price": "35.4"},
{ {
"summary": "An example with converted data", "name": "Baz",
"description": "FastAPI can convert price `strings` to actual `numbers` automatically", "price": "thirty five point four",
"value": {"name": "Bar", "price": "35.4"},
},
{
"summary": "Invalid data is rejected with an error",
"value": {
"name": "Baz",
"price": "thirty five point four",
},
}, },
], ],
} }

View File

@ -55,26 +55,15 @@ def test_openapi_schema(client: TestClient):
"title": "Item", "title": "Item",
"examples": [ "examples": [
{ {
"summary": "A normal example", "name": "Foo",
"description": "A **normal** item works correctly.", "description": "A very nice Item",
"value": { "price": 35.4,
"name": "Foo", "tax": 3.2,
"description": "A very nice Item",
"price": 35.4,
"tax": 3.2,
},
}, },
{"name": "Bar", "price": "35.4"},
{ {
"summary": "An example with converted data", "name": "Baz",
"description": "FastAPI can convert price `strings` to actual `numbers` automatically", "price": "thirty five point four",
"value": {"name": "Bar", "price": "35.4"},
},
{
"summary": "Invalid data is rejected with an error",
"value": {
"name": "Baz",
"price": "thirty five point four",
},
}, },
], ],
} }

View File

@ -55,26 +55,15 @@ def test_openapi_schema(client: TestClient):
"title": "Item", "title": "Item",
"examples": [ "examples": [
{ {
"summary": "A normal example", "name": "Foo",
"description": "A **normal** item works correctly.", "description": "A very nice Item",
"value": { "price": 35.4,
"name": "Foo", "tax": 3.2,
"description": "A very nice Item",
"price": 35.4,
"tax": 3.2,
},
}, },
{"name": "Bar", "price": "35.4"},
{ {
"summary": "An example with converted data", "name": "Baz",
"description": "FastAPI can convert price `strings` to actual `numbers` automatically", "price": "thirty five point four",
"value": {"name": "Bar", "price": "35.4"},
},
{
"summary": "Invalid data is rejected with an error",
"value": {
"name": "Baz",
"price": "thirty five point four",
},
}, },
], ],
} }