title: Changing schema name in OpenAPI docs generated by FastAPI
body: <p>I'm using FastAPI to create backend for my project. I have a method that allows to upload a file. I implemented it as follows:</p>
  <pre class="lang-py prettyprint-override"><code>from fastapi import APIRouter, UploadFile, File
  
  from app.models.schemas.files import FileInResponse
  
  router = APIRouter()
  
  
  @router.post(&quot;&quot;, name=&quot;files:create-file&quot;, response_model=FileInResponse)
  async def create(file: UploadFile = File(...)) -&gt; FileInResponse:
      pass
  </code></pre>
  <p>As you can see, I use a dedicated pydantic model for a method result—<code>FileInResponse</code>:</p>
  <pre class="lang-py prettyprint-override"><code>from pathlib import Path
  
  from pydantic import BaseModel
  
  
  class FileInResponse(BaseModel):
      path: Path
  </code></pre>
  <p>And I follow this naming pattern for models (naming models as <code>&lt;Entity&gt;InCreate</code>, <code>&lt;Entity&gt;InResponse</code>, and so on) throughout the API. However, I couldn't create a pydantic model with a field of the type <code>File</code>, so I had to declare it directly in the route definition (i.e. without a model containing it). As a result, I have this long auto generated name <code>Body_files_create_file_api_files_post</code> in the OpenAPI docs:</p>
  <p><a href="https://i.stack.imgur.com/6I4E7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6I4E7.png" alt="Generated OpenAPI docs" /></a></p>
  <p>Is there a way to change the schema name?</p>