mirror of https://github.com/tiangolo/fastapi.git
📝 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:
parent
983f1d34db
commit
4d83f984cc
|
|
@ -116,19 +116,19 @@ You can of course also pass multiple `examples`:
|
|||
|
||||
=== "Python 3.10+"
|
||||
|
||||
```Python hl_lines="23-49"
|
||||
```Python hl_lines="23-38"
|
||||
{!> ../../../docs_src/schema_extra_example/tutorial004_an_py310.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.9+"
|
||||
|
||||
```Python hl_lines="23-49"
|
||||
```Python hl_lines="23-38"
|
||||
{!> ../../../docs_src/schema_extra_example/tutorial004_an_py39.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.6+"
|
||||
|
||||
```Python hl_lines="24-50"
|
||||
```Python hl_lines="24-39"
|
||||
{!> ../../../docs_src/schema_extra_example/tutorial004_an.py!}
|
||||
```
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ You can of course also pass multiple `examples`:
|
|||
!!! tip
|
||||
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!}
|
||||
```
|
||||
|
||||
|
|
@ -146,7 +146,7 @@ You can of course also pass multiple `examples`:
|
|||
!!! tip
|
||||
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!}
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -20,29 +20,18 @@ async def update_item(
|
|||
item: Item = Body(
|
||||
examples=[
|
||||
{
|
||||
"summary": "A normal example",
|
||||
"description": "A **normal** item works correctly.",
|
||||
"value": {
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
{
|
||||
"summary": "An example with converted data",
|
||||
"description": "FastAPI can convert price `strings` to actual `numbers` automatically",
|
||||
"value": {
|
||||
"name": "Bar",
|
||||
"price": "35.4",
|
||||
},
|
||||
"name": "Bar",
|
||||
"price": "35.4",
|
||||
},
|
||||
{
|
||||
"summary": "Invalid data is rejected with an error",
|
||||
"value": {
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -23,29 +23,18 @@ async def update_item(
|
|||
Body(
|
||||
examples=[
|
||||
{
|
||||
"summary": "A normal example",
|
||||
"description": "A **normal** item works correctly.",
|
||||
"value": {
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
{
|
||||
"summary": "An example with converted data",
|
||||
"description": "FastAPI can convert price `strings` to actual `numbers` automatically",
|
||||
"value": {
|
||||
"name": "Bar",
|
||||
"price": "35.4",
|
||||
},
|
||||
"name": "Bar",
|
||||
"price": "35.4",
|
||||
},
|
||||
{
|
||||
"summary": "Invalid data is rejected with an error",
|
||||
"value": {
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -22,29 +22,18 @@ async def update_item(
|
|||
Body(
|
||||
examples=[
|
||||
{
|
||||
"summary": "A normal example",
|
||||
"description": "A **normal** item works correctly.",
|
||||
"value": {
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
{
|
||||
"summary": "An example with converted data",
|
||||
"description": "FastAPI can convert price `strings` to actual `numbers` automatically",
|
||||
"value": {
|
||||
"name": "Bar",
|
||||
"price": "35.4",
|
||||
},
|
||||
"name": "Bar",
|
||||
"price": "35.4",
|
||||
},
|
||||
{
|
||||
"summary": "Invalid data is rejected with an error",
|
||||
"value": {
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -22,29 +22,18 @@ async def update_item(
|
|||
Body(
|
||||
examples=[
|
||||
{
|
||||
"summary": "A normal example",
|
||||
"description": "A **normal** item works correctly.",
|
||||
"value": {
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
{
|
||||
"summary": "An example with converted data",
|
||||
"description": "FastAPI can convert price `strings` to actual `numbers` automatically",
|
||||
"value": {
|
||||
"name": "Bar",
|
||||
"price": "35.4",
|
||||
},
|
||||
"name": "Bar",
|
||||
"price": "35.4",
|
||||
},
|
||||
{
|
||||
"summary": "Invalid data is rejected with an error",
|
||||
"value": {
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -18,29 +18,18 @@ async def update_item(
|
|||
item: Item = Body(
|
||||
examples=[
|
||||
{
|
||||
"summary": "A normal example",
|
||||
"description": "A **normal** item works correctly.",
|
||||
"value": {
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
{
|
||||
"summary": "An example with converted data",
|
||||
"description": "FastAPI can convert price `strings` to actual `numbers` automatically",
|
||||
"value": {
|
||||
"name": "Bar",
|
||||
"price": "35.4",
|
||||
},
|
||||
"name": "Bar",
|
||||
"price": "35.4",
|
||||
},
|
||||
{
|
||||
"summary": "Invalid data is rejected with an error",
|
||||
"value": {
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -46,26 +46,15 @@ def test_openapi_schema():
|
|||
"title": "Item",
|
||||
"examples": [
|
||||
{
|
||||
"summary": "A normal example",
|
||||
"description": "A **normal** item works correctly.",
|
||||
"value": {
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
{"name": "Bar", "price": "35.4"},
|
||||
{
|
||||
"summary": "An example with converted data",
|
||||
"description": "FastAPI can convert price `strings` to actual `numbers` automatically",
|
||||
"value": {"name": "Bar", "price": "35.4"},
|
||||
},
|
||||
{
|
||||
"summary": "Invalid data is rejected with an error",
|
||||
"value": {
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,26 +46,15 @@ def test_openapi_schema():
|
|||
"title": "Item",
|
||||
"examples": [
|
||||
{
|
||||
"summary": "A normal example",
|
||||
"description": "A **normal** item works correctly.",
|
||||
"value": {
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
{"name": "Bar", "price": "35.4"},
|
||||
{
|
||||
"summary": "An example with converted data",
|
||||
"description": "FastAPI can convert price `strings` to actual `numbers` automatically",
|
||||
"value": {"name": "Bar", "price": "35.4"},
|
||||
},
|
||||
{
|
||||
"summary": "Invalid data is rejected with an error",
|
||||
"value": {
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,26 +55,15 @@ def test_openapi_schema(client: TestClient):
|
|||
"title": "Item",
|
||||
"examples": [
|
||||
{
|
||||
"summary": "A normal example",
|
||||
"description": "A **normal** item works correctly.",
|
||||
"value": {
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
{"name": "Bar", "price": "35.4"},
|
||||
{
|
||||
"summary": "An example with converted data",
|
||||
"description": "FastAPI can convert price `strings` to actual `numbers` automatically",
|
||||
"value": {"name": "Bar", "price": "35.4"},
|
||||
},
|
||||
{
|
||||
"summary": "Invalid data is rejected with an error",
|
||||
"value": {
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,26 +55,15 @@ def test_openapi_schema(client: TestClient):
|
|||
"title": "Item",
|
||||
"examples": [
|
||||
{
|
||||
"summary": "A normal example",
|
||||
"description": "A **normal** item works correctly.",
|
||||
"value": {
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
{"name": "Bar", "price": "35.4"},
|
||||
{
|
||||
"summary": "An example with converted data",
|
||||
"description": "FastAPI can convert price `strings` to actual `numbers` automatically",
|
||||
"value": {"name": "Bar", "price": "35.4"},
|
||||
},
|
||||
{
|
||||
"summary": "Invalid data is rejected with an error",
|
||||
"value": {
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,26 +55,15 @@ def test_openapi_schema(client: TestClient):
|
|||
"title": "Item",
|
||||
"examples": [
|
||||
{
|
||||
"summary": "A normal example",
|
||||
"description": "A **normal** item works correctly.",
|
||||
"value": {
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
{"name": "Bar", "price": "35.4"},
|
||||
{
|
||||
"summary": "An example with converted data",
|
||||
"description": "FastAPI can convert price `strings` to actual `numbers` automatically",
|
||||
"value": {"name": "Bar", "price": "35.4"},
|
||||
},
|
||||
{
|
||||
"summary": "Invalid data is rejected with an error",
|
||||
"value": {
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
"name": "Baz",
|
||||
"price": "thirty five point four",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue