Skip to content

Commit

Permalink
telegram authorizer support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Kinduk committed Aug 2, 2024
1 parent 254ea03 commit d3b142a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions crates/aide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"] }
Expand Down
11 changes: 10 additions & 1 deletion crates/aide/src/axum/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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 {}
}
6 changes: 3 additions & 3 deletions crates/aide/src/axum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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<F>(&mut self, api: &mut OpenApi, transform: F)
where
Expand Down
9 changes: 6 additions & 3 deletions crates/aide/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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
Expand All @@ -848,7 +851,7 @@ impl<'t> TransformOperation<'t> {
.unwrap()
.is_empty()
{
self.operation.callbacks.remove(callback_name);
self.operation.callbacks.swap_remove(callback_name);
}
}

Expand Down

0 comments on commit d3b142a

Please sign in to comment.