]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
📝 Update source examples to use new JSON Schema examples field (#9776)
authorSebastián Ramírez <tiangolo@gmail.com>
Sat, 1 Jul 2023 16:43:29 +0000 (18:43 +0200)
committerGitHub <noreply@github.com>
Sat, 1 Jul 2023 16:43:29 +0000 (18:43 +0200)
* 📝 Update source examples to use new JSON Schema examples field

* ✅ Update tests for JSON Schema examples

* 📝 Update highlights in JSON Schema examples

docs/en/docs/tutorial/schema-extra-example.md
docs_src/schema_extra_example/tutorial004.py
docs_src/schema_extra_example/tutorial004_an.py
docs_src/schema_extra_example/tutorial004_an_py310.py
docs_src/schema_extra_example/tutorial004_an_py39.py
docs_src/schema_extra_example/tutorial004_py310.py
tests/test_tutorial/test_schema_extra_example/test_tutorial004.py
tests/test_tutorial/test_schema_extra_example/test_tutorial004_an.py
tests/test_tutorial/test_schema_extra_example/test_tutorial004_an_py310.py
tests/test_tutorial/test_schema_extra_example/test_tutorial004_an_py39.py
tests/test_tutorial/test_schema_extra_example/test_tutorial004_py310.py

index 6cf8bf1813788e5f00c6074ae291c8adb28c800f..86ccb1f5adb1f89700f379082d81a97783ab631d 100644 (file)
@@ -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!}
     ```
 
index eb49293fd8e240acdc3566194c8733f8787e72af..75514a3e914ad1ad86ca904fba5b4e0cfd2a0738 100644 (file)
@@ -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",
             },
         ],
     ),
index 567ec4702430e76d251d19cc8927d9cf3deb8707..e817302a2240dda0c7fe4af77372092b4603f7fd 100644 (file)
@@ -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",
                 },
             ],
         ),
index 026654835633ff6bdeeaba8710bc328bc1dd2ca9..650da3187e8aed5cef37b57dee4c949753809cd1 100644 (file)
@@ -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",
                 },
             ],
         ),
index 06219ede8df8de5712bbd15b217bc51726cfcd24..dc5a8fe49c6f9d8849b867233866e16d5b2f9225 100644 (file)
@@ -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",
                 },
             ],
         ),
index ef2b9d8cb9276befff4e2da1f58a5d79414d1783..05996ac2a22256c131c47af780b0a94b0560bacf 100644 (file)
@@ -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",
             },
         ],
     ),
index dea136fb226c6b34064fc764b03c1781874465ef..313cd51d68d9a7e464d6a358200b2c3fdbaaadd1 100644 (file)
@@ -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",
                                         },
                                     ],
                                 }
index 571feb19f8965e336d1f8f9e80d9da492ce9eff3..353401b78eb2bc102ba789c2f689bcb3e8139509 100644 (file)
@@ -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",
                                         },
                                     ],
                                 }
index e25531794982b47d079231178486e4070b7fd365..79f4e1e1eb7801372c13dae57d4cb06f051aca61 100644 (file)
@@ -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",
                                         },
                                     ],
                                 }
index dafc5afade2cb8ce3371cb7de3ef0b4ba03960a4..1ee120705116e05dbf5de28a55de9d49cfc0c052 100644 (file)
@@ -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",
                                         },
                                     ],
                                 }
index 29004218bb38b11b608e7942a8f43f40b93c4d91..b7736840084313f7d90bee27933e633785bd9a92 100644 (file)
@@ -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",
                                         },
                                     ],
                                 }