<h3 dir="auto">First Check</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I added a very descriptive title to this issue.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I used the GitHub search to find a similar issue and didn't find it.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I searched the FastAPI documentation, with the integrated search.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already searched in Google "How to X in FastAPI" and didn't find any information.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already read and followed all the tutorial in the docs and didn't find an answer.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/samuelcolvin/pydantic">Pydantic</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/swagger-api/swagger-ui">Swagger UI</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/Redocly/redoc">ReDoc</a>.</li>
</ul>
<h3 dir="auto">Commit to Help</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I commit to help with one of those options <g-emoji class="g-emoji" alias="point_up_2" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f446.png">👆</g-emoji></li>
</ul>
<h3 dir="auto">Example Code</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from dataclasses import dataclass, field
from typing import List, Optional

from fastapi import FastAPI


@dataclass
class Item:
    name: str
    price: float
    tags: List[str] = field(default_factory=list)
    description: Optional[str] = None
    tax: Optional[float] = None


app = FastAPI()


@app.post(&quot;/items/next&quot;, response_model=Item)
async def read_next_item(item: Item):
    return {}"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">dataclasses</span> <span class="pl-k">import</span> <span class="pl-s1">dataclass</span>, <span class="pl-s1">field</span>
<span class="pl-k">from</span> <span class="pl-s1">typing</span> <span class="pl-k">import</span> <span class="pl-v">List</span>, <span class="pl-v">Optional</span>

<span class="pl-k">from</span> <span class="pl-s1">fastapi</span> <span class="pl-k">import</span> <span class="pl-v">FastAPI</span>


<span class="pl-en">@<span class="pl-s1">dataclass</span></span>
<span class="pl-k">class</span> <span class="pl-v">Item</span>:
    <span class="pl-s1">name</span>: <span class="pl-s1">str</span>
    <span class="pl-s1">price</span>: <span class="pl-s1">float</span>
    <span class="pl-s1">tags</span>: <span class="pl-v">List</span>[<span class="pl-s1">str</span>] <span class="pl-c1">=</span> <span class="pl-en">field</span>(<span class="pl-s1">default_factory</span><span class="pl-c1">=</span><span class="pl-s1">list</span>)
    <span class="pl-s1">description</span>: <span class="pl-v">Optional</span>[<span class="pl-s1">str</span>] <span class="pl-c1">=</span> <span class="pl-c1">None</span>
    <span class="pl-s1">tax</span>: <span class="pl-v">Optional</span>[<span class="pl-s1">float</span>] <span class="pl-c1">=</span> <span class="pl-c1">None</span>


<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">FastAPI</span>()


<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">post</span>(<span class="pl-s">"/items/next"</span>, <span class="pl-s1">response_model</span><span class="pl-c1">=</span><span class="pl-v">Item</span>)</span>
<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">read_next_item</span>(<span class="pl-s1">item</span>: <span class="pl-v">Item</span>):
    <span class="pl-k">return</span> {}</pre></div>
