Skip to content

Commit

Permalink
fix(feat): Put utoipa types as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
fussybeaver authored and Niel Drummond committed Dec 2, 2024
1 parent b0eb72e commit 763f3f3
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 68 deletions.
2 changes: 1 addition & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ tracing-subscriber = { workspace = true, optional = true }
typeshare = { workspace = true }
url = { workspace = true, features = ["serde"] }
uuid = { workspace = true, features = ["v4", "serde"], optional = true }
utoipa = { version = "5", features = ["chrono"] }
utoipa = { version = "5.2", features = ["chrono"], optional = true }
zeroize = { workspace = true }
wiremock = { workspace = true, optional = true }

Expand Down
10 changes: 6 additions & 4 deletions common/src/certificate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

#[derive(Deserialize, Serialize, Debug, ToSchema)]
#[derive(Deserialize, Serialize, Debug)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct AddCertificateRequest {
#[serde(alias = "domain")]
Expand All @@ -15,7 +15,8 @@ pub struct DeleteCertificateRequest {
pub subject: String,
}

#[derive(Deserialize, Serialize, Debug, ToSchema)]
#[derive(Deserialize, Serialize, Debug)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct CertificateResponse {
pub id: String,
Expand All @@ -24,7 +25,8 @@ pub struct CertificateResponse {
pub not_after: String,
}

#[derive(Deserialize, Serialize, Debug, ToSchema)]
#[derive(Deserialize, Serialize, Debug)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct CertificateListResponse {
pub certificates: Vec<CertificateResponse>,
Expand Down
4 changes: 2 additions & 2 deletions common/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{path::PathBuf, str::FromStr};
use crossterm::style::Stylize;
use serde::{Deserialize, Serialize};
use strum::{Display, EnumString};
use utoipa::ToSchema;

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Display, Serialize, EnumString)]
#[serde(rename_all = "lowercase")]
Expand All @@ -21,7 +20,8 @@ pub enum State {
Unknown,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Display, Serialize, EnumString, ToSchema)]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Display, Serialize, EnumString)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
#[strum(ascii_case_insensitive)]
Expand Down
7 changes: 4 additions & 3 deletions common/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use serde::{Deserialize, Serialize};
use strum::EnumString;
use tracing::{field::Visit, span, warn, Event, Level, Metadata, Subscriber};
use tracing_subscriber::Layer;
use utoipa::ToSchema;
use uuid::Uuid;

use crate::tracing::JsonVisitor;
Expand Down Expand Up @@ -57,7 +56,8 @@ pub struct LogItem {
pub line: String,
}

#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct LogItemBeta {
pub timestamp: DateTime<Utc>,
Expand Down Expand Up @@ -93,7 +93,8 @@ impl std::fmt::Display for LogItemBeta {
}
}

#[derive(Debug, Serialize, Deserialize, ToSchema)]
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct LogsResponseBeta {
pub logs: Vec<LogItemBeta>,
Expand Down
28 changes: 18 additions & 10 deletions common/src/models/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use comfy_table::{
use crossterm::style::Stylize;
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, fmt::Display, str::FromStr};
use utoipa::ToSchema;
use uuid::Uuid;

use crate::deployment::{DeploymentStateBeta, State};
Expand All @@ -30,13 +29,15 @@ pub struct Response {
pub git_dirty: Option<bool>,
}

#[derive(Deserialize, Serialize, ToSchema)]
#[derive(Deserialize, Serialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct DeploymentListResponseBeta {
pub deployments: Vec<DeploymentResponseBeta>,
}

#[derive(Deserialize, Serialize, ToSchema)]
#[derive(Deserialize, Serialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct DeploymentResponseBeta {
pub id: String,
Expand Down Expand Up @@ -268,7 +269,8 @@ pub fn get_deployments_table(
}
}

