Skip to content

Commit 48f201e

Browse files
fussybeaverNiel Drummond
andauthored
feat(common): Add utoipa attribute macro types (#2000)
* feat(common): Add utoipa attribute macro types * fix: Move utoipa dependency version into workspace * fix: Add utoipa secret attributes --------- Co-authored-by: Niel Drummond <[email protected]>
1 parent 4c34d24 commit 48f201e

File tree

8 files changed

+52
-0
lines changed

8 files changed

+52
-0
lines changed

Cargo.lock

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ tracing-subscriber = { version = "0.3.16", default-features = false, features =
8484
] }
8585
trybuild = "1.0.72"
8686
typeshare = "1.0.3"
87+
utoipa = "5"
8788
url = "2.5.4"
8889
walkdir = "2.3.3"
8990
webbrowser = "1.0.1"

common/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ serde_json = { workspace = true }
2121
strum = { workspace = true, features = ["derive"] }
2222
tracing = { workspace = true, features = ["std"], optional = true }
2323
typeshare = { workspace = true }
24+
utoipa = { workspace = true, features = ["chrono"], optional = true }
2425
zeroize = { workspace = true }
2526

2627
[dev-dependencies]
@@ -35,6 +36,8 @@ axum = ["dep:axum", "dep:tracing"]
3536
display = ["chrono/clock", "dep:crossterm"]
3637
tables = ["models", "display", "dep:comfy-table"]
3738

39+
utoipa = ["dep:utoipa"]
40+
3841
# internal / utility features
3942
integration-tests = []
4043

common/src/models/certificate.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use serde::{Deserialize, Serialize};
22

