From 40a3c6e0fb96514c59db51e9253d12c31a6c755f Mon Sep 17 00:00:00 2001 From: NexVeridian Date: Wed, 16 Oct 2024 01:38:36 -0700 Subject: [PATCH 1/6] example: serving the OpenAPI doc and adding OpenAPI to auth --- examples/demo/Cargo.lock | 171 ++++++++++++++++++++- examples/demo/Cargo.toml | 7 +- examples/demo/README.md | 13 +- examples/demo/src/app.rs | 20 +++ examples/demo/src/controllers/auth.rs | 31 +++- examples/demo/src/controllers/responses.rs | 6 + examples/demo/src/models/users.rs | 4 +- examples/demo/src/views/auth.rs | 4 +- 8 files changed, 242 insertions(+), 14 deletions(-) diff --git a/examples/demo/Cargo.lock b/examples/demo/Cargo.lock index b769ce4ab..a2dd21a75 100644 --- a/examples/demo/Cargo.lock +++ b/examples/demo/Cargo.lock @@ -182,6 +182,15 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" +dependencies = [ + "derive_arbitrary", +] + [[package]] name = "arc-swap" version = "1.7.1" @@ -1446,6 +1455,10 @@ dependencies = [ "trycmd", "unic-langid", "utoipa", + "utoipa-axum", + "utoipa-redoc", + "utoipa-scalar", + "utoipa-swagger-ui", "uuid", "validator", ] @@ -1482,6 +1495,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive_arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "derive_more" version = "0.99.18" @@ -2994,6 +3018,12 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "lockfree-object-pool" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9374ef4228402d4b7e403e5838cb880d9ee663314b0a900d5a6aabf0c213552e" + [[package]] name = "loco-extras" version = "0.4.0" @@ -4374,6 +4404,40 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "rust-embed" +version = "8.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa66af4a4fdd5e7ebc276f115e895611a34739a9c1c01028383d612d550953c0" +dependencies = [ + "rust-embed-impl", + "rust-embed-utils", + "walkdir", +] + +[[package]] +name = "rust-embed-impl" +version = "8.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6125dbc8867951125eec87294137f4e9c2c96566e61bf72c45095a7c77761478" +dependencies = [ + "proc-macro2", + "quote", + "rust-embed-utils", + "syn 2.0.66", + "walkdir", +] + +[[package]] +name = "rust-embed-utils" +version = "8.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e5347777e9aacb56039b0e1f28785929a8a3b709e87482e7442c72e7c12529d" +dependencies = [ + "sha2", + "walkdir", +] + [[package]] name = "rust-multipart-rfc7578_2" version = "0.6.1" @@ -5070,6 +5134,12 @@ dependencies = [ "rand_core", ] +[[package]] +name = "simd-adler32" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" + [[package]] name = "simdutf8" version = "0.1.4" @@ -6451,9 +6521,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "utoipa" -version = "4.2.3" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5afb1a60e207dca502682537fefcfd9921e71d0b83e9576060f09abc6efab23" +checksum = "5e2b34fc58a72021914a5745832024b2baa638fe771df5a35f3d1b69266bd92c" dependencies = [ "indexmap 2.2.6", "serde", @@ -6461,18 +6531,78 @@ dependencies = [ "utoipa-gen", ] +[[package]] +name = "utoipa-axum" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06e6cee799402b054e6cb75294d86a4ccdd1227bb4ce87e2a732a68f2aa9f934" +dependencies = [ + "axum 0.7.7", + "paste", + "tower-layer", + "tower-service", + "utoipa", +] + [[package]] name = "utoipa-gen" -version = "4.3.1" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20c24e8ab68ff9ee746aad22d39b5535601e6416d1b0feeabf78be986a5c4392" +checksum = "866f11b33be38a747542f435578a164674b8922d958cc065d7f19319c19d4784" dependencies = [ - "proc-macro-error", "proc-macro2", "quote", "syn 2.0.66", ] +[[package]] +name = "utoipa-redoc" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9218304bba9a0ea5e92085b0a427ccce5fd56eaaf6436d245b7578e6a95787e1" +dependencies = [ + "axum 0.7.7", + "serde", + "serde_json", + "utoipa", +] + +[[package]] +name = "utoipa-scalar" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1291aa7a2223c2f8399d1c6627ca0ba57ca0d7ecac762a2094a9dfd6376445a" +dependencies = [ + "axum 0.7.7", + "serde", + "serde_json", + "utoipa", +] + +[[package]] +name = "utoipa-swagger-ui" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0800ca865caaff4484adca065a77927a801bd9c48879f0451ec08846eb6a12b" +dependencies = [ + "axum 0.7.7", + "mime_guess", + "regex", + "rust-embed", + "serde", + "serde_json", + "url", + "utoipa", + "utoipa-swagger-ui-vendored", + "zip", +] + +[[package]] +name = "utoipa-swagger-ui-vendored" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20d6689d3a5693eec4d21f6b9d7c54f37468b856da8e98a7bb316f7b32df6e3" + [[package]] name = "uuid" version = "1.10.0" @@ -7038,6 +7168,37 @@ dependencies = [ "syn 2.0.66", ] +[[package]] +name = "zip" +version = "2.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40dd8c92efc296286ce1fbd16657c5dbefff44f1b4ca01cc5f517d8b7b3d3e2e" +dependencies = [ + "arbitrary", + "crc32fast", + "crossbeam-utils", + "displaydoc", + "flate2", + "indexmap 2.2.6", + "memchr", + "thiserror", + "zopfli", +] + +[[package]] +name = "zopfli" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5019f391bac5cf252e93bbcc53d039ffd62c7bfb7c150414d61369afe57e946" +dependencies = [ + "bumpalo", + "crc32fast", + "lockfree-object-pool", + "log", + "once_cell", + "simd-adler32", +] + [[package]] name = "zstd" version = "0.13.1" diff --git a/examples/demo/Cargo.toml b/examples/demo/Cargo.toml index 36a04ae5a..5bd3445bb 100644 --- a/examples/demo/Cargo.toml +++ b/examples/demo/Cargo.toml @@ -42,7 +42,12 @@ unic-langid = "0.9.4" tera = "1.19.1" tower = "0.4.13" futures-util = "0.3.30" -utoipa = "4.2.3" + +utoipa = "5.0.0" +utoipa-axum = "0.1.0" +utoipa-swagger-ui = { version = "8.0", features = ["axum", "vendored"] } +utoipa-redoc = { version = "5.0.0", features = ["axum"] } +utoipa-scalar = { version = "0.2.0", features = ["axum"] } [[bin]] name = "demo_app-cli" diff --git a/examples/demo/README.md b/examples/demo/README.md index 52561c753..b9aa078e0 100644 --- a/examples/demo/README.md +++ b/examples/demo/README.md @@ -6,4 +6,15 @@ This app is a kitchensink for various capabilities and examples of the [Loco](ht ## OpenAPI with `utoipa` -See [src/controllers/responses.rs](src/controllers/responses.rs) +### Implementing OpenAPI path see +- [src/controllers/auth.rs](src/controllers/auth.rs) +- `Album` in [src/controllers/responses.rs](src/controllers/responses.rs) + +### How to serve the OpenAPI doc see +- `after_routes` in [src/app.rs](src/app.rs) +- `api_routes` in [src/controllers/auth.rs](src/controllers/auth.rs) + +### View the served OpenAPI doc at +- [http://localhost:5150/swagger-ui/](http://localhost:5150/swagger-ui/) +- [http://localhost:5150/redoc](http://localhost:5150/redoc) +- [http://localhost:5150/scalar](http://localhost:5150/scalar) diff --git a/examples/demo/src/app.rs b/examples/demo/src/app.rs index f625e6902..e88f694ed 100644 --- a/examples/demo/src/app.rs +++ b/examples/demo/src/app.rs @@ -1,6 +1,7 @@ use std::path::Path; use async_trait::async_trait; +use axum::Router as AxumRouter; use loco_extras; use loco_rs::{ app::{AppContext, Hooks, Initializer}, @@ -16,6 +17,10 @@ use loco_rs::{ }; use migration::Migrator; use sea_orm::DatabaseConnection; +use utoipa_axum::router::OpenApiRouter; +use utoipa_redoc::{Redoc, Servable}; +use utoipa_scalar::{Scalar, Servable as ScalarServable}; +use utoipa_swagger_ui::SwaggerUi; use crate::{ controllers::{self, middlewares}, @@ -77,6 +82,21 @@ impl Hooks for App { .add_route(controllers::cache::routes()) } + async fn after_routes(router: AxumRouter, _ctx: &AppContext) -> Result { + // Serveing the OpenAPI doc + let (_, api) = OpenApiRouter::new() + .merge(controllers::auth::api_routes()) + .merge(controllers::responses::api_routes()) + .split_for_parts(); + + let router = router + .merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", api.clone())) + .merge(Redoc::with_url("/redoc", api.clone())) + .merge(Scalar::with_url("/scalar", api)); + + Ok(router) + } + async fn boot(mode: StartMode, environment: &Environment) -> Result { create_app::(mode, environment).await } diff --git a/examples/demo/src/controllers/auth.rs b/examples/demo/src/controllers/auth.rs index 3c2cbb0ec..68f1aebdc 100644 --- a/examples/demo/src/controllers/auth.rs +++ b/examples/demo/src/controllers/auth.rs @@ -1,5 +1,6 @@ use loco_rs::{controller::bad_request, prelude::*}; use serde::{Deserialize, Serialize}; +use utoipa_axum::{router::OpenApiRouter, routes}; use crate::{ mailers::auth::AuthMailer, @@ -9,24 +10,27 @@ use crate::{ }, views::auth::UserSession, }; -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, utoipa::ToSchema)] pub struct VerifyParams { pub token: String, } -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, utoipa::ToSchema)] pub struct ForgotParams { pub email: String, } -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, utoipa::ToSchema)] pub struct ResetParams { pub token: String, pub password: String, } +/// Register new user +/// /// Register function creates a new user with the given parameters and sends a /// welcome email to the user +#[utoipa::path(post, request_body = RegisterParams, path = "/api/auth/register", responses((status = 200, body = UserSession)))] async fn register( State(ctx): State, Json(params): Json, @@ -58,8 +62,11 @@ async fn register( format::json(UserSession::new(&user, &token)) } +/// Verify registered user +/// /// Verify register user. if the user not verified his email, he can't login to /// the system. +#[utoipa::path(post, request_body = VerifyParams, path = "/api/auth/verify", responses((status = 200)))] async fn verify( State(ctx): State, Json(params): Json, @@ -77,10 +84,13 @@ async fn verify( format::empty_json() } +/// Forgot password +/// /// In case the user forgot his password this endpoints generate a forgot token /// and send email to the user. In case the email not found in our DB, we are /// returning a valid request for for security reasons (not exposing users DB /// list). +#[utoipa::path(post, request_body = ForgotParams, path = "/api/auth/forgot", responses((status = 200)))] async fn forgot( State(ctx): State, Json(params): Json, @@ -101,7 +111,10 @@ async fn forgot( format::empty_json() } +/// Reset password +/// /// reset user password by the given parameters +#[utoipa::path(post, request_body = ResetParams, path = "/api/auth/reset", responses((status = 200)))] async fn reset(State(ctx): State, Json(params): Json) -> Result { let Ok(user) = users::Model::find_by_reset_token(&ctx.db, ¶ms.token).await else { // we don't want to expose our users email. if the email is invalid we still @@ -117,7 +130,10 @@ async fn reset(State(ctx): State, Json(params): Json) - format::empty_json() } +/// Login +/// /// Creates a user login and returns a token +#[utoipa::path(post, request_body = LoginParams, path = "/api/auth/login", responses((status = 200, body = UserSession)))] async fn login(State(ctx): State, Json(params): Json) -> Result { let user = users::Model::find_by_email(&ctx.db, ¶ms.email).await?; @@ -145,3 +161,12 @@ pub fn routes() -> Routes { .add("/forgot", post(forgot)) .add("/reset", post(reset)) } + +pub fn api_routes() -> OpenApiRouter { + OpenApiRouter::new() + .routes(routes!(register)) + .routes(routes!(verify)) + .routes(routes!(login)) + .routes(routes!(forgot)) + .routes(routes!(reset)) +} diff --git a/examples/demo/src/controllers/responses.rs b/examples/demo/src/controllers/responses.rs index 43e0ea505..5d29b6f2d 100644 --- a/examples/demo/src/controllers/responses.rs +++ b/examples/demo/src/controllers/responses.rs @@ -3,6 +3,7 @@ use axum_extra::extract::cookie::Cookie; use loco_rs::prelude::*; use serde::Serialize; use utoipa::{openapi, OpenApi, ToSchema}; +use utoipa_axum::{router::OpenApiRouter, routes}; #[derive(Serialize)] pub struct Health { @@ -145,3 +146,8 @@ pub fn routes() -> Routes { .add("/album", get(album)) .add("/set_cookie", get(set_cookie)) } + +pub fn api_routes() -> OpenApiRouter { + OpenApiRouter::new() + .routes(routes!(album)) +} diff --git a/examples/demo/src/models/users.rs b/examples/demo/src/models/users.rs index bd2e3f2c3..23ab87f6e 100644 --- a/examples/demo/src/models/users.rs +++ b/examples/demo/src/models/users.rs @@ -7,13 +7,13 @@ use uuid::Uuid; pub use super::_entities::users::{self, ActiveModel, Entity, Model}; -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, utoipa::ToSchema)] pub struct LoginParams { pub email: String, pub password: String, } -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, utoipa::ToSchema)] pub struct RegisterParams { pub email: String, pub password: String, diff --git a/examples/demo/src/views/auth.rs b/examples/demo/src/views/auth.rs index efbf956fe..9e72d7c10 100644 --- a/examples/demo/src/views/auth.rs +++ b/examples/demo/src/views/auth.rs @@ -2,12 +2,12 @@ use serde::{Deserialize, Serialize}; use crate::models::_entities::users; -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, utoipa::ToSchema)] pub struct UserSession { pub token: String, pub user: UserDetail, } -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, utoipa::ToSchema)] pub struct UserDetail { pub pid: String, pub email: String, From d8887b208eb3790622e5a31e80a8b3c1b774df70 Mon Sep 17 00:00:00 2001 From: NexVeridian Date: Thu, 17 Oct 2024 00:59:56 -0700 Subject: [PATCH 2/6] example: add info and tag auth for OpenAPI doc --- examples/demo/src/app.rs | 10 +++++++++- examples/demo/src/controllers/auth.rs | 10 +++++----- examples/demo/src/controllers/responses.rs | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/examples/demo/src/app.rs b/examples/demo/src/app.rs index e88f694ed..ffe7e22ed 100644 --- a/examples/demo/src/app.rs +++ b/examples/demo/src/app.rs @@ -17,6 +17,7 @@ use loco_rs::{ }; use migration::Migrator; use sea_orm::DatabaseConnection; +use utoipa::OpenApi; use utoipa_axum::router::OpenApiRouter; use utoipa_redoc::{Redoc, Servable}; use utoipa_scalar::{Scalar, Servable as ScalarServable}; @@ -84,7 +85,14 @@ impl Hooks for App { async fn after_routes(router: AxumRouter, _ctx: &AppContext) -> Result { // Serveing the OpenAPI doc - let (_, api) = OpenApiRouter::new() + #[derive(OpenApi)] + #[openapi(info( + title = "Loco Demo", + description = "This app is a kitchensink for various capabilities and examples of the [Loco](https://loco.rs) project." + ))] + struct ApiDoc; + + let (_, api) = OpenApiRouter::with_openapi(ApiDoc::openapi()) .merge(controllers::auth::api_routes()) .merge(controllers::responses::api_routes()) .split_for_parts(); diff --git a/examples/demo/src/controllers/auth.rs b/examples/demo/src/controllers/auth.rs index 68f1aebdc..a691bc932 100644 --- a/examples/demo/src/controllers/auth.rs +++ b/examples/demo/src/controllers/auth.rs @@ -30,7 +30,7 @@ pub struct ResetParams { /// /// Register function creates a new user with the given parameters and sends a /// welcome email to the user -#[utoipa::path(post, request_body = RegisterParams, path = "/api/auth/register", responses((status = 200, body = UserSession)))] +#[utoipa::path(post, tag = "auth", request_body = RegisterParams, path = "/api/auth/register", responses((status = 200, body = UserSession)))] async fn register( State(ctx): State, Json(params): Json, @@ -66,7 +66,7 @@ async fn register( /// /// Verify register user. if the user not verified his email, he can't login to /// the system. -#[utoipa::path(post, request_body = VerifyParams, path = "/api/auth/verify", responses((status = 200)))] +#[utoipa::path(post, tag = "auth", request_body = VerifyParams, path = "/api/auth/verify", responses((status = 200)))] async fn verify( State(ctx): State, Json(params): Json, @@ -90,7 +90,7 @@ async fn verify( /// and send email to the user. In case the email not found in our DB, we are /// returning a valid request for for security reasons (not exposing users DB /// list). -#[utoipa::path(post, request_body = ForgotParams, path = "/api/auth/forgot", responses((status = 200)))] +#[utoipa::path(post, tag = "auth", request_body = ForgotParams, path = "/api/auth/forgot", responses((status = 200)))] async fn forgot( State(ctx): State, Json(params): Json, @@ -114,7 +114,7 @@ async fn forgot( /// Reset password /// /// reset user password by the given parameters -#[utoipa::path(post, request_body = ResetParams, path = "/api/auth/reset", responses((status = 200)))] +#[utoipa::path(post, tag = "auth", request_body = ResetParams, path = "/api/auth/reset", responses((status = 200)))] async fn reset(State(ctx): State, Json(params): Json) -> Result { let Ok(user) = users::Model::find_by_reset_token(&ctx.db, ¶ms.token).await else { // we don't want to expose our users email. if the email is invalid we still @@ -133,7 +133,7 @@ async fn reset(State(ctx): State, Json(params): Json) - /// Login /// /// Creates a user login and returns a token -#[utoipa::path(post, request_body = LoginParams, path = "/api/auth/login", responses((status = 200, body = UserSession)))] +#[utoipa::path(post, tag = "auth", request_body = LoginParams, path = "/api/auth/login", responses((status = 200, body = UserSession)))] async fn login(State(ctx): State, Json(params): Json) -> Result { let user = users::Model::find_by_email(&ctx.db, ¶ms.email).await?; diff --git a/examples/demo/src/controllers/responses.rs b/examples/demo/src/controllers/responses.rs index 5d29b6f2d..cbdaa2ce8 100644 --- a/examples/demo/src/controllers/responses.rs +++ b/examples/demo/src/controllers/responses.rs @@ -2,7 +2,7 @@ use axum_extra::extract::cookie::Cookie; use loco_rs::prelude::*; use serde::Serialize; -use utoipa::{openapi, OpenApi, ToSchema}; +use utoipa::{OpenApi, ToSchema}; use utoipa_axum::{router::OpenApiRouter, routes}; #[derive(Serialize)] From 912d2185d9f0e29a6c54d3c9333d3037ca55bcc6 Mon Sep 17 00:00:00 2001 From: NexVeridian Date: Fri, 18 Oct 2024 13:05:55 -0700 Subject: [PATCH 3/6] cargo fmt and cargo fix cargo fix --- examples/demo/src/app.rs | 4 ++-- examples/demo/src/controllers/cache.rs | 3 ++- examples/demo/src/controllers/responses.rs | 3 +-- examples/demo/src/models/roles.rs | 1 - src/mailer/email_sender.rs | 3 ++- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/demo/src/app.rs b/examples/demo/src/app.rs index 7fae62e22..bfc31e1f6 100644 --- a/examples/demo/src/app.rs +++ b/examples/demo/src/app.rs @@ -48,8 +48,8 @@ impl Hooks for App { } // - async fn initializers(ctx: &AppContext) -> Result>> { - let mut initializers: Vec> = vec![ + async fn initializers(_ctx: &AppContext) -> Result>> { + let initializers: Vec> = vec![ Box::new(initializers::axum_session::AxumSessionInitializer), Box::new(initializers::view_engine::ViewEngineInitializer), Box::new(initializers::hello_view_engine::HelloViewEngineInitializer), diff --git a/examples/demo/src/controllers/cache.rs b/examples/demo/src/controllers/cache.rs index 5edee1b8b..90c95fe4c 100644 --- a/examples/demo/src/controllers/cache.rs +++ b/examples/demo/src/controllers/cache.rs @@ -1,6 +1,7 @@ -use crate::models::users; use loco_rs::prelude::*; use serde::{Deserialize, Serialize}; + +use crate::models::users; #[derive(Serialize, Deserialize)] pub struct CacheResponse { value: Option, diff --git a/examples/demo/src/controllers/responses.rs b/examples/demo/src/controllers/responses.rs index cbdaa2ce8..410bea4a0 100644 --- a/examples/demo/src/controllers/responses.rs +++ b/examples/demo/src/controllers/responses.rs @@ -148,6 +148,5 @@ pub fn routes() -> Routes { } pub fn api_routes() -> OpenApiRouter { - OpenApiRouter::new() - .routes(routes!(album)) + OpenApiRouter::new().routes(routes!(album)) } diff --git a/examples/demo/src/models/roles.rs b/examples/demo/src/models/roles.rs index b591340cb..8c45bf9aa 100644 --- a/examples/demo/src/models/roles.rs +++ b/examples/demo/src/models/roles.rs @@ -1,5 +1,4 @@ use loco_rs::prelude::*; -use sea_orm::entity::prelude::*; pub use super::_entities::roles::{self, ActiveModel, Entity, Model}; use crate::models::{_entities::sea_orm_active_enums::RolesName, users, users_roles}; diff --git a/src/mailer/email_sender.rs b/src/mailer/email_sender.rs index 61fe0474b..e392365b5 100644 --- a/src/mailer/email_sender.rs +++ b/src/mailer/email_sender.rs @@ -93,7 +93,8 @@ impl EmailSender { /// /// # Errors /// - /// When email doesn't send successfully or has an error to build the message + /// When email doesn't send successfully or has an error to build the + /// message pub async fn mail(&self, email: &Email) -> Result<()> { let content = MultiPart::alternative_plain_html(email.text.clone(), email.html.clone()); let mut builder = Message::builder() From 7a79961ae0ae23fdc0e42634b32e8c3b0773521f Mon Sep 17 00:00:00 2001 From: NexVeridian Date: Mon, 4 Nov 2024 16:44:26 -0800 Subject: [PATCH 4/6] cargo update --- examples/demo/Cargo.lock | 241 +++++++++++++++++++-------------------- 1 file changed, 120 insertions(+), 121 deletions(-) diff --git a/examples/demo/Cargo.lock b/examples/demo/Cargo.lock index e2e1196d0..6ba6162f9 100644 --- a/examples/demo/Cargo.lock +++ b/examples/demo/Cargo.lock @@ -128,9 +128,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.17" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23a1e53f0f5d86382dafe1cf314783b2044280f406e7e1506368220ad11b1338" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" dependencies = [ "anstyle", "anstyle-parse", @@ -143,9 +143,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8365de52b16c035ff4fcafe0092ba9390540e3e352870ac09933bebcaa2c8c56" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" [[package]] name = "anstyle-parse" @@ -177,15 +177,15 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.91" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8" +checksum = "74f37166d7d48a0284b99dd824694c26119c700b53bf0d1540cdb147dbdaaf13" [[package]] name = "arbitrary" -version = "1.3.2" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" +checksum = "775a8770d29db3dadcb858482cc240af7b2ffde4ac4de67d1d4955728103f0e2" dependencies = [ "derive_arbitrary", ] @@ -378,7 +378,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -395,7 +395,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -513,7 +513,7 @@ checksum = "57d123550fa8d071b7255cb0cc04dc302baa6c8c4a79f55701552684d8399bce" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -633,9 +633,9 @@ dependencies = [ [[package]] name = "bigdecimal" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d712318a27c7150326677b321a5fa91b55f6d9034ffd67f20319e147d40cee" +checksum = "8f850665a0385e070b64c38d2354e6c104c8479c59868d1e48a0c13ee2c7a1c1" dependencies = [ "autocfg", "libm", @@ -717,7 +717,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "syn_derive", ] @@ -816,9 +816,9 @@ checksum = "a3e368af43e418a04d52505cf3dbc23dda4e3407ae2fa99fd0e4f308ce546acc" [[package]] name = "cc" -version = "1.1.31" +version = "1.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" +checksum = "67b9470d453346108f93a59222a9a1a5724db32d0a4727b7ab7ace4b4d822dc9" dependencies = [ "jobserver", "libc", @@ -925,7 +925,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1180,7 +1180,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1191,7 +1191,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1267,13 +1267,13 @@ dependencies = [ [[package]] name = "derive_arbitrary" -version = "1.3.2" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" +checksum = "d475dfebcb4854d596b17b09f477616f80f17a550517f2b3615d8c205d5c802b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1342,7 +1342,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1711,9 +1711,9 @@ checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-lite" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5" +checksum = "3f1fa2f9765705486b33fd2acf1577f8ec449c2ba1f318ae5447697b7c08d210" dependencies = [ "fastrand", "futures-core", @@ -1730,7 +1730,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1881,9 +1881,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" [[package]] name = "hashlink" @@ -2072,9 +2072,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" +checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" dependencies = [ "bytes", "futures-channel", @@ -2227,7 +2227,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -2248,16 +2248,25 @@ dependencies = [ [[package]] name = "idna" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd69211b9b519e98303c015e21a007e293db403b6c85b9b124e133d25e242cdd" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" dependencies = [ - "icu_normalizer", - "icu_properties", + "idna_adapter", "smallvec", "utf8_iter", ] +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + [[package]] name = "ignore" version = "0.4.23" @@ -2300,7 +2309,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.15.0", + "hashbrown 0.15.1", "serde", ] @@ -2312,7 +2321,7 @@ checksum = "0122b7114117e64a63ac49f752a5ca4624d534c7b1c7de796ac196381cd2d947" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -2326,9 +2335,9 @@ dependencies = [ [[package]] name = "insta" -version = "1.40.0" +version = "1.41.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6593a41c7a73841868772495db7dc1e8ecab43bb5c0b6da2059246c4b506ab60" +checksum = "7e9ffc4d4892617c50a928c52b2961cb5174b6fc6ebf252b2fac9d21955c48b8" dependencies = [ "console", "lazy_static", @@ -2476,7 +2485,7 @@ dependencies = [ "futures-util", "hostname", "httpdate", - "idna 1.0.2", + "idna 1.0.3", "mime", "nom", "percent-encoding", @@ -2499,9 +2508,9 @@ checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "libm" -version = "0.2.8" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" [[package]] name = "libredox" @@ -2622,6 +2631,7 @@ dependencies = [ "thiserror", "tokio", "tokio-cron-scheduler", + "tokio-util", "toml", "tower 0.4.13", "tower-http", @@ -2829,7 +2839,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -2955,7 +2965,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -3075,7 +3085,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -3281,7 +3291,7 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -3307,7 +3317,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "version_check", "yansi", ] @@ -3654,7 +3664,7 @@ dependencies = [ "regex", "relative-path", "rustc_version", - "syn 2.0.85", + "syn 2.0.87", "unicode-ident", ] @@ -3678,7 +3688,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn 2.0.85", + "syn 2.0.87", "walkdir", ] @@ -3747,9 +3757,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.37" +version = "0.38.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +checksum = "375116bee2be9ed569afe2154ea6a99dfdffd257f533f187498c2a8f5feaf4ee" dependencies = [ "bitflags", "errno", @@ -3760,9 +3770,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.15" +version = "0.23.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fbb44d7acc4e873d613422379f69f237a1b141928c02f6bc6ccfddddc2d7993" +checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e" dependencies = [ "log", "once_cell", @@ -3850,9 +3860,9 @@ dependencies = [ [[package]] name = "scc" -version = "2.2.3" +version = "2.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb4a8e7cf6f3e2ba33751990b9744cb21d247da624468020d0479faeefc098a5" +checksum = "d8d25269dd3a12467afe2e510f69fb0b46b698e5afb296b59f2145259deaf8e8" dependencies = [ "sdd", ] @@ -3879,14 +3889,14 @@ dependencies = [ "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] name = "sea-orm" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4872675cc5d5d399a2a202c60f3a393ec8d3f3307c36adb166517f348e4db5" +checksum = "d5680a8b686985116607ef5f5af2b1f9e1cc2c228330e93101816a0baa279afa" dependencies = [ "async-stream", "async-trait", @@ -3912,9 +3922,9 @@ dependencies = [ [[package]] name = "sea-orm-cli" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0aefbd960c9ed7b2dfbab97b11890f5d8c314ad6e2f68c7b36c73ea0967fcc25" +checksum = "70a157f42d291ccbd6e913b9d9b12dbe2ccbcf0472efc60c8715dd1254083aec" dependencies = [ "chrono", "clap", @@ -3929,23 +3939,23 @@ dependencies = [ [[package]] name = "sea-orm-macros" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85f714906b72e7265c0b2077d0ad8f235dabebda513c92f1326d5d40cef0dd01" +checksum = "3a239e3bb1b566ad4ec2654d0d193d6ceddfd733487edc9c21a64d214c773910" dependencies = [ "heck 0.4.1", "proc-macro2", "quote", "sea-bae", - "syn 2.0.85", + "syn 2.0.87", "unicode-ident", ] [[package]] name = "sea-orm-migration" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa7bbfbe3bec60b5925193acc9c98b9f8ae9853f52c8004df0c1ea5193c01ea0" +checksum = "63ba07e9f2479cc671758fcb1edee42ff2e32c34b3e67ab41d0af1e41f73c74e" dependencies = [ "async-trait", "clap", @@ -4001,7 +4011,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "thiserror", ] @@ -4025,7 +4035,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -4057,22 +4067,22 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.213" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ea7893ff5e2466df8d720bb615088341b295f849602c6956047f8f80f0e9bc1" +checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.213" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e85ad2009c50b58e87caa8cd6dac16bdf511bbfb7af6c33df902396aa480fa5" +checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -4172,7 +4182,7 @@ checksum = "82fe9db325bcef1fbcde82e078a5cc4efdf787e96b3b9cf45b50b529f2083d67" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -4376,7 +4386,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -4519,7 +4529,7 @@ dependencies = [ "quote", "sqlx-core", "sqlx-macros-core", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -4542,7 +4552,7 @@ dependencies = [ "sqlx-mysql", "sqlx-postgres", "sqlx-sqlite", - "syn 2.0.85", + "syn 2.0.87", "tempfile", "tokio", "url", @@ -4732,9 +4742,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.85" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -4750,7 +4760,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -4773,7 +4783,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -4836,22 +4846,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.65" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" +checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.65" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" +checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -4961,7 +4971,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -5001,14 +5011,14 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.15" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac2caab0bf757388c6c0ae23b3293fdb463fee59434529014f85e3263b995c28" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.16", + "toml_edit", ] [[package]] @@ -5024,18 +5034,7 @@ dependencies = [ name = "toml_edit" version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" -dependencies = [ - "indexmap", - "toml_datetime", - "winnow 0.5.40", -] - -[[package]] -name = "toml_edit" -version = "0.22.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "278f3d518e152219c994ce877758516bca5e118eaed6996192a774fb9fbf0788" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap", "serde", @@ -5142,7 +5141,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -5222,7 +5221,7 @@ dependencies = [ "serde", "shlex", "snapbox", - "toml_edit 0.22.16", + "toml_edit", ] [[package]] @@ -5317,7 +5316,7 @@ checksum = "1ed7f4237ba393424195053097c1516bd4590dc82b84f2f97c5c69e12704555b" dependencies = [ "proc-macro-hack", "quote", - "syn 2.0.85", + "syn 2.0.87", "unic-langid-impl", ] @@ -5425,12 +5424,12 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.2" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" dependencies = [ "form_urlencoded", - "idna 0.5.0", + "idna 1.0.3", "percent-encoding", ] @@ -5460,9 +5459,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "utoipa" -version = "5.1.2" +version = "5.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e12e84f0ff45b6818029cd0f67280e453c80132c1b9897df407ecc20b9f7cfd" +checksum = "514a48569e4e21c86d0b84b5612b5e73c0b2cf09db63260134ba426d4e8ea714" dependencies = [ "indexmap", "serde", @@ -5472,9 +5471,9 @@ dependencies = [ [[package]] name = "utoipa-axum" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "437ecfd6bbcdadb45dab6a63462ec9034fd9d3a926f471298f03aea749028419" +checksum = "1370cc4a8eee751c4d2a729566d83d1568212320a20581c7c72c2d76ab80ed37" dependencies = [ "axum", "paste", @@ -5485,13 +5484,13 @@ dependencies = [ [[package]] name = "utoipa-gen" -version = "5.1.2" +version = "5.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dfc694d3a3118d2b9e80d68be83bf1aab7988510916934db83da61c14e7e6b2" +checksum = "5629efe65599d0ccd5d493688cbf6e03aa7c1da07fe59ff97cf5977ed0637f66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -5580,7 +5579,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -5669,7 +5668,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -5703,7 +5702,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -6007,7 +6006,7 @@ checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "synstructure", ] @@ -6029,7 +6028,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -6049,7 +6048,7 @@ checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "synstructure", ] @@ -6078,7 +6077,7 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] From ebf834c0509a1b1783284b6cc3661febcead20d5 Mon Sep 17 00:00:00 2001 From: NexVeridian Date: Thu, 7 Nov 2024 19:34:53 -0800 Subject: [PATCH 5/6] SecurityAddon --- examples/demo/src/app.rs | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/examples/demo/src/app.rs b/examples/demo/src/app.rs index bfc31e1f6..b4276e7b5 100644 --- a/examples/demo/src/app.rs +++ b/examples/demo/src/app.rs @@ -16,7 +16,10 @@ use loco_rs::{ }; use migration::Migrator; use sea_orm::DatabaseConnection; -use utoipa::OpenApi; +use utoipa::{ + openapi::security::{ApiKey, ApiKeyValue, SecurityScheme, HttpBuilder, HttpAuthScheme}, + Modify, OpenApi, +}; use utoipa_axum::router::OpenApiRouter; use utoipa_redoc::{Redoc, Servable}; use utoipa_scalar::{Scalar, Servable as ScalarServable}; @@ -76,14 +79,41 @@ impl Hooks for App { } async fn after_routes(router: AxumRouter, _ctx: &AppContext) -> Result { - // Serveing the OpenAPI doc + // Serving the OpenAPI doc #[derive(OpenApi)] - #[openapi(info( + #[openapi(modifiers(&SecurityAddon), + info( title = "Loco Demo", description = "This app is a kitchensink for various capabilities and examples of the [Loco](https://loco.rs) project." ))] struct ApiDoc; + // TODO set the jwt token location + // let auth_location = ctx.config.auth.as_ref(); + + struct SecurityAddon; + impl Modify for SecurityAddon { + fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) { + if let Some(components) = openapi.components.as_mut() { + components.add_security_schemes_from_iter([ + ( + "jwt_token", + SecurityScheme::Http( + HttpBuilder::new() + .scheme(HttpAuthScheme::Bearer) + .bearer_format("JWT") + .build(), + ), + ), + ( + "api_key", + SecurityScheme::ApiKey(ApiKey::Header(ApiKeyValue::new("apikey"))), + ), + ]); + } + } + } + let (_, api) = OpenApiRouter::with_openapi(ApiDoc::openapi()) .merge(controllers::auth::api_routes()) .merge(controllers::responses::api_routes()) From be7c6eda03f1620eb5a7928aef166ec4b476095a Mon Sep 17 00:00:00 2001 From: NexVeridian Date: Tue, 12 Nov 2024 01:46:52 -0800 Subject: [PATCH 6/6] combine routes! --- examples/demo/src/controllers/auth.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/examples/demo/src/controllers/auth.rs b/examples/demo/src/controllers/auth.rs index a691bc932..f50ede9bc 100644 --- a/examples/demo/src/controllers/auth.rs +++ b/examples/demo/src/controllers/auth.rs @@ -163,10 +163,5 @@ pub fn routes() -> Routes { } pub fn api_routes() -> OpenApiRouter { - OpenApiRouter::new() - .routes(routes!(register)) - .routes(routes!(verify)) - .routes(routes!(login)) - .routes(routes!(forgot)) - .routes(routes!(reset)) + OpenApiRouter::new().routes(routes!(register, verify, login, forgot, reset)) }