title: How to make a query parameter required depending of another query parameter in FastApi?
body: <p>I want to make a query parameter required depending of another query parameter in <a href="https://fastapi.tiangolo.com" rel="nofollow noreferrer">FastApi</a></p>
  
  <p>For example I have four query parameters: <code>command</code>, <code>start_date</code>, <code>end_date</code> and <code>increment</code></p>
  
  <p>If <code>command</code> is equal to "analyse", then <code>end_date</code> must be required. But if <code>command</code> is equal to "add_working_days" then <code>end_date</code> is not required but <code>increment</code> is required. Is this possible?</p>
  
  <p>This is my code righ now:</p>
  
  <pre><code>import datetime
  from fastapi import FastAPI, Query
  
  app = FastAPI()  
  
  @app.get("/api/")
  async def read_item(
      start_date: str = Query(..., regex=r"[\d]{4}-[\d]{1,2}-[\d]{1,2}"),
      end_date: str = Query(..., regex=r"[\d]{4}-[\d]{1,2}-[\d]{1,2}"),
      command: str = None,
      increment: int = None,
  ):
      parsed_start_date = datetime.datetime.strptime(start_date, "%Y-%m-%d")
      parsed_end_date = datetime.datetime.strptime(end_date, "%Y-%m-%d")
      duration = parsed_end_date - parsed_start_date
      return duration.days
  </code></pre>