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 fastapi import FastAPI

from pydantic import BaseModel

app = FastAPI()

class TypicalResponse(BaseModel):
msg: str
data: int

@app.get("/add/{x}/{y}")
async def add(x: int, y: int) -> TypicalResponse:
return TypicalResponse(msg="Done!", data=x + y)

Description

Open the automatic doc on this handler

See no output schema defined

I would like to use typing "-> Type" for annotate response model.

This is good for simple handlers.

Wanted Solution

I would like to autodoc parse this typing same as "response_model=TypicalResponse"

Wanted Code

from fastapi import FastAPI

from pydantic import BaseModel

app = FastAPI()

# Same
class TypicalResponse(BaseModel):
msg: str
data: int

@app.get("/add/{x}/{y}")
async def add(x: int, y: int) -> TypicalResponse:
return TypicalResponse(msg="Done!", data=x + y)

Alternatives

I use kwarg "response_model" as single alternative

But typing already defines the output model, necessary duplicate as result.

Operating System

Linux

Operating System Details

No response

FastAPI Version

0.79.0

Python Version

Python 3.9.0

Additional Context

Without patch:

With patch:

I think second is better by avoid information duplication

Meanwhile, solution is quite simple.

One of the ways to implement (don't judge too much, that's first idea):

Open APIRouter class

Modify self.add_api_route by adding

May be dirty, so welcome to search another ways.

Issue 2:
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.

After submitting this, I commit to one of:

Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.

I already hit the "watch" button in this repository to receive notifications and I commit to help at least 2 people that ask questions in the future.

Implement a Pull Request for a confirmed bug.

Example

Here's a self-contained, minimal, reproducible, example with my use case:

from fastapi import FastAPI
from pydantic import BaseModel, constr

app = FastAPI()

class CategoryBase(BaseModel):
title: constr(min_length=4, max_length=30, regex="^[a-zA-Z0-9 _-]+$") # type: ignore
description: Optional[str]

class CategoryCreate(CategoryBase):
pass

class CategoryPublic(CategoryBase):
pass

@app.post("/", response_model=CategoryPublic, name="create-category", status_code=status.HTTP_201_CREATED)
async def create_category(
new_category: CategoryCreate = Body(..., embed=True),
) -> CategoryPublic:
"""I'm the culprit of weird documentation."""
# some code ...

@app.post("/", response_model=CategoryPublic, name="create-category", status_code=status.HTTP_201_CREATED)
async def create_category(
new_category: CategoryCreate = Body(..., embed=False),
) -> CategoryPublic:
"""I'm not."""
# some code ...

Description

TLDR:

How to have a nice documentation with the Body(..., embed=True)

I'm trying to have a nice documentation for the api I'm creating, and I noticed that when using embed=True for the Body parameter, a new schema is created. This not only create two schemas (one for the Pydantic model, and one for the Body), but the name used are not very readable.

I tried to look in the documentation, but I did not see anything about changing the name, or (better) simply preventing the documentation of a somewhat duplicate schema

Environment

OS: Docker image of python:3.8

FastAPI Version: 0.63.0

Additional context