Expand description
Serve OpenAPI documents and a pinned Swagger UI, and check a document against the routes a
service mounts.
This works with a document generated by utoipa or one written by hand,
because both end up as JSON:
use axa_openapi_docs::{SPEC_PATH, UI_PATH, router, with_bearer_auth};
use axum::Router;
use serde_json::json;
let mut spec = json!({
"openapi": "3.1.0",
"info": { "title": "Places", "version": "1.0.0" },
"paths": {},
});
with_bearer_auth(&mut spec);
let app: Router = Router::new().merge(router(spec, "Places"));
assert_eq!(SPEC_PATH, "/api-docs/openapi.json");
assert_eq!(UI_PATH, "/swagger-ui");Both routes are public by design, so a service using axa-paseto-auth lists
them with public_path. A deployment that does not want its API described
publicly should simply not mount them.
§The Swagger UI page
The page loads Swagger UI from a CDN, which keeps the binary small, and that makes the CDN part of the supply chain. So the page names one exact version and carries a Subresource Integrity hash for each file, and the browser refuses anything that does not match. The hashes in this crate were checked against the package published on npm.
Re-exports§
pub use utoipa;
Structs§
- Drift
- Where a document and the mounted routes disagree. Each entry reads
get /things/{}.
Constants§
- PAGE_
CSP - The page’s own policy, because
axasends a stricter one by default that would blank it. It allows inline script for the page’s one-line start-up, which holds nothing a caller supplies. - SPEC_
PATH - Where the document is served.
- SWAGGER_
UI_ VERSION - The exact Swagger UI version the page loads.
- UI_PATH
- Where the Swagger UI page is served.
Functions§
- dangling_
refs - Every
$refinsidedocumentthat points at nothing in it. A reference to another file is not followed, and not reported. - drift
- Compare the mounted
routes, as(method, full path)fromAppRoutes::mounted, withdocument’spaths, ignoring parameter names.not_documentedlists paths a service keeps out on purpose, such as its health probes. - router
- A router serving
specatSPEC_PATHand the page atUI_PATH. - shape
- A path with its parameter names removed:
/things/{pid}and/things/{id}are one route. - spec_of
- The JSON for a
utoipadocument. - swagger_
html - The Swagger UI page for the document at
spec_url. - with_
bearer_ auth - Declare bearer authentication on a document, required by default.