Skip to content

resolveFastApiRoutes

reference
1 min readUpdated

Kind: Function

Source: atloria-monorepo/libs/parser-core/src/techdocs/cross-file-routes.ts

Give every FastAPI endpoint the URL the application actually serves it at.

FastAPI builds a path from three pieces that are conventionally in three files: the decorator (@router.get("/{id}")), the router's own prefix (APIRouter(prefix="/api_keys")), and the mount — app.include_router(api_v1_router, prefix="/v1") in main.py, where api_v1_router is itself a router that included this one. Only the first two are in the endpoint's own file, so a per-file parser publishes a suffix and calls it a URL.

Walks down from each FastAPI() application through the include_router graph, resolving each mount's source through the mounting file's imports, and writes the accumulated path.

An endpoint the walk never reaches is one the application does not serve. Where the parse contains the wiring — an app that mounts routers — such an endpoint is marked pathUnresolved rather than left advertising a path that answers nothing. Where the parse contains no wiring at all (a routers-only directory), nothing is touched: the local path is then the best true statement available.

Signature

ts
function resolveFastApiRoutes(entities: Entity[]): number

Parameters

NameType
entitiesEntity[]

Returns: number

Was this page helpful?

Download as PDF