From afd814dd31679b696b82c19fa266f9e5be466e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABlle=20Huisman?= Date: Thu, 1 May 2025 15:44:16 +0200 Subject: [PATCH] feat(shield-sea-orm): add utoipa feature --- Cargo.lock | 2 ++ examples/sea-orm/Cargo.toml | 1 + packages/storage/shield-sea-orm/Cargo.toml | 3 +++ .../storage/shield-sea-orm/src/entities/email_address.rs | 9 +++++---- .../shield-sea-orm/src/entities/email_auth_token.rs | 7 ++++--- packages/storage/shield-sea-orm/src/entities/entity.rs | 5 +++-- .../shield-sea-orm/src/entities/oauth_provider.rs | 8 ++++++-- .../src/entities/oauth_provider_connection.rs | 7 ++++--- .../storage/shield-sea-orm/src/entities/oidc_provider.rs | 8 ++++++-- .../src/entities/oidc_provider_connection.rs | 7 ++++--- packages/storage/shield-sea-orm/src/entities/user.rs | 5 +++-- 11 files changed, 41 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 730f657..679e55b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4562,12 +4562,14 @@ name = "shield-sea-orm" version = "0.0.4" dependencies = [ "async-trait", + "chrono", "sea-orm", "sea-orm-migration", "serde", "serde_json", "shield", "shield-oidc", + "utoipa", ] [[package]] diff --git a/examples/sea-orm/Cargo.toml b/examples/sea-orm/Cargo.toml index 9bf0975..7eafe5b 100644 --- a/examples/sea-orm/Cargo.toml +++ b/examples/sea-orm/Cargo.toml @@ -25,5 +25,6 @@ sea-orm-migration = { workspace = true, features = [ ] } shield-sea-orm = { path = "../../packages/storage/shield-sea-orm", features = [ "all-providers", + "utoipa", ] } tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } diff --git a/packages/storage/shield-sea-orm/Cargo.toml b/packages/storage/shield-sea-orm/Cargo.toml index 8ffc111..1772a7d 100644 --- a/packages/storage/shield-sea-orm/Cargo.toml +++ b/packages/storage/shield-sea-orm/Cargo.toml @@ -10,6 +10,7 @@ version.workspace = true [dependencies] async-trait.workspace = true +chrono.workspace = true sea-orm.workspace = true sea-orm-migration.workspace = true serde = { workspace = true, features = ["derive"] } @@ -20,6 +21,7 @@ shield = { path = "../../core/shield", version = "0.0.4" } # shield-oauth = { path = "../../providers/shield-oauth", version = "0.0.2", optional = true } shield-oidc = { path = "../../providers/shield-oidc", version = "0.0.4", optional = true } # shield-webauthn = { path = "../../providers/shield-webauthn", version = "0.0.2", optional = true } +utoipa = { workspace = true, optional = true } [features] default = [] @@ -39,3 +41,4 @@ provider-email = [] provider-oauth = [] provider-oidc = ["dep:shield-oidc"] # provider-webauthn = ["dep:shield-webauthn"] +utoipa = ["dep:utoipa", "shield/utoipa"] diff --git a/packages/storage/shield-sea-orm/src/entities/email_address.rs b/packages/storage/shield-sea-orm/src/entities/email_address.rs index a595d6a..de519d8 100644 --- a/packages/storage/shield-sea-orm/src/entities/email_address.rs +++ b/packages/storage/shield-sea-orm/src/entities/email_address.rs @@ -4,19 +4,20 @@ use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] +#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema), schema(as = EmailAddress))] #[sea_orm(table_name = "email_address")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: Uuid, - pub created_at: DateTimeWithTimeZone, - pub updated_at: DateTimeWithTimeZone, + pub created_at: chrono::DateTime, + pub updated_at: chrono::DateTime, #[sea_orm(unique)] pub email: String, pub is_primary: bool, pub is_verified: bool, pub verification_token: Option, - pub verification_token_expired_at: Option, - pub verified_at: Option, + pub verification_token_expired_at: Option>, + pub verified_at: Option>, #[cfg(feature = "entity")] pub entity_id: Uuid, #[cfg(not(feature = "entity"))] diff --git a/packages/storage/shield-sea-orm/src/entities/email_auth_token.rs b/packages/storage/shield-sea-orm/src/entities/email_auth_token.rs index ee44f00..9c52ad7 100644 --- a/packages/storage/shield-sea-orm/src/entities/email_auth_token.rs +++ b/packages/storage/shield-sea-orm/src/entities/email_auth_token.rs @@ -4,15 +4,16 @@ use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] +#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema), schema(as = EmailAuthToken))] #[sea_orm(table_name = "email_auth_token")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: Uuid, - pub created_at: DateTimeWithTimeZone, - pub updated_at: DateTimeWithTimeZone, + pub created_at: chrono::DateTime, + pub updated_at: chrono::DateTime, pub email: String, pub token: String, - pub expired_at: DateTimeWithTimeZone, + pub expired_at: chrono::DateTime, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/packages/storage/shield-sea-orm/src/entities/entity.rs b/packages/storage/shield-sea-orm/src/entities/entity.rs index 44d01a1..259e392 100644 --- a/packages/storage/shield-sea-orm/src/entities/entity.rs +++ b/packages/storage/shield-sea-orm/src/entities/entity.rs @@ -4,12 +4,13 @@ use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] +#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema), schema(as = Entity))] #[sea_orm(table_name = "entity")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: Uuid, - pub created_at: DateTimeWithTimeZone, - pub updated_at: DateTimeWithTimeZone, + pub created_at: chrono::DateTime, + pub updated_at: chrono::DateTime, #[sea_orm(column_type = "Text")] pub name: String, } diff --git a/packages/storage/shield-sea-orm/src/entities/oauth_provider.rs b/packages/storage/shield-sea-orm/src/entities/oauth_provider.rs index fc2e811..806dcf4 100644 --- a/packages/storage/shield-sea-orm/src/entities/oauth_provider.rs +++ b/packages/storage/shield-sea-orm/src/entities/oauth_provider.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] +#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))] #[sea_orm( rs_type = "String", db_type = "Enum", @@ -19,6 +20,7 @@ pub enum OauthProviderPkceCodeChallenge { } #[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] +#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))] #[sea_orm( rs_type = "String", db_type = "Enum", @@ -30,6 +32,7 @@ pub enum OauthProviderType { } #[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] +#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))] #[sea_orm( rs_type = "String", db_type = "Enum", @@ -43,12 +46,13 @@ pub enum OauthProviderVisibility { } #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] +#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema), schema(as = OauthProvider))] #[sea_orm(table_name = "oauth_provider")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: Uuid, - pub created_at: DateTimeWithTimeZone, - pub updated_at: DateTimeWithTimeZone, + pub created_at: chrono::DateTime, + pub updated_at: chrono::DateTime, pub name: String, pub slug: Option, pub r#type: OauthProviderType, diff --git a/packages/storage/shield-sea-orm/src/entities/oauth_provider_connection.rs b/packages/storage/shield-sea-orm/src/entities/oauth_provider_connection.rs index 2717f95..52787d4 100644 --- a/packages/storage/shield-sea-orm/src/entities/oauth_provider_connection.rs +++ b/packages/storage/shield-sea-orm/src/entities/oauth_provider_connection.rs @@ -4,12 +4,13 @@ use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] +#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema), schema(as = OauthProviderConnection))] #[sea_orm(table_name = "oauth_provider_connection")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: Uuid, - pub created_at: DateTimeWithTimeZone, - pub updated_at: DateTimeWithTimeZone, + pub created_at: chrono::DateTime, + pub updated_at: chrono::DateTime, pub identifier: String, #[sea_orm(column_type = "Text")] pub token_type: String, @@ -17,7 +18,7 @@ pub struct Model { pub access_token: String, #[sea_orm(column_type = "Text", nullable)] pub refresh_token: Option, - pub expired_at: Option, + pub expired_at: Option>, #[sea_orm(column_type = "Text", nullable)] pub scopes: Option, pub provider_id: Uuid, diff --git a/packages/storage/shield-sea-orm/src/entities/oidc_provider.rs b/packages/storage/shield-sea-orm/src/entities/oidc_provider.rs index 0bf6092..5ab0f61 100644 --- a/packages/storage/shield-sea-orm/src/entities/oidc_provider.rs +++ b/packages/storage/shield-sea-orm/src/entities/oidc_provider.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] +#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))] #[sea_orm( rs_type = "String", db_type = "Enum", @@ -19,6 +20,7 @@ pub enum OidcProviderPkceCodeChallenge { } #[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] +#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))] #[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "oidc_provider_type")] pub enum OidcProviderType { #[sea_orm(string_value = "custom")] @@ -26,6 +28,7 @@ pub enum OidcProviderType { } #[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] +#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))] #[sea_orm( rs_type = "String", db_type = "Enum", @@ -39,12 +42,13 @@ pub enum OidcProviderVisibility { } #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] +#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema), schema(as = OidcProvider))] #[sea_orm(table_name = "oidc_provider")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: Uuid, - pub created_at: DateTimeWithTimeZone, - pub updated_at: DateTimeWithTimeZone, + pub created_at: chrono::DateTime, + pub updated_at: chrono::DateTime, pub name: String, pub slug: Option, pub r#type: OidcProviderType, diff --git a/packages/storage/shield-sea-orm/src/entities/oidc_provider_connection.rs b/packages/storage/shield-sea-orm/src/entities/oidc_provider_connection.rs index d3a7830..adaa2e0 100644 --- a/packages/storage/shield-sea-orm/src/entities/oidc_provider_connection.rs +++ b/packages/storage/shield-sea-orm/src/entities/oidc_provider_connection.rs @@ -4,12 +4,13 @@ use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] +#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema), schema(as = OidcProviderConnection))] #[sea_orm(table_name = "oidc_provider_connection")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: Uuid, - pub created_at: DateTimeWithTimeZone, - pub updated_at: DateTimeWithTimeZone, + pub created_at: chrono::DateTime, + pub updated_at: chrono::DateTime, pub identifier: String, #[sea_orm(column_type = "Text")] pub token_type: String, @@ -19,7 +20,7 @@ pub struct Model { pub refresh_token: Option, #[sea_orm(column_type = "Text", nullable)] pub id_token: Option, - pub expired_at: Option, + pub expired_at: Option>, #[sea_orm(column_type = "Text", nullable)] pub scopes: Option, pub provider_id: Uuid, diff --git a/packages/storage/shield-sea-orm/src/entities/user.rs b/packages/storage/shield-sea-orm/src/entities/user.rs index 9fd9986..56b9426 100644 --- a/packages/storage/shield-sea-orm/src/entities/user.rs +++ b/packages/storage/shield-sea-orm/src/entities/user.rs @@ -4,12 +4,13 @@ use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] +#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema), schema(as = User))] #[sea_orm(table_name = "user")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: Uuid, - pub created_at: DateTimeWithTimeZone, - pub updated_at: DateTimeWithTimeZone, + pub created_at: chrono::DateTime, + pub updated_at: chrono::DateTime, #[cfg(not(feature = "entity"))] #[sea_orm(column_type = "Text")] pub name: String,