title: Make every fields as optional with Pydantic
body: <p>I'm making an API with FastAPI and Pydantic.</p>
  <p>I would like to have some PATCH endpoints, where 1 or N fields of a record could be edited at once. <strong>Moreover, I would like the client to only pass the necessary fields in the payload.</strong></p>
  <p>Example:</p>
  <pre class="lang-py prettyprint-override"><code>class Item(BaseModel):
      name: str
      description: str
      price: float
      tax: float
  
  
  @app.post(&quot;/items&quot;, response_model=Item)
  async def post_item(item: Item):
      ...
  
  @app.patch(&quot;/items/{item_id}&quot;, response_model=Item)
  async def update_item(item_id: str, item: Item):
      ...
  </code></pre>
  <p>In this example, for the POST request, I want every field to be required. However, in the PATCH endpoint, I don't mind if the payload only contains, for example, the description field. That's why I wish to have all fields as optional.</p>
  <p>Naive approach:</p>
  <pre class="lang-py prettyprint-override"><code>class UpdateItem(BaseModel):
      name: Optional[str] = None
      description: Optional[str] = None
      price: Optional[float] = None
      tax: Optional[float]
  </code></pre>
  <p>But that would be terrible in terms of code repetition.</p>
  <p>Any better option?</p>