Python endpoint discovery

List Every FastAPI Endpoint and Find Routes Missing from OpenAPI

FastAPI exposes its registered routes at runtime and generates OpenAPI automatically. That makes route inspection straightforward, but mounted applications, custom route classes, disabled schema inclusion, and stale deployment artifacts can still create differences between code, runtime, and the published specification.

Direct framework method

Start with the routes registered at runtime

List the routes from the running application, then compare them with app.openapi()["paths"] to find routes left out of the generated contract. Since FastAPI 0.137, included routers stay nested inside app.routes, so the snippet walks them with iter_route_contexts() when it is available and skips mounts and WebSocket routes.

FastAPI route inventory · python
from fastapi import FastAPI

try:  # FastAPI 0.137.2+: included routers stay a tree inside app.routes
    from fastapi.routing import iter_route_contexts
except ImportError:  # older versions copy every route into one flat list
    iter_route_contexts = None


def list_routes(application: FastAPI) -> list[tuple[str, str]]:
    routes = application.routes
    if iter_route_contexts is not None:
        routes = iter_route_contexts(routes)
    found = []
    for route in routes:
        if hasattr(route, "original_router"):  # only FastAPI 0.137.0 and 0.137.1
            raise RuntimeError("Upgrade FastAPI to 0.137.2+ to list included routers")
        methods = getattr(route, "methods", None)
        if methods:  # mounts and WebSocket routes have no HTTP methods
            found.append((", ".join(sorted(methods)), route.path))
    return sorted(found, key=lambda item: item[1])


def routes_missing_from_openapi(application: FastAPI) -> list[tuple[str, str]]:
    documented = {
        (method.upper(), path)
        for path, operations in application.openapi()["paths"].items()
        for method in operations
    }
    built_in = {application.openapi_url, application.docs_url,
                application.redoc_url, application.swagger_ui_oauth2_redirect_url}
    return [
        (methods, path)
        for methods, path in list_routes(application)
        if path not in built_in
        and not any((method, path) in documented for method in methods.split(", "))
    ]


from app.main import app  # import your FastAPI application

for methods, path in list_routes(app):
    print(f"{methods:10} {path}")
print("Not in OpenAPI:", routes_missing_from_openapi(app))

Where a route-listing snippet stops

  • The application must import and start successfully before runtime inspection is complete.
  • Routes configured with include_in_schema=False are reachable but absent from generated OpenAPI.
  • Mounted sub-applications and dynamically registered routes require explicit traversal and verification.
  • A runtime list does not explain which source file or handler registered each route consistently.
  • app.routes is an internal detail: FastAPI 0.137 changed it from a flat list to a tree, which broke code that looped over it.

Use source as the second inventory

APIScout reads supported FastAPI projects from source inside VS Code, links discovered routes to their implementation context, and exports an OpenAPI baseline without starting the service.

Review supported frameworks

Source scan example

What a source scan finds in a FastAPI app

We ran the APIScout engine on a small FastAPI app: routers included in routers with accumulated prefixes and tags, a Depends() database session, an optional query parameter, a header parameter, Pydantic request models with inheritance, a named status code, a multipart upload, and a route hidden with include_in_schema=False. It read the source without importing the app or installing its dependencies, and linked each endpoint back to the file that registered it.

app/main.py
app.include_router(api_router, prefix="/api/v1")


@app.get("/internal/debug", include_in_schema=False)
def debug():
    return {"debug": True}
app/api.py
api_router.include_router(users.router, prefix="/users", tags=["users"])
api_router.include_router(projects.router)
app/routers/users.py
@router.get("/", response_model=list[User])
def list_users(page: int = 1, db=Depends(get_db)):
    return []


@router.post("/", status_code=status.HTTP_201_CREATED, response_model=User)
def create_user(user: UserCreate, db=Depends(get_db)):
    return {"id": 1, "email": user.email}


@router.get("/{user_id}", response_model=User)
def get_user(user_id: int, x_request_id: Annotated[str | None, Header()] = None):
    return {"id": user_id, "email": "[email protected]"}
app/routers/projects.py
router = APIRouter(prefix="/projects", tags=["projects"])


@router.post("/{project_id}/files")
def upload_file(project_id: int, file: UploadFile = File(...), note: str = Form("")):
    return {"project_id": project_id, "name": file.filename}
app/schemas.py
class UserBase(BaseModel):
    email: str


class UserCreate(UserBase):
    password: str = Field(..., min_length=8)

Endpoints found

GET/api/v1/users/Two prefixes joined; optional page query parameter; Depends() left out
POST/api/v1/users/JSON body UserCreate with email (inherited) and password, both required; status 201 from status.HTTP_201_CREATED
GET/api/v1/users/{user_id}Path parameter user_id and an optional header parameter
POST/api/v1/projects/{project_id}/filesRouter-level prefix; multipart body with file and note
GET/healthTop-level route
GET/internal/debugListed, although include_in_schema=False keeps it out of FastAPI's OpenAPI

Not resolved from source: paths built in code, such as routes registered in a loop. Compare those with a runtime listing.

Route patterns: the snippet above vs a source scan

Routers included in routersFull path; on FastAPI 0.137.2+ through iter_route_contexts()Found with the accumulated prefix, such as /api/v1/users/{user_id}
include_in_schema=FalseListed, and reported by routes_missing_from_openapi()Listed with the other routes
Parameters and request modelsMethod and path onlyQuery, path, and header parameters; the Pydantic body with inherited fields; multipart File and Form fields
Depends() argumentsNot shownLeft out of the parameters
Status codes such as status.HTTP_201_CREATEDNot shownRead into the operation's responses
Importing the appNeeds the app to import, with its dependencies and settingsReads the source; nothing is imported or started
Paths built in code (loops)Final values, because the app has runNot resolved; check them against a runtime listing

Questions about listing FastAPI routes

How do I list all routes in a FastAPI app?

Loop over the app's routes and keep the entries that have HTTP methods. Since FastAPI 0.137.0, app.routes is a tree: included routers stay as intermediate objects, so a plain loop over it raises an AttributeError. FastAPI 0.137.2 added fastapi.routing.iter_route_contexts() for code that used to read router.routes, and the snippet above uses it when it exists. The release notes call router.routes an internal implementation detail, so expect it to change again.

How do I find FastAPI routes missing from OpenAPI?

Compare the runtime list with app.openapi()["paths"]. Routes declared with include_in_schema=False still answer requests but are left out of the generated document, and so are FastAPI's own /openapi.json, /docs, and /redoc routes. routes_missing_from_openapi() in the snippet does the comparison and leaves FastAPI's docs routes out. On the sample app it returns GET /internal/debug.

Why does my route listing fail with "has no attribute 'methods'"?

Not every entry in app.routes is an HTTP route. Mounted applications (app.mount(), including StaticFiles) and WebSocket routes have no methods, and on FastAPI 0.137+ an included router appears as an _IncludedRouter object. Read the attribute with getattr(route, "methods", None) and skip entries without it, as the snippet does.

Can I get an OpenAPI document for a FastAPI project without running it?

FastAPI builds its OpenAPI document at runtime, so app.openapi() needs the app to import with its dependencies and settings. APIScout reads the source instead: it resolves router prefixes, reads parameters, Pydantic request models, and status codes, lists routes hidden with include_in_schema=False, and exports an OpenAPI document.

Turn the inventory into a reviewable API contract

Export OpenAPI, review the endpoints with the team that owns them, and use the same contract for documentation and security testing.

Open the source-to-OpenAPI workflow