#[derive(Deserialize, Serialize, ToSchema)]
#[derive(Deserialize, Serialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct UploadArchiveResponseBeta {
/// The S3 object version ID of the uploaded object
Expand All @@ -286,7 +288,8 @@ pub struct DeploymentRequest {
pub git_dirty: Option<bool>,
}

#[derive(Deserialize, Serialize, ToSchema)]
#[derive(Deserialize, Serialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde(tag = "type", content = "content")]
#[typeshare::typeshare]
pub enum DeploymentRequestBeta {
Expand All @@ -297,7 +300,8 @@ pub enum DeploymentRequestBeta {
Image(DeploymentRequestImageBeta),
}

#[derive(Default, Deserialize, Serialize, ToSchema)]
#[derive(Default, Deserialize, Serialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct DeploymentRequestBuildArchiveBeta {
/// The S3 object version ID of the archive to use
Expand All @@ -309,7 +313,8 @@ pub struct DeploymentRequestBuildArchiveBeta {
pub build_meta: Option<BuildMetaBeta>,
}

#[derive(Deserialize, Serialize, Default, ToSchema)]
#[derive(Deserialize, Serialize, Default)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde(tag = "type", content = "content")]
#[typeshare::typeshare]
pub enum BuildArgsBeta {
Expand All @@ -318,7 +323,8 @@ pub enum BuildArgsBeta {
Unknown,
}

#[derive(Deserialize, Serialize, ToSchema)]
#[derive(Deserialize, Serialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct BuildArgsRustBeta {
/// Version of shuttle-runtime used by this crate
Expand Down Expand Up @@ -354,7 +360,8 @@ impl Default for BuildArgsRustBeta {
}
}

#[derive(Default, Deserialize, Serialize, ToSchema)]
#[derive(Default, Deserialize, Serialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct BuildMetaBeta {
pub git_commit_id: Option<String>,
Expand All @@ -379,7 +386,8 @@ impl std::fmt::Display for BuildMetaBeta {
}
}

#[derive(Default, Deserialize, Serialize, ToSchema)]
#[derive(Default, Deserialize, Serialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct DeploymentRequestImageBeta {
pub image: String,
Expand Down
26 changes: 10 additions & 16 deletions common/src/models/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crossterm::style::Stylize;
use serde::{Deserialize, Serialize};
use strum::Display;
use strum::EnumString;
use utoipa::ToSchema;

use crate::deployment::DeploymentStateBeta;

Expand All @@ -29,13 +28,15 @@ pub struct Response {
pub is_admin: bool,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, ToSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct ProjectCreateRequestBeta {
pub name: String,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, ToSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct ProjectResponseBeta {
pub id: String,
Expand Down Expand Up @@ -81,33 +82,26 @@ impl ProjectResponseBeta {
}
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, ToSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct ProjectListResponseBeta {
pub projects: Vec<ProjectResponseBeta>,
}

/// Set wanted field(s) to Some to update those parts of the project
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, ToSchema)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct ProjectUpdateRequestBeta {
pub name: Option<String>,
pub compute_tier: Option<ComputeTier>,
}

#[derive(
Debug,
Default,
Clone,
Copy,
PartialEq,
Eq,
Display,
Serialize,
Deserialize,
EnumString,
ToSchema,
Debug, Default, Clone, Copy, PartialEq, Eq, Display, Serialize, Deserialize, EnumString,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
#[typeshare::typeshare]
Expand Down
27 changes: 10 additions & 17 deletions common/src/models/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use chrono::{DateTime, Utc};
use crossterm::style::Stylize;
use serde::{Deserialize, Serialize};
use strum::{Display, EnumString};
use utoipa::ToSchema;

/// In normal cases, a string with the format `user_<ULID>`.
/// This is a soft rule and the string can be something different.
pub type UserId = String;

#[derive(Deserialize, Serialize, Debug, ToSchema)]
#[derive(Deserialize, Serialize, Debug)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct UserResponse {
pub name: String,
Expand Down Expand Up @@ -43,24 +43,14 @@ impl UserResponse {
}

#[derive(
Clone,
Copy,
Debug,
Default,
Deserialize,
Serialize,
Eq,
PartialEq,
Ord,
PartialOrd,
EnumString,
ToSchema,
Clone, Copy, Debug, Default, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd, EnumString,
)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(feature = "display", derive(strum::Display))]
#[cfg_attr(feature = "display", strum(serialize_all = "lowercase"))]
#[cfg_attr(feature = "persist", derive(sqlx::Type))]
#[cfg_attr(feature = "persist", sqlx(rename_all = "lowercase"))]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub enum AccountTier {
#[default]
Expand All @@ -77,7 +67,8 @@ pub enum AccountTier {
Deployer,
}

