Expand description
OpenAPI 3.1 doc generation. Behind the openapi feature.
Walk a built Router and emit a serde_json::Value
shaped like an OpenAPI 3.1 document. The generator pulls structural data
directly from the route tree — every (mount_path, RouteDef) pair the
#[controller] and app_routes! macros recorded — so the spec reflects
the code, not a hand-maintained YAML file.
ⓘ
use actus::prelude::*;
use actus::openapi;
let router = init().await?;
let spec = openapi::generate(
&router,
&openapi::Options::new("My API", "1.0.0").description("…"),
// Document only `/api/...` — hide internal mounts.
|mount| mount.starts_with("api/"),
);
println!("{}", openapi::to_string_pretty(&spec));§Scope
- Mapping is structural, not semantic. Verbs, path params, query
params (typed, with defaults, optional
Vec<String>), JSON / Bytes request bodies, and the handler’s///doc as summary + description. No response-body schema is inferred — handlers can return anything, and the framework’sReplyshape doesn’t carry that information. Operations get adefaultresponse with a generic description; if you need richer responses, post-process the generatedValue. - Trailing rest parameters (
{...name}) don’t have a clean OpenAPI form — the spec’s path templating is a single segment per{name}. The generator strips the...and addsx-actus-rest-param: trueplus adescriptionnoting “captures the trailing path (slashes included)” on the parameter, so clients and tooling can recognise it if they want to. DEFAULT_VERBSroutes (no verb prefix inroutes!— acceptsGETandPOST) emit two operations on the path, one per verb.- Route selection. The
filterpredicate runs on the mount path (the controller’s prefix, no leading slash, no trailing slash). A route is included iff its controller’s mount passes the predicate. The flexible form is a closure; the most common shape is|mount| mount.starts_with("api/").
Structs§
- Options
- Top-level options for the generated spec. The OpenAPI
infoobject plus an optionalserverslist. - Server
Info - One entry in the OpenAPI
serversarray — a base URL the API is reachable at, plus an optional human description.
Functions§
- generate
- Walk
routerand emit an OpenAPI 3.1Value.filteris consulted with the mount path of each controller (no leading or trailing slash); only routes from controllers whose mount passes are included. - to_
string_ pretty - Pretty-printed JSON of a generated spec. Convenience for serving the
document at e.g.
/openapi.json.