Guide Home Part 1 - FastAPI Foundations Part 2 - Building Applications Part 3 - Pages and HTML Part 4 - Security and Deployment Part 5 - Going Further Capstone Build Plan Markdown Source All Guides

Chapter 11: Documenting APIs with OpenAPI

FastAPI generates OpenAPI from routes, type hints, Pydantic models, status codes, tags, summaries, descriptions, and security dependencies.

@router.post(
    "",
    response_model=RecipeRead,
    status_code=201,
    summary="Create a recipe",
    responses={
        409: {"description": "A recipe with this title already exists"},
    },
)
def create_recipe(command: RecipeCreate, db: DbSession) -> RecipeRead:
    ...

Good API documentation is not accidental:

OpenAPI is also a contract. If client teams depend on your schema, test it or snapshot it.