From 4f115872b71f438c4438baabd543f04fd8aa3373 Mon Sep 17 00:00:00 2001 From: Eugene Michkov Date: Sat, 10 Aug 2024 21:03:37 +0300 Subject: [PATCH] refactor: remove swagger --- Cargo.lock | 88 ++++------------------- Cargo.toml | 1 - src/data/enums/device_status.rs | 5 +- src/data/enums/os.rs | 5 +- src/dto/auth/request/authorize.rs | 3 +- src/dto/auth/request/change_password.rs | 4 +- src/dto/auth/request/sign_in.rs | 5 +- src/dto/auth/request/sign_up.rs | 5 +- src/dto/auth/response/tokens.rs | 3 +- src/dto/device/internal/device_info.rs | 5 +- src/dto/device/response/device.rs | 3 +- src/dto/session/request/create_session.rs | 3 +- src/dto/session/response/session.rs | 3 +- src/swagger.rs | 70 ------------------ 14 files changed, 24 insertions(+), 179 deletions(-) delete mode 100644 src/swagger.rs diff --git a/Cargo.lock b/Cargo.lock index 79dd279..efb61cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -104,7 +104,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn", ] [[package]] @@ -464,7 +464,7 @@ dependencies = [ "diesel_table_macro_syntax", "proc-macro2", "quote", - "syn 2.0.63", + "syn", ] [[package]] @@ -473,7 +473,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc5557efc453706fed5e4fa85006fe9817c224c3f480a34c7e5959fd700921c5" dependencies = [ - "syn 2.0.63", + "syn", ] [[package]] @@ -758,7 +758,6 @@ dependencies = [ "tower-http", "tracing", "tracing-subscriber", - "utoipa", "uuid", ] @@ -1015,7 +1014,6 @@ checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown 0.14.5", - "serde", ] [[package]] @@ -1334,7 +1332,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn", ] [[package]] @@ -1428,7 +1426,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn", ] [[package]] @@ -1476,30 +1474,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" version = "1.0.82" @@ -1891,7 +1865,7 @@ checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn", ] [[package]] @@ -2022,16 +1996,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "unicode-ident", -] - [[package]] name = "syn" version = "2.0.63" @@ -2105,7 +2069,7 @@ checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn", ] [[package]] @@ -2190,7 +2154,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn", ] [[package]] @@ -2321,7 +2285,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn", ] [[package]] @@ -2423,32 +2387,6 @@ dependencies = [ "serde", ] -[[package]] -name = "utoipa" -version = "4.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5afb1a60e207dca502682537fefcfd9921e71d0b83e9576060f09abc6efab23" -dependencies = [ - "indexmap 2.2.6", - "serde", - "serde_json", - "utoipa-gen", -] - -[[package]] -name = "utoipa-gen" -version = "4.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bf0e16c02bc4bf5322ab65f10ab1149bdbcaa782cba66dc7057370a3f8190be" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "regex", - "syn 2.0.63", - "uuid", -] - [[package]] name = "uuid" version = "1.10.0" @@ -2469,7 +2407,7 @@ checksum = "ee1cd046f83ea2c4e920d6ee9f7c3537ef928d75dce5d84a87c2c5d6b3999a3a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn", ] [[package]] @@ -2526,7 +2464,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.63", + "syn", "wasm-bindgen-shared", ] @@ -2560,7 +2498,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2794,7 +2732,7 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 5986138..9a5d49b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,6 @@ tower = { version = "0.4.13", features = ["full"] } tower-http = { version = "0.5.0", features = ["full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } -utoipa = { version = "4.2", features = ["axum_extras", "chrono", "uuid"] } uuid = { version = "1.10", features = [ "serde", "v4", diff --git a/src/data/enums/device_status.rs b/src/data/enums/device_status.rs index 562d491..6efd271 100644 --- a/src/data/enums/device_status.rs +++ b/src/data/enums/device_status.rs @@ -7,11 +7,8 @@ use diesel::{ serialize::{self, IsNull, Output, ToSql}, }; use serde::{Deserialize, Serialize}; -use utoipa::ToSchema; -#[derive( - Debug, AsExpression, FromSqlRow, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, ToSchema, -)] +#[derive(Debug, AsExpression, FromSqlRow, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] #[diesel(sql_type = crate::data::schema::sql_types::DeviceStatus)] pub enum DeviceStatus { LoggedIn, diff --git a/src/data/enums/os.rs b/src/data/enums/os.rs index 40a9232..585da10 100644 --- a/src/data/enums/os.rs +++ b/src/data/enums/os.rs @@ -7,11 +7,8 @@ use diesel::{ serialize::{self, IsNull, Output, ToSql}, }; use serde::{Deserialize, Serialize}; -use utoipa::ToSchema; -#[derive( - Debug, AsExpression, FromSqlRow, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, ToSchema, -)] +#[derive(Debug, AsExpression, FromSqlRow, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] #[diesel(sql_type = crate::data::schema::sql_types::Os)] #[allow( non_camel_case_types, diff --git a/src/dto/auth/request/authorize.rs b/src/dto/auth/request/authorize.rs index dfb62c5..2c72e02 100644 --- a/src/dto/auth/request/authorize.rs +++ b/src/dto/auth/request/authorize.rs @@ -1,8 +1,7 @@ use crate::{data::enums::OAuthProvider, dto::device::internal::DeviceInfo}; use serde::{Deserialize, Serialize}; -use utoipa::ToSchema; -#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct AuthorizeRequest { pub code: String, pub provider: OAuthProvider, diff --git a/src/dto/auth/request/change_password.rs b/src/dto/auth/request/change_password.rs index c6a54eb..29fbcce 100644 --- a/src/dto/auth/request/change_password.rs +++ b/src/dto/auth/request/change_password.rs @@ -1,8 +1,6 @@ use serde::{Deserialize, Serialize}; -use utoipa::ToSchema; -#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct ChangePasswordRequest { - #[schema(example = "strong_password")] pub password: String, } diff --git a/src/dto/auth/request/sign_in.rs b/src/dto/auth/request/sign_in.rs index 472d7b9..84dc9b1 100644 --- a/src/dto/auth/request/sign_in.rs +++ b/src/dto/auth/request/sign_in.rs @@ -1,12 +1,9 @@ use crate::dto::device::internal::DeviceInfo; use serde::{Deserialize, Serialize}; -use utoipa::ToSchema; -#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct SignInRequest { - #[schema(example = "vitya@gmail.com")] pub email: String, - #[schema(example = "strong_password")] pub password: String, pub device: DeviceInfo, } diff --git a/src/dto/auth/request/sign_up.rs b/src/dto/auth/request/sign_up.rs index 6817b53..a2793a2 100644 --- a/src/dto/auth/request/sign_up.rs +++ b/src/dto/auth/request/sign_up.rs @@ -1,12 +1,9 @@ use crate::dto::device::internal::DeviceInfo; use serde::{Deserialize, Serialize}; -use utoipa::ToSchema; -#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct SignUpRequest { - #[schema(example = "vitya@gmail.com")] pub email: String, - #[schema(example = "strong_password")] pub password: String, pub device: DeviceInfo, } diff --git a/src/dto/auth/response/tokens.rs b/src/dto/auth/response/tokens.rs index 8145152..7ca985b 100644 --- a/src/dto/auth/response/tokens.rs +++ b/src/dto/auth/response/tokens.rs @@ -1,7 +1,6 @@ use serde::{Deserialize, Serialize}; -use utoipa::ToSchema; -#[derive(Debug, Deserialize, Serialize, ToSchema)] +#[derive(Debug, Deserialize, Serialize)] pub struct Tokens { pub access_token: String, pub refresh_token: String, diff --git a/src/dto/device/internal/device_info.rs b/src/dto/device/internal/device_info.rs index 4c9e3ba..b6ea493 100644 --- a/src/dto/device/internal/device_info.rs +++ b/src/dto/device/internal/device_info.rs @@ -1,11 +1,8 @@ use crate::data::enums::OS; use serde::{Deserialize, Serialize}; -use utoipa::ToSchema; -#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct DeviceInfo { - #[schema(example = "Android")] pub os: OS, - #[schema(example = "Vitya Phone")] pub name: String, } diff --git a/src/dto/device/response/device.rs b/src/dto/device/response/device.rs index 3e0f1b0..e1d851c 100644 --- a/src/dto/device/response/device.rs +++ b/src/dto/device/response/device.rs @@ -3,10 +3,9 @@ use crate::data::{ models, }; use serde::{Deserialize, Serialize}; -use utoipa::ToSchema; use uuid::Uuid; -#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct Device { pub id: Uuid, pub name: String, diff --git a/src/dto/session/request/create_session.rs b/src/dto/session/request/create_session.rs index 7e79023..749f5cb 100644 --- a/src/dto/session/request/create_session.rs +++ b/src/dto/session/request/create_session.rs @@ -1,8 +1,7 @@ use crate::data::enums::Country; use serde::{Deserialize, Serialize}; -use utoipa::ToSchema; -#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct CreateSession { pub country: Country, } diff --git a/src/dto/session/response/session.rs b/src/dto/session/response/session.rs index 4b6dbfe..3d2ba75 100644 --- a/src/dto/session/response/session.rs +++ b/src/dto/session/response/session.rs @@ -1,9 +1,8 @@ use crate::data::models; use serde::{Deserialize, Serialize}; -use utoipa::ToSchema; use uuid::Uuid; -#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct Session { pub session_id: Uuid, pub server_public_key: String, diff --git a/src/swagger.rs b/src/swagger.rs deleted file mode 100644 index 6d5fdad..0000000 --- a/src/swagger.rs +++ /dev/null @@ -1,70 +0,0 @@ -use crate::{ - data::enums::{DeviceStatus, OS}, - dto::{ - auth::{ - request::{ChangePasswordRequest, SignInRequest, SignUpRequest}, - response::Tokens, - }, - device::{internal::DeviceInfo, response::Device}, - session::{request::CreateSession, response::Session}, - }, - handlers::{ - auth::{change_password, logout, refresh, sign_in, sign_up}, - device::get_devices, - session::{close_session, create_session}, - }, -}; -use utoipa::{ - openapi::security::SecurityScheme, - {Modify, OpenApi}, -}; - -struct SecurityAddon; - -impl Modify for SecurityAddon { - fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) { - let components = openapi.components.as_mut().unwrap(); - components.add_security_scheme( - "access_token", - SecurityScheme::Http(utoipa::openapi::security::Http::new( - utoipa::openapi::security::HttpAuthScheme::Bearer, - )), - ); - components.add_security_scheme( - "refresh_token", - SecurityScheme::Http(utoipa::openapi::security::Http::new( - utoipa::openapi::security::HttpAuthScheme::Bearer, - )), - ); - } -} - -#[derive(OpenApi)] -#[openapi( - paths( - sign_in::sign_in, - sign_up::sign_up, - refresh::refresh, - logout::logout, - change_password::change_password, - create_session::create_session, - close_session::close_session, - get_devices::get_devices - ), - components( - schemas( - SignInRequest, - SignUpRequest, - DeviceInfo, - Device, - Tokens, - ChangePasswordRequest, - Session, - CreateSession, - OS, - DeviceStatus - ) - ), - modifiers(&SecurityAddon), -)] -pub struct ApiDoc;