I am using Pydantic in FastAPI, to define in an OpenAPI doc. Realised that to define a value as required, I need to keep the values empty, like below.
class Item(BaseModel):
name: str
description: str
price: float
tax: float
However, I wanted to give an the JSON with example values, which I can create with the below syntax.
class Item(BaseModel):
name: str = "my name"
description: str = "my description"
price: float = 0.234
tax: float = 0.20
But this will render them as not required in OpenAPI docs. Is there any way where I can specify them as required, and yet give an example value?