add api key info to admin openapi docs
This commit is contained in:
parent
7d2a72bcde
commit
d827f540e3
|
@ -1,4 +1,10 @@
|
|||
use crate::{app::App, bot::BotMessage, error::Error};
|
||||
use aide::{
|
||||
openapi::{
|
||||
HeaderStyle, Parameter, ParameterData, ParameterSchemaOrContent, ReferenceOr, SchemaObject,
|
||||
},
|
||||
transform::TransformOperation,
|
||||
};
|
||||
use axum::{
|
||||
extract::State,
|
||||
http::Request,
|
||||
|
@ -31,6 +37,31 @@ pub async fn admin_auth<B>(
|
|||
Err((StatusCode::FORBIDDEN, "No, I don't think so"))
|
||||
}
|
||||
|
||||
pub fn admin_auth_doc(op: &mut TransformOperation) {
|
||||
let schema = aide::gen::in_context(|ctx| ctx.schema.subschema_for::<String>());
|
||||
|
||||
op.inner_mut()
|
||||
.parameters
|
||||
.push(ReferenceOr::Item(Parameter::Header {
|
||||
parameter_data: ParameterData {
|
||||
name: "X-Api-Key".to_owned(),
|
||||
description: Some("Configured admin API key".to_owned()),
|
||||
required: true,
|
||||
deprecated: None,
|
||||
format: ParameterSchemaOrContent::Schema(SchemaObject {
|
||||
json_schema: schema,
|
||||
external_docs: None,
|
||||
example: None,
|
||||
}),
|
||||
example: None,
|
||||
examples: Default::default(),
|
||||
explode: None,
|
||||
extensions: Default::default(),
|
||||
},
|
||||
style: HeaderStyle::Simple,
|
||||
}));
|
||||
}
|
||||
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
pub struct ChannelsRequest {
|
||||
/// List of channel ids
|
||||
|
|
|
@ -5,6 +5,7 @@ mod responders;
|
|||
pub mod schema;
|
||||
mod trace_layer;
|
||||
|
||||
use self::handlers::no_cache_header;
|
||||
use crate::{app::App, bot::BotMessage, web::admin::admin_auth, ShutdownRx};
|
||||
use aide::{
|
||||
axum::{
|
||||
|
@ -29,8 +30,6 @@ use tower_http::{
|
|||
};
|
||||
use tracing::{debug, info};
|
||||
|
||||
use self::handlers::no_cache_header;
|
||||
|
||||
pub async fn run(app: App, mut shutdown_rx: ShutdownRx, bot_tx: Sender<BotMessage>) {
|
||||
aide::gen::on_error(|error| {
|
||||
panic!("Could not generate docs: {error}");
|
||||
|
@ -50,10 +49,12 @@ pub async fn run(app: App, mut shutdown_rx: ShutdownRx, bot_tx: Sender<BotMessag
|
|||
let admin_routes = ApiRouter::new()
|
||||
.api_route(
|
||||
"/channels",
|
||||
post_with(admin::add_channels, |op| {
|
||||
post_with(admin::add_channels, |mut op| {
|
||||
admin::admin_auth_doc(&mut op);
|
||||
op.tag("Admin").description("Join the specified channels")
|
||||
})
|
||||
.delete_with(admin::remove_channels, |op| {
|
||||
.delete_with(admin::remove_channels, |mut op| {
|
||||
admin::admin_auth_doc(&mut op);
|
||||
op.tag("Admin").description("Leave the specified channels")
|
||||
}),
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue