Skip to content

Commit

Permalink
📝 Fix types in examples under docs_src/extra_data_types (#10535)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <[email protected]>
  • Loading branch information
3 people authored Apr 19, 2024
1 parent d84d6e0 commit 6d523d6
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 215 deletions.
8 changes: 4 additions & 4 deletions docs_src/extra_data_types/tutorial001.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
@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
return {
"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,
}
8 changes: 4 additions & 4 deletions docs_src/extra_data_types/tutorial001_an.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
@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
return {
"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,
}
8 changes: 4 additions & 4 deletions docs_src/extra_data_types/tutorial001_an_py310.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
@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
return {
"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,
}
8 changes: 4 additions & 4 deletions docs_src/extra_data_types/tutorial001_an_py39.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
@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
return {
"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,
}
8 changes: 4 additions & 4 deletions docs_src/extra_data_types/tutorial001_py310.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
@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
return {
"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,
}
54 changes: 15 additions & 39 deletions tests/test_tutorial/test_extra_data_types/test_tutorial001.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def test_openapi_schema():
}
],
"requestBody": {
"required": True,
"content": {
"application/json": {
"schema": IsDict(
Expand All @@ -86,7 +87,7 @@ def test_openapi_schema():
}
)
}
}
},
},
}
}
Expand All @@ -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",
Expand All @@ -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(
Expand All @@ -166,6 +141,7 @@ def test_openapi_schema():
}
),
},
"required": ["start_datetime", "end_datetime", "process_after"],
},
"ValidationError": {
"title": "ValidationError",
Expand Down
54 changes: 15 additions & 39 deletions tests/test_tutorial/test_extra_data_types/test_tutorial001_an.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def test_openapi_schema():
}
],
"requestBody": {
"required": True,
"content": {
"application/json": {
"schema": IsDict(
Expand All @@ -86,7 +87,7 @@ def test_openapi_schema():
}
)
}
}
},
},
}
}
Expand All @@ -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",
Expand All @@ -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(
Expand All @@ -166,6 +141,7 @@ def test_openapi_schema():
}
),
},
"required": ["start_datetime", "end_datetime", "process_after"],
},
"ValidationError": {
"title": "ValidationError",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def test_openapi_schema(client: TestClient):
}
],
"requestBody": {
"required": True,
"content": {
"application/json": {
"schema": IsDict(
Expand All @@ -95,7 +96,7 @@ def test_openapi_schema(client: TestClient):
}
)
}
}
},
},
}
}
Expand All @@ -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",
Expand All @@ -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(
Expand All @@ -175,6 +150,7 @@ def test_openapi_schema(client: TestClient):
}
),
},
"required": ["start_datetime", "end_datetime", "process_after"],
},
"ValidationError": {
"title": "ValidationError",
Expand Down
Loading

0 comments on commit 6d523d6

Please sign in to comment.