Issue 1:
First Check

I added a very descriptive title to this issue.

I used the GitHub search to find a similar issue and didn't find it.

I searched the FastAPI documentation, with the integrated search.

I already searched in Google "How to X in FastAPI" and didn't find any information.

I already read and followed all the tutorial in the docs and didn't find an answer.

I already checked if it is not related to FastAPI but to Pydantic.

I already checked if it is not related to FastAPI but to Swagger UI.

I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

I commit to help with one of those options 👆

Example Code

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("/items/next", response_model=Item)
async def read_next_item(item: Item):
return {}

Description

Visit swagger docs /docs

Get error Failed to load API definition.

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: <class 'pydantic.dataclasses.Item'>

Operating System

macOS

Operating System Details

No response

FastAPI Version

0.67.0

Python Version

3.9.5

Additional Context

No response

Issue 2:
Describe the bug

When input data is defined as Union type and both models have the same field (or inherit the same base class) response contains duplicated validation errors for the same field.

To Reproduce

Let's create models and route:

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("/foo")
async def foo_post(data: Input = Body(...)):
pass

When request is made with empty json payload {}, response contains two errors for field name (mesage is field required).

Expected behavior

In such case only one error of the same type should be returned without duplicates.

Environment:

OS: macOS

FastAPI: 0.35

Python: 3.7.4