]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
📝 Fix types in examples under `docs_src/extra_data_types` (#10535)
authorNils Lindemann <nilslindemann@tutanota.com>
Fri, 19 Apr 2024 00:11:40 +0000 (02:11 +0200)
committerGitHub <noreply@github.com>
Fri, 19 Apr 2024 00:11:40 +0000 (19:11 -0500)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
docs_src/extra_data_types/tutorial001.py
docs_src/extra_data_types/tutorial001_an.py
docs_src/extra_data_types/tutorial001_an_py310.py
docs_src/extra_data_types/tutorial001_an_py39.py
docs_src/extra_data_types/tutorial001_py310.py
tests/test_tutorial/test_extra_data_types/test_tutorial001.py
tests/test_tutorial/test_extra_data_types/test_tutorial001_an.py
tests/test_tutorial/test_extra_data_types/test_tutorial001_an_py310.py
tests/test_tutorial/test_extra_data_types/test_tutorial001_an_py39.py
tests/test_tutorial/test_extra_data_types/test_tutorial001_py310.py

index 8ae8472a7069558fcf8e0e5d8bb367bde3b235d5..71de958ff564ed63e8144400587b6d872bb391f2 100644 (file)
@@ -10,10 +10,10 @@ app = FastAPI()
 @app.put("/items/{item_id}")
 async def read_items(
     item_id: UUID,
-    start_datetime: Union[datetime, None] = Body(default=None),
-    end_datetime: Union[datetime, None] = Body(default=None),
+    start_datetime: datetime = Body(),
+    end_datetime: datetime = Body(),
+    process_after: timedelta = Body(),
     repeat_at: Union[time, None] = Body(default=None),
-    process_after: Union[timedelta, None] = Body(default=None),
 ):
     start_process = start_datetime + process_after
     duration = end_datetime - start_process
@@ -21,8 +21,8 @@ async def read_items(
         "item_id": item_id,
         "start_datetime": start_datetime,
         "end_datetime": end_datetime,
-        "repeat_at": repeat_at,
         "process_after": process_after,
+        "repeat_at": repeat_at,
         "start_process": start_process,
         "duration": duration,
     }
index a4c074241a7b75e5852bb27e5cf9d0afa71c78e7..257d0c7c862e1c9adabe6fea2d696662a547446d 100644 (file)
@@ -11,10 +11,10 @@ app = FastAPI()
 @app.put("/items/{item_id}")
 async def read_items(
     item_id: UUID,
-    start_datetime: Annotated[Union[datetime, None], Body()] = None,
-    end_datetime: Annotated[Union[datetime, None], Body()] = None,
+    start_datetime: Annotated[datetime, Body()],
+    end_datetime: Annotated[datetime, Body()],
+    process_after: Annotated[timedelta, Body()],
     repeat_at: Annotated[Union[time, None], Body()] = None,
-    process_after: Annotated[Union[timedelta, None], Body()] = None,
 ):
     start_process = start_datetime + process_after
     duration = end_datetime - start_process
@@ -22,8 +22,8 @@ async def read_items(
         "item_id": item_id,
         "start_datetime": start_datetime,
         "end_datetime": end_datetime,
-        "repeat_at": repeat_at,
         "process_after": process_after,
+        "repeat_at": repeat_at,
         "start_process": start_process,
         "duration": duration,
     }
index 4f69c40d950270a6577c1ec10b2cfbeb8f3b9f0d..668bf19090d4eb6efa8f9892618561a12c39e8cb 100644 (file)
@@ -10,10 +10,10 @@ app = FastAPI()
 @app.put("/items/{item_id}")
 async def read_items(
     item_id: UUID,
-    start_datetime: Annotated[datetime | None, Body()] = None,
-    end_datetime: Annotated[datetime | None, Body()] = None,
+    start_datetime: Annotated[datetime, Body()],
+    end_datetime: Annotated[datetime, Body()],
+    process_after: Annotated[timedelta, Body()],
     repeat_at: Annotated[time | None, Body()] = None,
-    process_after: Annotated[timedelta | None, Body()] = None,
 ):
     start_process = start_datetime + process_after
     duration = end_datetime - start_process
@@ -21,8 +21,8 @@ async def read_items(
         "item_id": item_id,
         "start_datetime": start_datetime,
         "end_datetime": end_datetime,
-        "repeat_at": repeat_at,
         "process_after": process_after,
+        "repeat_at": repeat_at,
         "start_process": start_process,
         "duration": duration,
     }
index 630d36ae31ee4c1c39230d1f10164ff6d796f722..fa3551d6659c10228216ce87dc2373f39cbac0a0 100644 (file)
@@ -10,10 +10,10 @@ app = FastAPI()
 @app.put("/items/{item_id}")
 async def read_items(
     item_id: UUID,
-    start_datetime: Annotated[Union[datetime, None], Body()] = None,
-    end_datetime: Annotated[Union[datetime, None], Body()] = None,
+    start_datetime: Annotated[datetime, Body()],
+    end_datetime: Annotated[datetime, Body()],
+    process_after: Annotated[timedelta, Body()],
     repeat_at: Annotated[Union[time, None], Body()] = None,
-    process_after: Annotated[Union[timedelta, None], Body()] = None,
 ):
     start_process = start_datetime + process_after
     duration = end_datetime - start_process
@@ -21,8 +21,8 @@ async def read_items(
         "item_id": item_id,
         "start_datetime": start_datetime,
         "end_datetime": end_datetime,
-        "repeat_at": repeat_at,
         "process_after": process_after,
+        "repeat_at": repeat_at,
         "start_process": start_process,
         "duration": duration,
     }
index d22f818886d9d078b216388871c01042cfcc230b..a275a05776946f66079560735683ee9bda8f68fe 100644 (file)
@@ -9,10 +9,10 @@ app = FastAPI()
 @app.put("/items/{item_id}")
 async def read_items(
     item_id: UUID,
-    start_datetime: datetime | None = Body(default=None),
-    end_datetime: datetime | None = Body(default=None),
+    start_datetime: datetime = Body(),
+    end_datetime: datetime = Body(),
+    process_after: timedelta = Body(),
     repeat_at: time | None = Body(default=None),
-    process_after: timedelta | None = Body(default=None),
 ):
     start_process = start_datetime + process_after
     duration = end_datetime - start_process
@@ -20,8 +20,8 @@ async def read_items(
         "item_id": item_id,
         "start_datetime": start_datetime,
         "end_datetime": end_datetime,
-        "repeat_at": repeat_at,
         "process_after": process_after,
+        "repeat_at": repeat_at,
         "start_process": start_process,
         "duration": duration,
     }
index 7710446ce34d9158b060b924aaa19b71b7c92b06..5558671b919b54b861ddf7e3bd7a014f4da21587 100644 (file)
@@ -67,6 +67,7 @@ def test_openapi_schema():
                         }
                     ],
                     "requestBody": {
+                        "required": True,
                         "content": {
                             "application/json": {
                                 "schema": IsDict(
@@ -86,7 +87,7 @@ def test_openapi_schema():
                                     }
                                 )
                             }
-                        }
+                        },
                     },
                 }
             }
