Skip to main content

Module aide

Module aide 

Source
Available on crate feature aide only.
Expand description

OpenAPI support through aide, and so through rovo.

With the aide feature the extractors and error types document themselves:

  • AuthSession marks its route as requiring the SECURITY_SCHEME cookie and documents the layer’s 401 rejections. Option<AuthSession> adds the requirement as well, so a bypass route that also takes an API key lists both as alternatives.
  • Sessions leaves the route public: it is what login and step-up handlers take.
  • GuardError and StepUpError document the responses they convert into.

register adds the scheme itself to the spec; call it once, after finish_api. With rovo, @security session_cookie on a handler adds the same requirement explicitly.

use aide::{axum::{ApiRouter, routing::get}, openapi::OpenApi};
use session_guard::{AuthSession, Guard, MemoryStore};
use uuid::Uuid;

async fn me(session: AuthSession<Uuid>) -> String {
    session.subject.to_string()
}

let guard = Guard::new(MemoryStore::new());
let mut api = OpenApi::default();
let app: axum::Router = ApiRouter::new()
    .api_route("/me", get(me))
    .with_state(guard.clone())
    .finish_api(&mut api);
session_guard::aide::register(&mut api, &guard);

Constants§

SECURITY_SCHEME
The name of the session cookie’s security scheme: session_cookie.

Functions§

register
Adds security_scheme to api as SECURITY_SCHEME.
security_scheme
The session cookie as an OpenAPI apiKey scheme, named after the guard’s cookie.