@suss/framework-fastapi
v0.11.0
Published
Pattern pack for extracting suss behavioral summaries from FastAPI routes, composing APIRouter prefixes one include hop deep.
Maintainers
Readme
@suss/framework-fastapi
Framework pack for FastAPI routes, read by the Python adapter.
What this package is
@suss/framework-fastapi returns a PythonPack object describing:
- Discovery: a function decorated with a verb-named method on the app or on a router (
@app.get(path),@router.post(path)), where the decorator's own attribute name is the HTTP verb (get,post,put,patch,delete,head,options). The app and router are recognized by construction:app = FastAPI(),router = APIRouter(), one assignment back from an import offastapi. - Router prefix composition: a route on a router composes its path from the router's own
prefixand theprefixat the singleapp.include_router(...)call that mounts it, when both are string literals and the mount reaches the router through one variable binding (same file, or imported from the file that constructed it). Beyond that, the pack abstains: it still discovers the route by name, with no path, and the summary's gap says why. - Boundary bindings:
rest(method, path), with the declaredresponse_model/status_codekeywords and parameter / return annotations read as the route's contract.
Where it fits in suss
Depends only on @suss/adapter-python (for the PythonPack type and the Python-language extraction pipeline). Contains no analysis logic of its own.
What abstains
The pack never guesses a path. A route keeps its name and has no path when:
- the decorator's path argument is not a string literal,
- the router's own
prefixor the mount call'sprefixis not a string literal, - nothing mounts the router through a single variable binding in the files read,
- the router is mounted more than once,
- the router is mounted onto another router (a second hop), or
- the router's variable name is assigned a second router construction (routes bind at decoration time, so which construction a decorator or mount saw depends on the order things run in, and the pack does not follow that).
Dependencies, middleware, and mounted sub-apps are not read in v0.
The wrapper-module option
A project that re-exports FastAPI's constructors from its own module lists that module alongside fastapi, which is always accepted:
import { fastapiFramework } from "@suss/framework-fastapi";
const pack = fastapiFramework({ wrapperModules: ["myapp.compat"] });Coverage
License
Licensed under Apache 2.0. See LICENSE.