@@ -97,40 +98,16 @@ def test_openapi_schema():
                     "title": "Body_read_items_items__item_id__put",
                     "type": "object",
                     "properties": {
-                        "start_datetime": IsDict(
-                            {
-                                "title": "Start Datetime",
-                                "anyOf": [
-                                    {"type": "string", "format": "date-time"},
-                                    {"type": "null"},
-                                ],
-                            }
-                        )
-                        | IsDict(
-                            # TODO: remove when deprecating Pydantic v1
-                            {
-                                "title": "Start Datetime",
-                                "type": "string",
-                                "format": "date-time",
-                            }
-                        ),
-                        "end_datetime": IsDict(
-                            {
-                                "title": "End Datetime",
-                                "anyOf": [
-                                    {"type": "string", "format": "date-time"},
-                                    {"type": "null"},
-                                ],
-                            }
-                        )
-                        | IsDict(
-                            # TODO: remove when deprecating Pydantic v1
-                            {
-                                "title": "End Datetime",
-                                "type": "string",
-                                "format": "date-time",
-                            }
-                        ),
+                        "start_datetime": {
+                            "title": "Start Datetime",
+                            "type": "string",
+                            "format": "date-time",
+                        },
+                        "end_datetime": {
+                            "title": "End Datetime",
+                            "type": "string",
+                            "format": "date-time",
+                        },
                         "repeat_at": IsDict(
                             {
                                 "title": "Repeat At",
@@ -151,10 +128,8 @@ def test_openapi_schema():
                         "process_after": IsDict(
                             {
                                 "title": "Process After",
-                                "anyOf": [
-                                    {"type": "string", "format": "duration"},
-                                    {"type": "null"},
-                                ],
+                                "type": "string",
+                                "format": "duration",
                             }
                         )
                         | IsDict(
@@ -166,6 +141,7 @@ def test_openapi_schema():
                             }
                         ),
                     },
+                    "required": ["start_datetime", "end_datetime", "process_after"],
                 },
                 "ValidationError": {
                     "title": "ValidationError",
index 9951b3b51173a3d8db76c46e79b1ef019a10e3e0..e309f8bd6bbe41f065de4118b6791766da6ae42a 100644 (file)
@@ -67,6 +67,7 @@ def test_openapi_schema():
                         }
                     ],
                     "requestBody": {
+                        "required": True,
                         "content": {
                             "application/json": {
                                 "schema": IsDict(
@@ -86,7 +87,7 @@ def test_openapi_schema():
                                     }
                                 )
                             }
-                        }
+                        },
                     },
                 }
             }
