80 lines
2.2 KiB
Rust
80 lines
2.2 KiB
Rust
use utoipa::{
|
|
openapi::security::{ApiKey, ApiKeyValue, SecurityScheme},
|
|
Modify, OpenApi,
|
|
};
|
|
|
|
use crate::content::{
|
|
collection::CollectionData,
|
|
post::{CreatePostData, ImageElement, PostBlock, PostWithAuthor, UpdatePostData},
|
|
site::{CreateSiteData, SiteData, UpdateSiteData},
|
|
};
|
|
|
|
use super::{
|
|
admin::{self, BootstrapInfo},
|
|
auth, collections, posts, sites, users,
|
|
};
|
|
|
|
#[derive(OpenApi)]
|
|
#[openapi(
|
|
info(description = "Cenere content backend"),
|
|
paths(
|
|
// Authentication routes
|
|
auth::login,
|
|
auth::logout,
|
|
auth::me,
|
|
// Post routes
|
|
posts::get_post,
|
|
posts::create_post,
|
|
posts::update_post,
|
|
posts::delete_post,
|
|
// Site routes
|
|
sites::get_site,
|
|
sites::create_site,
|
|
sites::update_site,
|
|
sites::delete_site,
|
|
// Collection routes
|
|
collections::list_collections_for_site,
|
|
collections::list_posts_in_collection,
|
|
// User routes
|
|
users::get_user_sites,
|
|
// Admin routes
|
|
admin::bootstrap
|
|
),
|
|
components(
|
|
schemas(
|
|
// Post data
|
|
PostWithAuthor,PostBlock,ImageElement,
|
|
CreatePostData,UpdatePostData,
|
|
// Site data
|
|
SiteData, CreateSiteData, UpdateSiteData,
|
|
// Collection data
|
|
CollectionData,
|
|
// Admin data
|
|
BootstrapInfo
|
|
)
|
|
),
|
|
modifiers(&SessionAddon),
|
|
tags(
|
|
(name = "posts", description = "Operation on posts within a site"),
|
|
(name = "sites", description = "Operation on sites"),
|
|
(name = "auth", description = "Session management")
|
|
)
|
|
)]
|
|
pub struct ApiDoc;
|
|
|
|
struct SessionAddon;
|
|
|
|
impl Modify for SessionAddon {
|
|
fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
|
|
if let Some(components) = openapi.components.as_mut() {
|
|
components.add_security_scheme(
|
|
"session",
|
|
SecurityScheme::ApiKey(ApiKey::Cookie(ApiKeyValue::with_description(
|
|
"session",
|
|
"Session ID obtained via login or other authenticated calls",
|
|
))),
|
|
)
|
|
}
|
|
}
|
|
}
|