Skip to content

Commit d3b142a

Browse files
author
Kirill Kinduk
committed
telegram authorizer support
1 parent 254ea03 commit d3b142a

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

crates/aide/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ cfg-if = "1.0.0"
3131
# custom axum extractors
3232
serde_qs = { version = "0.13", optional = true }
3333
jwt-authorizer = { version = "0.14", default-features = false, optional = true }
34+
telegram-authorizer = { version = "0.1.0", default-features = false, optional = true }
3435

3536
[features]
3637
macros = ["dep:aide-macros"]
@@ -52,6 +53,7 @@ axum-wasm = ["axum"]
5253

5354
serde_qs = ["dep:serde_qs"]
5455
jwt-authorizer = ["dep:jwt-authorizer"]
56+
telegram-authorizer = ["dep:telegram-authorizer"]
5557

5658
[dev-dependencies]
5759
serde = { version = "1.0.144", features = ["derive"] }

crates/aide/src/axum/inputs.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ mod jwt_authorizer {
424424
ctx.security_schemes.insert(
425425
t.clone(),
426426
ReferenceOr::Item(SecurityScheme::Http {
427-
scheme: "Bearer".to_string(),
427+
scheme: "bearer".to_string(),
428428
bearer_format: Some("JWT".to_string()),
429429
description: Some("A bearer token.".to_string()),
430430
extensions: Default::default(),
@@ -435,3 +435,12 @@ mod jwt_authorizer {
435435
}
436436
}
437437
}
438+
439+
#[cfg(feature = "telegram-authorizer")]
440+
mod telegram_authorizer {
441+
442+
use crate::OperationInput;
443+
use ::telegram_authorizer::TelegramUser;
444+
445+
impl OperationInput for TelegramUser {}
446+
}

crates/aide/src/axum/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ use crate::{
177177
util::merge_paths,
178178
OperationInput, OperationOutput,
179179
};
180+
#[cfg(not(feature = "axum-wasm"))]
181+
use axum::extract::connect_info::IntoMakeServiceWithConnectInfo;
180182
use axum::{
181183
body::Body,
182184
handler::Handler,
@@ -185,8 +187,6 @@ use axum::{
185187
routing::{IntoMakeService, Route, RouterAsService, RouterIntoService},
186188
Router,
187189
};
188-
#[cfg(not(feature = "axum-wasm"))]
189-
use axum::extract::connect_info::IntoMakeServiceWithConnectInfo;
190190
use indexmap::map::Entry;
191191
use indexmap::IndexMap;
192192
use tower_layer::Layer;
@@ -361,7 +361,7 @@ where
361361
}
362362

363363
fn merge_api(&mut self, api: &mut OpenApi) {
364-
self.merge_api_with(api, |x| x)
364+
self.merge_api_with(api, |x| x);
365365
}
366366
fn merge_api_with<F>(&mut self, api: &mut OpenApi, transform: F)
367367
where

crates/aide/src/transform.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,10 @@ impl<'t> TransformOperation<'t> {
646646
{
647647
in_context(|ctx| {
648648
if let Some(mut res) = R::operation_response(ctx, self.operation) {
649-
let responses = self.operation.responses.get_or_insert_with(Default::default);
649+
let responses = self
650+
.operation
651+
.responses
652+
.get_or_insert_with(Default::default);
650653
if responses.default.is_none() {
651654
let t = transform(TransformResponse::new(&mut res));
652655

@@ -838,7 +841,7 @@ impl<'t> TransformOperation<'t> {
838841
let t = callback_transform(TransformCallback::new(p));
839842

840843
if t.hidden {
841-
callbacks.remove(callback_url);
844+
callbacks.swap_remove(callback_url);
842845
if self
843846
.operation
844847
.callbacks
@@ -848,7 +851,7 @@ impl<'t> TransformOperation<'t> {
848851
.unwrap()
849852
.is_empty()
850853
{
851-
self.operation.callbacks.remove(callback_name);
854+
self.operation.callbacks.swap_remove(callback_name);
852855
}
853856
}
854857

0 commit comments

Comments
 (0)