@@ -97,40 +98,16 @@ def test_openapi_schema():
                     "title": "Body_read_items_items__item_id__put",
                     "type": "object",
                     "properties": {
-                        "start_datetime": IsDict(
-                            {
-                                "title": "Start Datetime",
-                                "anyOf": [
-                                    {"type": "string", "format": "date-time"},
-                                    {"type": "null"},
-                                ],
-                            }
-                        )
-                        | IsDict(
-                            # TODO: remove when deprecating Pydantic v1
-                            {
-                                "title": "Start Datetime",
-                                "type": "string",
-                                "format": "date-time",
-                            }
-                        ),
-                        "end_datetime": IsDict(
-                            {
-                                "title": "End Datetime",
-                                "anyOf": [
-                                    {"type": "string", "format": "date-time"},
-                                    {"type": "null"},
-                                ],
-                            }
-                        )
-                        | IsDict(
-                            # TODO: remove when deprecating Pydantic v1
-                            {
-                                "title": "End Datetime",
-                                "type": "string",
-                                "format": "date-time",
-                            }
-                        ),
+                        "start_datetime": {
+                            "title": "Start Datetime",
+                            "type": "string",
+                            "format": "date-time",
+                        },
+                        "end_datetime": {
+                            "title": "End Datetime",
+                            "type": "string",
+                            "format": "date-time",
+                        },
                         "repeat_at": IsDict(
                             {
                                 "title": "Repeat At",
@@ -151,10 +128,8 @@ def test_openapi_schema():
                         "process_after": IsDict(
                             {
                                 "title": "Process After",
-                                "anyOf": [
-                                    {"type": "string", "format": "duration"},
-                                    {"type": "null"},
-                                ],
+                                "type": "string",
+                                "format": "duration",
                             }
                         )
                         | IsDict(
@@ -166,6 +141,7 @@ def test_openapi_schema():
                             }
                         ),
                     },
+                    "required": ["start_datetime", "end_datetime", "process_after"],
                 },
                 "ValidationError": {
                     "title": "ValidationError",
index 7c482b8cb2384c8d0241b066e9a33224d17746f7..ca110dc00d9d82f82d7c8b9f644f0f663ecefa80 100644 (file)
@@ -76,6 +76,7 @@ def test_openapi_schema(client: TestClient):
                         }
                     ],
                     "requestBody": {
+                        "required": True,
                         "content": {
                             "application/json": {
                                 "schema": IsDict(
@@ -95,7 +96,7 @@ def test_openapi_schema(client: TestClient):
                                     }
                                 )
                             }
-                        }
+                        },
                     },
                 }
             }
