mirror of https://github.com/tiangolo/fastapi.git
🎨 Auto format
This commit is contained in:
parent
eec2fe9033
commit
ee496848c8
|
|
@ -55,7 +55,7 @@ For example, this model above declares a JSON "`object`" (or Python `dict`) like
|
|||
}
|
||||
```
|
||||
|
||||
### Required fields that can be `None`
|
||||
### Required fields that can be `None` { #required-fields-that-can-be-none }
|
||||
|
||||
In Python type hints, a parameter can be **required** and still allow the value `None`.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,11 @@ from pydantic import BaseModel
|
|||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
description: str | None
|
||||
|
||||
|
||||
@app.post("/items/")
|
||||
async def create_item(item: Item):
|
||||
return item
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
from typing import Optional
|
||||
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
description: Optional[str]
|
||||
|
||||
|
||||
@app.post("/items/")
|
||||
async def create_item(item: Item):
|
||||
return item
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import importlib
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from ...utils import needs_py310
|
||||
|
||||
|
||||
@pytest.fixture(
|
||||
name="client",
|
||||
params=[
|
||||
|
|
|
|||
Loading…
Reference in New Issue