<h3 dir="auto">Description</h3>
<ul dir="auto">
<li>Visit swagger docs <code class="notranslate">/docs</code></li>
<li>Get error <code class="notranslate">Failed to load API definition.</code></li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;/.../.venv/lib/python3.9/site-packages/uvicorn/protocols/http/httptools_impl.py&quot;, line 398, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File &quot;/.../.venv/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py&quot;, line 45, in __call__
    return await self.app(scope, receive, send)
  File &quot;/.../.venv/lib/python3.9/site-packages/fastapi/applications.py&quot;, line 199, in __call__
    await super().__call__(scope, receive, send)
  File &quot;/.../.venv/lib/python3.9/site-packages/starlette/applications.py&quot;, line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File &quot;/.../.venv/lib/python3.9/site-packages/starlette/middleware/errors.py&quot;, line 181, in __call__
    raise exc from None
  File &quot;/.../.venv/lib/python3.9/site-packages/starlette/middleware/errors.py&quot;, line 159, in __call__
    await self.app(scope, receive, _send)
  File &quot;/.../.venv/lib/python3.9/site-packages/starlette/exceptions.py&quot;, line 82, in __call__
    raise exc from None
  File &quot;/.../.venv/lib/python3.9/site-packages/starlette/exceptions.py&quot;, line 71, in __call__
    await self.app(scope, receive, sender)
  File &quot;/.../.venv/lib/python3.9/site-packages/starlette/routing.py&quot;, line 580, in __call__
    await route.handle(scope, receive, send)
  File &quot;/.../.venv/lib/python3.9/site-packages/starlette/routing.py&quot;, line 241, in handle
    await self.app(scope, receive, send)
  File &quot;/.../.venv/lib/python3.9/site-packages/starlette/routing.py&quot;, line 52, in app
    response = await func(request)
  File &quot;/.../.venv/lib/python3.9/site-packages/fastapi/applications.py&quot;, line 152, in openapi
    return JSONResponse(self.openapi())
  File &quot;/.../.venv/lib/python3.9/site-packages/fastapi/applications.py&quot;, line 130, in openapi
    self.openapi_schema = get_openapi(
  File &quot;/.../.venv/lib/python3.9/site-packages/fastapi/openapi/utils.py&quot;, line 376, in get_openapi
    definitions = get_model_definitions(
  File &quot;/.../.venv/lib/python3.9/site-packages/fastapi/utils.py&quot;, line 28, in get_model_definitions
    model_name = model_name_map[model]
KeyError: &lt;class 'pydantic.dataclasses.Item'&gt;"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "/.../.venv/lib/python3.9/site-packages/uvicorn/protocols/http/httptools_impl.py", line 398, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/.../.venv/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "/.../.venv/lib/python3.9/site-packages/fastapi/applications.py", line 199, in __call__
    await super().__call__(scope, receive, send)
  File "/.../.venv/lib/python3.9/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/.../.venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc from None
  File "/.../.venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/.../.venv/lib/python3.9/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc from None
  File "/.../.venv/lib/python3.9/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/.../.venv/lib/python3.9/site-packages/starlette/routing.py", line 580, in __call__
    await route.handle(scope, receive, send)
  File "/.../.venv/lib/python3.9/site-packages/starlette/routing.py", line 241, in handle
    await self.app(scope, receive, send)
  File "/.../.venv/lib/python3.9/site-packages/starlette/routing.py", line 52, in app
    response = await func(request)
  File "/.../.venv/lib/python3.9/site-packages/fastapi/applications.py", line 152, in openapi
    return JSONResponse(self.openapi())
  File "/.../.venv/lib/python3.9/site-packages/fastapi/applications.py", line 130, in openapi
    self.openapi_schema = get_openapi(
  File "/.../.venv/lib/python3.9/site-packages/fastapi/openapi/utils.py", line 376, in get_openapi
    definitions = get_model_definitions(
  File "/.../.venv/lib/python3.9/site-packages/fastapi/utils.py", line 28, in get_model_definitions
    model_name = model_name_map[model]
KeyError: &lt;class 'pydantic.dataclasses.Item'&gt;
</code></pre></div>
<h3 dir="auto">Operating System</h3>
<p dir="auto">macOS</p>
<h3 dir="auto">Operating System Details</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">FastAPI Version</h3>
<p dir="auto">0.67.0</p>
<h3 dir="auto">Python Version</h3>
<p dir="auto">3.9.5</p>
<h3 dir="auto">Additional Context</h3>
<p dir="auto"><em>No response</em></p>
<p dir="auto"><strong>Describe the bug</strong><br>
When input data is defined as <code class="notranslate">Union</code> type and both models have the same field (or inherit the same base class) response contains duplicated validation errors for the same field.</p>
<p dir="auto"><strong>To Reproduce</strong></p>
<p dir="auto">Let's create models and route:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Base(BaseModel):
    name: str

class ModelA(Base):
    foo: Optional[str] = None

class ModelB(Base):
    bar: Optional[str] = None

Input = Union[ModelA, ModelB]

@api.post(&quot;/foo&quot;)
async def foo_post(data: Input = Body(...)):
    pass"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">Base</span>(<span class="pl-v">BaseModel</span>):
    <span class="pl-s1">name</span>: <span class="pl-s1">str</span>

<span class="pl-k">class</span> <span class="pl-v">ModelA</span>(<span class="pl-v">Base</span>):
    <span class="pl-s1">foo</span>: <span class="pl-v">Optional</span>[<span class="pl-s1">str</span>] <span class="pl-c1">=</span> <span class="pl-c1">None</span>

<span class="pl-k">class</span> <span class="pl-v">ModelB</span>(<span class="pl-v">Base</span>):
    <span class="pl-s1">bar</span>: <span class="pl-v">Optional</span>[<span class="pl-s1">str</span>] <span class="pl-c1">=</span> <span class="pl-c1">None</span>

<span class="pl-v">Input</span> <span class="pl-c1">=</span> <span class="pl-v">Union</span>[<span class="pl-v">ModelA</span>, <span class="pl-v">ModelB</span>]

<span class="pl-en">@<span class="pl-s1">api</span>.<span class="pl-en">post</span>(<span class="pl-s">"/foo"</span>)</span>
<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">foo_post</span>(<span class="pl-s1">data</span>: <span class="pl-v">Input</span> <span class="pl-c1">=</span> <span class="pl-v">Body</span>(...)):
    <span class="pl-k">pass</span></pre></div>
<p dir="auto">When request is made with empty json payload <code class="notranslate">{}</code>, response contains two errors for field <code class="notranslate">name</code> (mesage is <code class="notranslate">field required</code>).</p>
<p dir="auto"><strong>Expected behavior</strong><br>
In such case only one error of the same type should be returned without duplicates.</p>
<p dir="auto"><strong>Environment:</strong></p>
<ul dir="auto">
<li>OS: macOS</li>
<li>FastAPI: 0.35</li>
<li>Python: 3.7.4</li>
</ul>