33
#[derive(Deserialize, Serialize, Debug)]
4+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
45
#[typeshare::typeshare]
56
pub struct AddCertificateRequest {
67
#[serde(alias = "domain")]
@@ -15,6 +16,7 @@ pub struct DeleteCertificateRequest {
1516
}
1617

1718
#[derive(Deserialize, Serialize, Debug)]
19+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
1820
#[typeshare::typeshare]
1921
pub struct CertificateResponse {
2022
pub id: String,
@@ -24,6 +26,7 @@ pub struct CertificateResponse {
2426
}
2527

2628
#[derive(Deserialize, Serialize, Debug)]
29+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
2730
#[typeshare::typeshare]
2831
pub struct CertificateListResponse {
2932
pub certificates: Vec<CertificateResponse>,

common/src/models/deployment.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use strum::{Display, EnumString};
88
use crossterm::style::Stylize;
99

1010
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Display, Serialize, EnumString)]
11+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
1112
#[serde(rename_all = "lowercase")]
1213
#[strum(serialize_all = "lowercase")]
1314
#[strum(ascii_case_insensitive)]
@@ -65,12 +66,14 @@ impl DeploymentState {
6566
}
6667

6768
#[derive(Deserialize, Serialize)]
69+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
6870
#[typeshare::typeshare]
6971
pub struct DeploymentListResponse {
7072
pub deployments: Vec<DeploymentResponse>,
7173
}
7274

7375
#[derive(Deserialize, Serialize)]
76+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
7477
#[typeshare::typeshare]
7578
pub struct DeploymentResponse {
7679
pub id: String,
@@ -105,13 +108,15 @@ impl DeploymentResponse {
105108
}
106109

107110
#[derive(Deserialize, Serialize)]
111+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
108112
#[typeshare::typeshare]
109113
pub struct UploadArchiveResponse {
110114
/// The S3 object version ID of the uploaded object
111115
pub archive_version_id: String,
112116
}
113117

114118
#[derive(Deserialize, Serialize)]
119+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
115120
#[serde(tag = "type", content = "content")]
116121
#[typeshare::typeshare]
117122
pub enum DeploymentRequest {
@@ -123,6 +128,7 @@ pub enum DeploymentRequest {
123128
}
124129

125130
#[derive(Default, Deserialize, Serialize)]
131+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
126132
#[typeshare::typeshare]
127133
pub struct DeploymentRequestBuildArchive {
128134
/// The S3 object version ID of the archive to use
@@ -135,6 +141,7 @@ pub struct DeploymentRequestBuildArchive {
135141
}
136142

137143
#[derive(Deserialize, Serialize, Default)]
144+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
138145
#[serde(tag = "type", content = "content")]
139146
#[typeshare::typeshare]
140147
pub enum BuildArgs {
@@ -144,6 +151,7 @@ pub enum BuildArgs {
144151
}
145152

146153
#[derive(Deserialize, Serialize)]
154+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
147155
#[typeshare::typeshare]
148156
pub struct BuildArgsRust {
149157
/// Version of shuttle-runtime used by this crate
@@ -183,6 +191,7 @@ impl Default for BuildArgsRust {
183191
pub const GIT_STRINGS_MAX_LENGTH: usize = 80;
184192

185193
#[derive(Default, Deserialize, Serialize)]
194+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
186195
#[typeshare::typeshare]
187196
pub struct BuildMeta {
188197
pub git_commit_id: Option<String>,
@@ -209,6 +218,7 @@ impl std::fmt::Display for BuildMeta {
209218
}
210219

211220
#[derive(Default, Deserialize, Serialize)]
221+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
212222
#[typeshare::typeshare]
213223
pub struct DeploymentRequestImage {
214224
pub image: String,

common/src/models/project.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ use std::fmt::Write;
1010
use super::deployment::DeploymentState;
1111

1212
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
13+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
1314
#[typeshare::typeshare]
1415
pub struct ProjectCreateRequest {
1516
pub name: String,
1617
}
1718

1819
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
20+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
1921
#[typeshare::typeshare]
2022
pub struct ProjectResponse {
2123
pub id: String,
@@ -64,13 +66,15 @@ impl ProjectResponse {
6466
}
6567

6668
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
69+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
6770
#[typeshare::typeshare]
6871
pub struct ProjectListResponse {
6972
pub projects: Vec<ProjectResponse>,
7073
}
7174

7275
/// Set wanted field(s) to Some to update those parts of the project
7376
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq)]
77+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
7478
#[typeshare::typeshare]
7579
pub struct ProjectUpdateRequest {
7680
/// Change display name
@@ -88,6 +92,7 @@ pub struct ProjectUpdateRequest {
8892
#[derive(
8993
Debug, Default, Clone, Copy, PartialEq, Eq, Display, Serialize, Deserialize, EnumString,
9094
)]
95+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
9196
#[serde(rename_all = "lowercase")]
9297
#[strum(serialize_all = "lowercase")]
9398
#[typeshare::typeshare]

common/src/models/user.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
88
use strum::{EnumString, IntoStaticStr};
99

1010
#[derive(Debug, Deserialize, Serialize)]
11+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
1112
#[typeshare::typeshare]
1213
pub struct UserResponse {
1314
pub id: String,
@@ -73,6 +74,7 @@ impl UserResponse {
7374
)]
7475
#[serde(rename_all = "lowercase")]
7576
#[strum(serialize_all = "lowercase")]
77+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
7678
#[typeshare::typeshare]
7779
pub enum AccountTier {
7880
#[default]
@@ -89,6 +91,7 @@ pub enum AccountTier {
8991
}
9092

9193
#[derive(Debug, Deserialize, Serialize)]
94+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
9295
#[typeshare::typeshare]
9396
pub struct Subscription {
9497
pub id: String,
@@ -99,6 +102,7 @@ pub struct Subscription {
99102
}
100103

101104
#[derive(Debug, Deserialize)]
105+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
102106
#[typeshare::typeshare]
103107
pub struct SubscriptionRequest {
104108
pub id: String,
@@ -120,6 +124,7 @@ pub struct SubscriptionRequest {
120124
strum::Display,
121125
IntoStaticStr,
122126
)]
127+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
123128
#[serde(rename_all = "lowercase")]
124129
#[strum(serialize_all = "lowercase")]
125130
#[typeshare::typeshare]

common/src/secrets.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use zeroize::Zeroize;
1515
/// To make sure nothing leaks after the [`Secret`] has been dropped, a custom [`Drop`]
1616
/// implementation will zero-out the underlying memory.
1717
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
18+
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema), schema(value_type = String, format = "password"))]
1819
pub struct Secret<T: Zeroize>(T);
1920

2021
impl<T: Zeroize> Debug for Secret<T> {

0 commit comments

Comments
 (0)