title: FastAPI schema from an OpenAPI yaml file
body: <p>I'm looking for a way to initialize a <a href="https://fastapi.tiangolo.com/" rel="nofollow noreferrer">FastAPI</a> server, with an existing OpenAPI YAML schema file.</p>
  <p>The <a href="https://fastapi.tiangolo.com/advanced/extending-openapi/" rel="nofollow noreferrer">docs</a> do describe how to modify the auto-generated schema, but I'm looking for something like <a href="https://connexion.readthedocs.io/en/latest/index.html" rel="nofollow noreferrer">Connexion</a>, which can generate the validators on-the-fly.</p>
  <ul>
  <li>a related question can be found <a href="https://stackoverflow.com/questions/64401878/how-to-extend-fastapi-docs-with-another-swagger-docs">here</a></li>
  <li>a tool to generate a FastAPI project from an OpenAPI schema file can be found <a href="https://pypi.org/project/fastapi-code-generator/" rel="nofollow noreferrer">here</a>, but did not work in my case (the project is still experimental)</li>
  </ul>
  <p><strong>Edit</strong></p>
  <p>I've traced down the offending property to this one:</p>
  <pre><code>class MyParameters(BaseModel):
      ...
      ModelName: Optional[ModelName] = Field(None, description='')
      ...
  </code></pre>
  <p>The matching object schema in openapi.yaml:</p>
  <pre><code>MyParameters:
      type: object
      properties:
          ...
          ModelName:
              type: string
              enum: [XYZ]
              description: &quot;&quot;
          ...
  </code></pre>
  <p><code>ModelName</code> is not mandatory.</p>