mirror of
https://github.com/clowzed/sero
synced 2026-03-14 20:55:50 +01:00
33 lines
849 B
Rust
33 lines
849 B
Rust
use utoipa::{
|
|
openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme},
|
|
Modify, OpenApi,
|
|
};
|
|
use utoipauto::utoipauto;
|
|
|
|
#[utoipauto]
|
|
#[derive(OpenApi)]
|
|
#[openapi(
|
|
modifiers(&SecurityAddon),
|
|
)]
|
|
pub struct ApiDoc;
|
|
|
|
pub struct SecurityAddon;
|
|
|
|
impl Modify for SecurityAddon {
|
|
fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
|
|
if let Some(components) = openapi.components.as_mut() {
|
|
let security_scheme = SecurityScheme::Http(
|
|
HttpBuilder::new()
|
|
.scheme(HttpAuthScheme::Bearer)
|
|
.bearer_format("JWT")
|
|
.build(),
|
|
);
|
|
|
|
components.add_security_scheme("Bearer-JWT", security_scheme);
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn generate_openapi() -> Result<String, serde_json::Error> {
|
|
ApiDoc::openapi().to_pretty_json()
|
|
}
|