@@ -6,14 +6,14 @@ use revolt_config::config;
6
6
use revolt_database:: { Database , DatabaseInfo } ;
7
7
use tokio:: net:: TcpListener ;
8
8
use utoipa:: {
9
- openapi:: security:: { Http , HttpAuthScheme , SecurityScheme } ,
9
+ openapi:: security:: { ApiKey , ApiKeyValue , SecurityScheme } ,
10
10
Modify , OpenApi ,
11
11
} ;
12
12
use utoipa_scalar:: { Scalar , Servable as ScalarServable } ;
13
13
14
14
use crate :: tenor:: Tenor ;
15
15
16
- mod api ;
16
+ mod routes ;
17
17
mod tenor;
18
18
mod types;
19
19
@@ -35,6 +35,26 @@ impl FromRef<AppState> for Tenor {
35
35
}
36
36
}
37
37
38
+ struct TokenAddon ;
39
+
40
+ impl Modify for TokenAddon {
41
+ fn modify ( & self , openapi : & mut utoipa:: openapi:: OpenApi ) {
42
+ let components = openapi. components . get_or_insert_default ( ) ;
43
+
44
+ components. add_security_scheme (
45
+ "User Token" ,
46
+ SecurityScheme :: ApiKey ( ApiKey :: Header ( ApiKeyValue :: new (
47
+ "X-Session-Token" . to_string ( ) ,
48
+ ) ) ) ,
49
+ ) ;
50
+
51
+ components. add_security_scheme (
52
+ "Bot Token" ,
53
+ SecurityScheme :: ApiKey ( ApiKey :: Header ( ApiKeyValue :: new ( "X-Bot-Token" . to_string ( ) ) ) ) ,
54
+ ) ;
55
+ }
56
+ }
57
+
38
58
#[ tokio:: main]
39
59
async fn main ( ) -> Result < ( ) , std:: io:: Error > {
40
60
// Configure logging and environment
@@ -43,36 +63,28 @@ async fn main() -> Result<(), std::io::Error> {
43
63
// Configure API schema
44
64
#[ derive( OpenApi ) ]
45
65
#[ openapi(
46
- modifiers( & SecurityAddon ) ,
66
+ modifiers( & TokenAddon ) ,
47
67
paths(
48
- api:: root,
49
- api:: search,
68
+ routes:: categories:: categories,
69
+ routes:: root:: root,
70
+ routes:: search:: search,
71
+ routes:: trending:: trending,
72
+ ) ,
73
+ tags(
74
+ ( name = "Misc" , description = "Misc routes for microservice." ) ,
75
+ ( name = "GIFs" , description = "All routes for requesting GIFs from tenor." )
50
76
) ,
51
77
components(
52
78
schemas(
53
79
revolt_result:: Error ,
54
80
revolt_result:: ErrorType ,
55
- types:: SearchResponse ,
56
- types:: MediaObject ,
57
81
types:: MediaResult ,
82
+ types:: MediaObject ,
58
83
)
59
- )
84
+ ) ,
60
85
) ]
61
86
struct ApiDoc ;
62
87
63
- struct SecurityAddon ;
64
-
65
- impl Modify for SecurityAddon {
66
- fn modify ( & self , openapi : & mut utoipa:: openapi:: OpenApi ) {
67
- if let Some ( components) = openapi. components . as_mut ( ) {
68
- components. add_security_scheme (
69
- "api_key" ,
70
- SecurityScheme :: Http ( Http :: new ( HttpAuthScheme :: Bearer ) ) ,
71
- )
72
- }
73
- }
74
- }
75
-
76
88
let config = config ( ) . await ;
77
89
let state = AppState {
78
90
database : DatabaseInfo :: Auto
@@ -85,7 +97,7 @@ async fn main() -> Result<(), std::io::Error> {
85
97
// Configure Axum and router
86
98
let app = Router :: new ( )
87
99
. merge ( Scalar :: with_url ( "/scalar" , ApiDoc :: openapi ( ) ) )
88
- . nest ( "/" , api :: router ( ) . await )
100
+ . nest ( "/" , routes :: router ( ) )
89
101
. with_state ( state) ;
90
102
91
103
// Configure TCP listener and bind
0 commit comments