Skip to main content

Crate axa_openapi_docs

Crate axa_openapi_docs 

Source
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 axa sends 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 $ref inside document that 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) from AppRoutes::mounted, with document’s paths, ignoring parameter names. not_documented lists paths a service keeps out on purpose, such as its health probes.
router
A router serving spec at SPEC_PATH and the page at UI_PATH.
shape
A path with its parameter names removed: /things/{pid} and /things/{id} are one route.
spec_of
The JSON for a utoipa document.
swagger_html
The Swagger UI page for the document at spec_url.
with_bearer_auth
Declare bearer authentication on a document, required by default.