summaryrefslogtreecommitdiff
path: root/server/src/api_model.rs
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2024-12-29 22:40:12 +0100
committerJoel Klinghed <the_jk@spawned.biz>2024-12-29 22:40:12 +0100
commit776406684bdc591a4c97b58b8d28f689881c285e (patch)
tree7551fcc2d10eb4d75314b2ad93bce6c328481413 /server/src/api_model.rs
parent7bc8e8b7262a3f3abe3222b3b434838e85cdb2bb (diff)
Add openapi generation using utoipa
Diffstat (limited to 'server/src/api_model.rs')
-rw-r--r--server/src/api_model.rs47
1 files changed, 37 insertions, 10 deletions
diff --git a/server/src/api_model.rs b/server/src/api_model.rs
index 286e11f..a7c8e88 100644
--- a/server/src/api_model.rs
+++ b/server/src/api_model.rs
@@ -1,6 +1,7 @@
use rocket::serde::Serialize;
+use utoipa::ToSchema;
-#[derive(Serialize, Copy, Clone)]
+#[derive(Serialize, Copy, Clone, ToSchema)]
pub enum ReviewState {
Draft,
Open,
@@ -8,70 +9,96 @@ pub enum ReviewState {
Closed,
}
-#[derive(Serialize)]
+#[derive(Serialize, ToSchema)]
pub struct User {
+ #[schema(example = 1337u64)]
pub id: u64,
+ #[schema(example = "jsmith")]
pub username: String,
+ #[schema(example = "John Smith")]
pub name: String,
+ #[schema(example = true)]
pub active: bool,
}
-#[derive(Serialize)]
+#[derive(Serialize, ToSchema)]
pub struct Review {
+ #[schema(example = 1000u64)]
pub id: u64,
+ #[schema(example = "FAKE-512: Add more features")]
pub title: String,
+ #[schema(example = "We're adding more features because features are what we want.")]
pub description: String,
pub owner: User,
pub reviewers: Vec<User>,
pub watchers: Vec<User>,
+ #[schema(example = ReviewState::Open)]
pub state: ReviewState,
+ #[schema(example = 37.5)]
pub progress: f32,
}
-#[derive(Serialize)]
+#[derive(Serialize, ToSchema)]
pub struct ReviewEntry {
+ #[schema(example = 1000u64)]
pub id: u64,
+ #[schema(example = "FAKE-512: Add more features")]
pub title: String,
pub owner: User,
+ #[schema(example = ReviewState::Open)]
pub state: ReviewState,
+ #[schema(example = 37.5)]
pub progress: f32,
}
-#[derive(Serialize)]
+#[derive(Serialize, ToSchema)]
pub struct Reviews {
+ #[schema(example = 0u32)]
pub offset: u32,
+ #[schema(example = 10u32)]
pub limit: u32,
+ #[schema(example = 42u32)]
pub total_count: u32,
+ #[schema(example = true)]
pub more: bool,
pub reviews: Vec<ReviewEntry>,
}
-#[derive(Serialize)]
+#[derive(Serialize, ToSchema)]
pub struct Project {
+ #[schema(example = 1u64)]
pub id: u64,
+ #[schema(example = "FAKE: Features All Kids Erase")]
pub title: String,
+ #[schema(example = "Example project")]
pub description: String,
pub members: Vec<User>,
}
-#[derive(Serialize)]
+#[derive(Serialize, ToSchema)]
pub struct ProjectEntry {
+ #[schema(example = 1u64)]
pub id: u64,
+ #[schema(example = "FAKE: Features All Kids Erase")]
pub title: String,
}
-#[derive(Serialize)]
+#[derive(Serialize, ToSchema)]
pub struct Projects {
+ #[schema(example = 0u32)]
pub offset: u32,
+ #[schema(example = 10u32)]
pub limit: u32,
+ #[schema(example = 1u32)]
pub total_count: u32,
+ #[schema(example = false)]
pub more: bool,
pub projects: Vec<ProjectEntry>,
}
-#[derive(Serialize)]
+#[derive(Serialize, ToSchema)]
pub struct StatusResponse {
pub ok: bool,
#[serde(skip_serializing_if = "Option::is_none")]
- pub error: Option<String>,
+ pub error: Option<&'static str>,
}