66 lines
1.7 KiB
Rust
Executable File
66 lines
1.7 KiB
Rust
Executable File
use utoipa::{
|
|
Modify, OpenApi,
|
|
openapi::{
|
|
Components,
|
|
security::{ApiKey, ApiKeyValue, SecurityScheme},
|
|
},
|
|
};
|
|
use utoipa_swagger_ui::SwaggerUi;
|
|
|
|
// Because apparently the OpenApi macro can't import these on its own
|
|
// if the routes are not in the same location as the router
|
|
use crate::routes::{
|
|
__path_index,
|
|
channel::{
|
|
__path_delete_channel, __path_get_channel, __path_get_channel_videos, __path_list_channels,
|
|
__path_update_channel, __path_upload_channel,
|
|
},
|
|
comment::__path_get_video_comments,
|
|
video::{
|
|
__path_delete_video, __path_get_video, __path_list_videos, __path_update_video,
|
|
__path_upload_video,
|
|
},
|
|
};
|
|
|
|
#[derive(OpenApi)]
|
|
#[openapi(
|
|
paths(
|
|
index,
|
|
list_channels,
|
|
list_videos,
|
|
upload_video,
|
|
upload_channel,
|
|
update_channel,
|
|
update_video,
|
|
delete_channel,
|
|
delete_video,
|
|
get_video,
|
|
get_channel,
|
|
get_video_comments,
|
|
get_channel_videos
|
|
),
|
|
info(
|
|
title = "Almond API",
|
|
description = "Interface to archive YouTube videos."
|
|
),
|
|
modifiers(&SecurityAddon),
|
|
)]
|
|
struct ApiDoc;
|
|
|
|
struct SecurityAddon;
|
|
|
|
impl Modify for SecurityAddon {
|
|
fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
|
|
let components = openapi.components.get_or_insert_with(Components::default);
|
|
|
|
components.add_security_scheme(
|
|
"authKey",
|
|
SecurityScheme::ApiKey(ApiKey::Header(ApiKeyValue::with_description("almond-api-key", "The API key/password that must be sent at the request header for protected routes."))),
|
|
);
|
|
}
|
|
}
|
|
|
|
pub fn docs_router() -> SwaggerUi {
|
|
SwaggerUi::new("/docs").url("/api-doc/openapi.json", ApiDoc::openapi())
|
|
}
|