aboutsummaryrefslogtreecommitdiff
path: root/src/api.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api.rs')
-rw-r--r--src/api.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/api.rs b/src/api.rs
new file mode 100644
index 0000000..23fb74b
--- /dev/null
+++ b/src/api.rs
@@ -0,0 +1,56 @@
1use utoipa::{
2 Modify, OpenApi,
3 openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme},
4};
5
6use crate::ErrorResponse;
7
8pub mod tags {
9 pub const ACCOUNT: &str = "Account";
10}
11
12struct AuthModifier;
13
14impl Modify for AuthModifier {
15 fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
16 if let Some(components) = openapi.components.as_mut() {
17 components.add_security_scheme(
18 "auth",
19 SecurityScheme::Http(
20 HttpBuilder::new()
21 .scheme(HttpAuthScheme::Bearer)
22 .bearer_format("JWT")
23 .build(),
24 ),
25 )
26 }
27 }
28}
29
30#[derive(OpenApi)]
31#[openapi(
32 info(
33 title = "ITMO queue server API",
34 description = "Queuing service for labs works",
35 license(
36 name = "AGPL-3.0",
37 url="https://www.gnu.org/licenses/agpl-3.0.en.html#license-text"
38 ),
39 ),
40 servers(
41 (
42 url = "http://localhost:{port}/",
43 description = "Local server",
44 variables(("port" = (default = "8888", description="Server port")))
45 ),
46 (url = "https://очередь.псж.онлайн/api/v1/", description = "Production server"),
47 ),
48 tags(
49 (name=tags::ACCOUNT, description="Account management methods")
50 ),
51 components(
52 schemas(ErrorResponse)
53 ),
54 modifiers(&AuthModifier)
55)]
56pub struct AppOpenApi;