@@ -106,40 +107,16 @@ def test_openapi_schema(client: TestClient):
                     "title": "Body_read_items_items__item_id__put",
                     "type": "object",
                     "properties": {
-                        "start_datetime": IsDict(
-                            {
-                                "title": "Start Datetime",
-                                "anyOf": [
-                                    {"type": "string", "format": "date-time"},
-                                    {"type": "null"},
-                                ],
-                            }
-                        )
-                        | IsDict(
-                            # TODO: remove when deprecating Pydantic v1
-                            {
-                                "title": "Start Datetime",
-                                "type": "string",
-                                "format": "date-time",
-                            }
-                        ),
-                        "end_datetime": IsDict(
-                            {
-                                "title": "End Datetime",
-                                "anyOf": [
-                                    {"type": "string", "format": "date-time"},
-                                    {"type": "null"},
-                                ],
-                            }
-                        )
-                        | IsDict(
-                            # TODO: remove when deprecating Pydantic v1
-                            {
-                                "title": "End Datetime",
-                                "type": "string",
-                                "format": "date-time",
-                            }
-                        ),
+                        "start_datetime": {
+                            "title": "Start Datetime",
+                            "type": "string",
+                            "format": "date-time",
+                        },
+                        "end_datetime": {
+                            "title": "End Datetime",
+                            "type": "string",
+                            "format": "date-time",
+                        },
                         "repeat_at": IsDict(
                             {
                                 "title": "Repeat At",
@@ -160,10 +137,8 @@ def test_openapi_schema(client: TestClient):
                         "process_after": IsDict(
                             {
                                 "title": "Process After",
-                                "anyOf": [
-                                    {"type": "string", "format": "duration"},
-                                    {"type": "null"},
-                                ],
+                                "type": "string",
+                                "format": "duration",
                             }
                         )
                         | IsDict(
@@ -175,6 +150,7 @@ def test_openapi_schema(client: TestClient):
                             }
                         ),
                     },
+                    "required": ["start_datetime", "end_datetime", "process_after"],
                 },
                 "ValidationError": {
                     "title": "ValidationError",
index 87473867b02fcf2efdb61150265037de2d811cf3..3386fb1fd84bb529e173c29d02bd0893c1de08cb 100644 (file)
@@ -76,6 +76,7 @@ def test_openapi_schema(client: TestClient):
                         }
                     ],
                     "requestBody": {
+                        "required": True,
                         "content": {
                             "application/json": {
                                 "schema": IsDict(
@@ -95,7 +96,7 @@ def test_openapi_schema(client: TestClient):
                                     }
                                 )
                             }
-                        }
+                        },
                     },
                 }
             }
