Compile-time switch
OpenApi::enabled(false) turns the documentation routes off at runtime. To keep the documentation engine out of the binary entirely, switch it off when building.
Turn it off
toml
[env]
AXUM_AUTODOC_ENABLED = "false"sh
AXUM_AUTODOC_ENABLED=false cargo build --releaseAccepted values are true/false, 1/0, yes/no and on/off; the default is true. Anything else stops the build with an error, so a typo cannot silently ship the docs.
What is left out
With false, these are not compiled:
- the spec builder and the schema generator,
- the Scalar and Swagger UI pages,
- the TypeScript client,
#[api]registration.
ApiRouter becomes a thin wrapper over axum::Router, and #[api] leaves the function untouched.
What keeps working
Your code compiles unchanged:
- the builders,
DocError,DocContextandDetailare still there and do nothing, Body,QueryandParamsstill validate,Authstill authenticates.
Only the APIs that read the generated document are unavailable: ApiRouter::document, typescript_client, DocContext::operation and the openapi module's document types.
Which mode am I in?
axum_autodoc::ENABLED is a const bool:
rust
if axum_autodoc::ENABLED {
eprintln!("docs at http://localhost:{port}/openapi");
}