diff options
Diffstat (limited to 'src/api.rs')
| -rw-r--r-- | src/api.rs | 56 |
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 @@ | |||
| 1 | use utoipa::{ | ||
| 2 | Modify, OpenApi, | ||
| 3 | openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme}, | ||
| 4 | }; | ||
| 5 | |||
| 6 | use crate::ErrorResponse; | ||
| 7 | |||
| 8 | pub mod tags { | ||
| 9 | pub const ACCOUNT: &str = "Account"; | ||
| 10 | } | ||
| 11 | |||
| 12 | struct AuthModifier; | ||
| 13 | |||
| 14 | impl 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 | )] | ||
| 56 | pub struct AppOpenApi; | ||