#[derive(Deserialize, Serialize, Debug, ToSchema)]
#[derive(Deserialize, Serialize, Debug)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct Subscription {
pub id: String,
Expand All @@ -87,15 +78,17 @@ pub struct Subscription {
pub updated_at: DateTime<Utc>,
}

#[derive(Deserialize, Debug, ToSchema)]
#[derive(Deserialize, Debug)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct SubscriptionRequest {
pub id: String,
pub r#type: SubscriptionType,
pub quantity: i32,
}

#[derive(Clone, Debug, EnumString, Display, Deserialize, Serialize, Eq, PartialEq, ToSchema)]
#[derive(Clone, Debug, EnumString, Display, Deserialize, Serialize, Eq, PartialEq)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
#[typeshare::typeshare]
Expand Down
25 changes: 10 additions & 15 deletions common/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{fmt::Display, str::FromStr};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use thiserror::Error;
use utoipa::ToSchema;

use crate::{constants::RESOURCE_SCHEMA_VERSION, database};

Expand Down Expand Up @@ -49,7 +48,8 @@ impl From<ProvisionResourceRequest> for ProvisionResourceRequestBeta {
}
}

#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct ProvisionResourceRequestBeta {
/// The type of this resource
Expand Down Expand Up @@ -77,8 +77,9 @@ pub enum ResourceInputBeta {

/// The resource state represents the stage of the provisioning process the resource is in.
#[derive(
Debug, Clone, PartialEq, Eq, strum::Display, strum::EnumString, Serialize, Deserialize, ToSchema,
Debug, Clone, PartialEq, Eq, strum::Display, strum::EnumString, Serialize, Deserialize,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
#[typeshare::typeshare]
Expand All @@ -102,7 +103,8 @@ pub struct ShuttleResourceOutput<T> {
pub custom: Value,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, ToSchema)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct ResourceResponseBeta {
pub r#type: ResourceTypeBeta,
Expand All @@ -113,7 +115,8 @@ pub struct ResourceResponseBeta {
pub output: Value,
}

#[derive(Debug, Serialize, Deserialize, ToSchema)]
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
pub struct ResourceListResponseBeta {
pub resources: Vec<ResourceResponseBeta>,
Expand Down Expand Up @@ -157,17 +160,9 @@ pub enum Type {
}

#[derive(
Clone,
Copy,
Debug,
strum::EnumString,
strum::Display,
Deserialize,
Serialize,
Eq,
PartialEq,
ToSchema,
Clone, Copy, Debug, strum::EnumString, strum::Display, Deserialize, Serialize, Eq, PartialEq,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[typeshare::typeshare]
// is a flat enum instead of nested enum to allow typeshare
pub enum ResourceTypeBeta {
Expand Down
1 change: 1 addition & 0 deletions common/src/secrets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use zeroize::Zeroize;
/// To make sure nothing leaks after the [`Secret`] has been dropped, a custom [`Drop`]
/// implementation will zero-out the underlying memory.
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct Secret<T: Zeroize>(T);

impl<T: Zeroize> Debug for Secret<T> {
Expand Down

0 comments on commit 763f3f3

Please sign in to comment.