mirror of https://github.com/tiangolo/fastapi.git
📝 Fix types in examples under `docs_src/extra_data_types` (#10535)
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>
This commit is contained in:
parent
d84d6e03f4
commit
6d523d62d0
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in New Issue