@@ -106,40 +107,16 @@ def test_openapi_schema(client: TestClient):
                     "title": "Body_read_items_items__item_id__put",
                     "type": "object",
                     "properties": {
-                        "start_datetime": IsDict(
-                            {
-                                "title": "Start Datetime",
-                                "anyOf": [
-                                    {"type": "string", "format": "date-time"},
-                                    {"type": "null"},
-                                ],
-                            }
-                        )
-                        | IsDict(
-                            # TODO: remove when deprecating Pydantic v1
-                            {
-                                "title": "Start Datetime",
-                                "type": "string",
-                                "format": "date-time",
-                            }
-                        ),
-                        "end_datetime": IsDict(
-                            {
-                                "title": "End Datetime",
-                                "anyOf": [
-                                    {"type": "string", "format": "date-time"},
-                                    {"type": "null"},
-                                ],
-                            }
-                        )
-                        | IsDict(
-                            # TODO: remove when deprecating Pydantic v1
-                            {
-                                "title": "End Datetime",
-                                "type": "string",
-                                "format": "date-time",
-                            }
-                        ),
+                        "start_datetime": {
+                            "title": "Start Datetime",
+                            "type": "string",
+                            "format": "date-time",
+                        },
+                        "end_datetime": {
+                            "title": "End Datetime",
+                            "type": "string",
+                            "format": "date-time",
+                        },
                         "repeat_at": IsDict(
                             {
                                 "title": "Repeat At",
@@ -160,10 +137,8 @@ def test_openapi_schema(client: TestClient):
                         "process_after": IsDict(
                             {
                                 "title": "Process After",
-                                "anyOf": [
-                                    {"type": "string", "format": "duration"},
-                                    {"type": "null"},
-                                ],
+                                "type": "string",
+                                "format": "duration",
                             }
                         )
                         | IsDict(
@@ -175,6 +150,7 @@ def test_openapi_schema(client: TestClient):
                             }
                         ),
                     },
+                    "required": ["start_datetime", "end_datetime", "process_after"],
                 },
                 "ValidationError": {
                     "title": "ValidationError",
index 0b71d9177332979a661b3a344e8e023d92e4cb4e..50c9aefdf22fed34d5464ec98e4e444cd699a696 100644 (file)
@@ -76,6 +76,7 @@ def test_openapi_schema(client: TestClient):
                         }
                     ],
                     "requestBody": {
+                        "required": True,
                         "content": {
                             "application/json": {
                                 "schema": IsDict(
@@ -95,7 +96,7 @@ def test_openapi_schema(client: TestClient):
                                     }
                                 )
                             }
-                        }
+                        },
                     },
                 }
             }
@@ -106,40 +107,16 @@ def test_openapi_schema(client: TestClient):
                     "title": "Body_read_items_items__item_id__put",
                     "type": "object",
                     "properties": {
-                        "start_datetime": IsDict(
-                            {
-                                "title": "Start Datetime",
-                                "anyOf": [
-                                    {"type": "string", "format": "date-time"},
-                                    {"type": "null"},
-                                ],
-                            }
-                        )
-                        | IsDict(
-                            # TODO: remove when deprecating Pydantic v1
-                            {
-                                "title": "Start Datetime",
-                                "type": "string",
-                                "format": "date-time",
-                            }
-                        ),
-                        "end_datetime": IsDict(
-                            {
-                                "title": "End Datetime",
-                                "anyOf": [
-                                    {"type": "string", "format": "date-time"},
-                                    {"type": "null"},
-                                ],
-                            }
-                        )
-                        | IsDict(
-                            # TODO: remove when deprecating Pydantic v1
-                            {
-                                "title": "End Datetime",
-                                "type": "string",
-                                "format": "date-time",
-                            }
-                        ),
+                        "start_datetime": {
+                            "title": "Start Datetime",
+                            "type": "string",
+                            "format": "date-time",
+                        },
+                        "end_datetime": {
+                            "title": "End Datetime",
+                            "type": "string",
+                            "format": "date-time",
+                        },
                         "repeat_at": IsDict(
                             {
                                 "title": "Repeat At",
@@ -160,10 +137,8 @@ def test_openapi_schema(client: TestClient):
                         "process_after": IsDict(
                             {
                                 "title": "Process After",
-                                "anyOf": [
-                                    {"type": "string", "format": "duration"},
-                                    {"type": "null"},
-                                ],
+                                "type": "string",
+                                "format": "duration",
                             }
                         )
                         | IsDict(
@@ -175,6 +150,7 @@ def test_openapi_schema(client: TestClient):
                             }
                         ),
                     },
+                    "required": ["start_datetime", "end_datetime", "process_after"],
                 },
                 "ValidationError": {
                     "title": "ValidationError",