From d3b142a488d6ac68af6f1913a834cb4d669ee4ea Mon Sep 17 00:00:00 2001 From: Kirill Kinduk Date: Fri, 2 Aug 2024 11:32:47 +0300 Subject: [PATCH] telegram authorizer support --- crates/aide/Cargo.toml | 2 ++ crates/aide/src/axum/inputs.rs | 11 ++++++++++- crates/aide/src/axum/mod.rs | 6 +++--- crates/aide/src/transform.rs | 9 ++++++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/crates/aide/Cargo.toml b/crates/aide/Cargo.toml index 24e81e4..a2fc583 100644 --- a/crates/aide/Cargo.toml +++ b/crates/aide/Cargo.toml @@ -31,6 +31,7 @@ cfg-if = "1.0.0" # custom axum extractors serde_qs = { version = "0.13", optional = true } jwt-authorizer = { version = "0.14", default-features = false, optional = true } +telegram-authorizer = { version = "0.1.0", default-features = false, optional = true } [features] macros = ["dep:aide-macros"] @@ -52,6 +53,7 @@ axum-wasm = ["axum"] serde_qs = ["dep:serde_qs"] jwt-authorizer = ["dep:jwt-authorizer"] +telegram-authorizer = ["dep:telegram-authorizer"] [dev-dependencies] serde = { version = "1.0.144", features = ["derive"] } diff --git a/crates/aide/src/axum/inputs.rs b/crates/aide/src/axum/inputs.rs index d0ad5c7..f6c0414 100644 --- a/crates/aide/src/axum/inputs.rs +++ b/crates/aide/src/axum/inputs.rs @@ -424,7 +424,7 @@ mod jwt_authorizer { ctx.security_schemes.insert( t.clone(), ReferenceOr::Item(SecurityScheme::Http { - scheme: "Bearer".to_string(), + scheme: "bearer".to_string(), bearer_format: Some("JWT".to_string()), description: Some("A bearer token.".to_string()), extensions: Default::default(), @@ -435,3 +435,12 @@ mod jwt_authorizer { } } } + +#[cfg(feature = "telegram-authorizer")] +mod telegram_authorizer { + + use crate::OperationInput; + use ::telegram_authorizer::TelegramUser; + + impl OperationInput for TelegramUser {} +} diff --git a/crates/aide/src/axum/mod.rs b/crates/aide/src/axum/mod.rs index e7fcbe0..bd4a983 100644 --- a/crates/aide/src/axum/mod.rs +++ b/crates/aide/src/axum/mod.rs @@ -177,6 +177,8 @@ use crate::{ util::merge_paths, OperationInput, OperationOutput, }; +#[cfg(not(feature = "axum-wasm"))] +use axum::extract::connect_info::IntoMakeServiceWithConnectInfo; use axum::{ body::Body, handler::Handler, @@ -185,8 +187,6 @@ use axum::{ routing::{IntoMakeService, Route, RouterAsService, RouterIntoService}, Router, }; -#[cfg(not(feature = "axum-wasm"))] -use axum::extract::connect_info::IntoMakeServiceWithConnectInfo; use indexmap::map::Entry; use indexmap::IndexMap; use tower_layer::Layer; @@ -361,7 +361,7 @@ where } fn merge_api(&mut self, api: &mut OpenApi) { - self.merge_api_with(api, |x| x) + self.merge_api_with(api, |x| x); } fn merge_api_with(&mut self, api: &mut OpenApi, transform: F) where diff --git a/crates/aide/src/transform.rs b/crates/aide/src/transform.rs index 5e97d49..bb97906 100644 --- a/crates/aide/src/transform.rs +++ b/crates/aide/src/transform.rs @@ -646,7 +646,10 @@ impl<'t> TransformOperation<'t> { { in_context(|ctx| { if let Some(mut res) = R::operation_response(ctx, self.operation) { - let responses = self.operation.responses.get_or_insert_with(Default::default); + let responses = self + .operation + .responses + .get_or_insert_with(Default::default); if responses.default.is_none() { let t = transform(TransformResponse::new(&mut res)); @@ -838,7 +841,7 @@ impl<'t> TransformOperation<'t> { let t = callback_transform(TransformCallback::new(p)); if t.hidden { - callbacks.remove(callback_url); + callbacks.swap_remove(callback_url); if self .operation .callbacks @@ -848,7 +851,7 @@ impl<'t> TransformOperation<'t> { .unwrap() .is_empty() { - self.operation.callbacks.remove(callback_name); + self.operation.callbacks.swap_remove(callback_name); } }