feat(api-types): add utoipa ToSchema and IntoParams derives
This commit is contained in:
@@ -7,3 +7,4 @@ edition = "2021"
|
|||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
uuid = { workspace = true }
|
uuid = { workspace = true }
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
|
utoipa = { version = "5.5.0", features = ["uuid", "chrono"] }
|
||||||
|
|||||||
@@ -1,34 +1,37 @@
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, utoipa::ToSchema)]
|
||||||
pub struct RegisterRequest {
|
pub struct RegisterRequest {
|
||||||
|
/// Username (1-32 chars, alphanumeric + underscore)
|
||||||
pub username: String,
|
pub username: String,
|
||||||
pub email: String,
|
pub email: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, utoipa::ToSchema)]
|
||||||
pub struct LoginRequest {
|
pub struct LoginRequest {
|
||||||
pub email: String,
|
pub email: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, utoipa::ToSchema)]
|
||||||
pub struct CreateThoughtRequest {
|
pub struct CreateThoughtRequest {
|
||||||
|
/// Up to 128 characters
|
||||||
pub content: String,
|
pub content: String,
|
||||||
pub in_reply_to_id: Option<Uuid>,
|
pub in_reply_to_id: Option<Uuid>,
|
||||||
|
/// One of: "public", "followers", "unlisted", "direct"
|
||||||
pub visibility: Option<String>,
|
pub visibility: Option<String>,
|
||||||
pub content_warning: Option<String>,
|
pub content_warning: Option<String>,
|
||||||
pub sensitive: Option<bool>,
|
pub sensitive: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, utoipa::ToSchema)]
|
||||||
pub struct EditThoughtRequest {
|
pub struct EditThoughtRequest {
|
||||||
pub content: String,
|
pub content: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, utoipa::ToSchema)]
|
||||||
pub struct UpdateProfileRequest {
|
pub struct UpdateProfileRequest {
|
||||||
pub display_name: Option<String>,
|
pub display_name: Option<String>,
|
||||||
pub bio: Option<String>,
|
pub bio: Option<String>,
|
||||||
@@ -37,17 +40,18 @@ pub struct UpdateProfileRequest {
|
|||||||
pub custom_css: Option<String>,
|
pub custom_css: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, utoipa::ToSchema)]
|
||||||
pub struct SetTopFriendsRequest {
|
pub struct SetTopFriendsRequest {
|
||||||
|
/// Ordered list of user UUIDs, max 8
|
||||||
pub friend_ids: Vec<Uuid>,
|
pub friend_ids: Vec<Uuid>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, utoipa::ToSchema)]
|
||||||
pub struct CreateApiKeyRequest {
|
pub struct CreateApiKeyRequest {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, utoipa::IntoParams)]
|
||||||
pub struct PaginationQuery {
|
pub struct PaginationQuery {
|
||||||
pub page: Option<u64>,
|
pub page: Option<u64>,
|
||||||
pub per_page: Option<u64>,
|
pub per_page: Option<u64>,
|
||||||
@@ -63,7 +67,7 @@ impl PaginationQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, utoipa::IntoParams)]
|
||||||
pub struct SearchQuery {
|
pub struct SearchQuery {
|
||||||
pub q: String,
|
pub q: String,
|
||||||
pub page: Option<u64>,
|
pub page: Option<u64>,
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ use chrono::{DateTime, Utc};
|
|||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, utoipa::ToSchema)]
|
||||||
pub struct AuthResponse {
|
pub struct AuthResponse {
|
||||||
pub token: String,
|
pub token: String,
|
||||||
pub user: UserResponse,
|
pub user: UserResponse,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Clone)]
|
#[derive(Serialize, Clone, utoipa::ToSchema)]
|
||||||
pub struct UserResponse {
|
pub struct UserResponse {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub username: String,
|
pub username: String,
|
||||||
@@ -20,7 +20,7 @@ pub struct UserResponse {
|
|||||||
pub created_at: DateTime<Utc>,
|
pub created_at: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Clone)]
|
#[derive(Serialize, Clone, utoipa::ToSchema)]
|
||||||
pub struct ThoughtResponse {
|
pub struct ThoughtResponse {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
@@ -38,22 +38,22 @@ pub struct ThoughtResponse {
|
|||||||
pub updated_at: Option<DateTime<Utc>>,
|
pub updated_at: Option<DateTime<Utc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, utoipa::ToSchema)]
|
||||||
pub struct PagedResponse<T: Serialize> {
|
pub struct PagedResponse<T: Serialize + utoipa::ToSchema> {
|
||||||
pub items: Vec<T>,
|
pub items: Vec<T>,
|
||||||
pub total: i64,
|
pub total: i64,
|
||||||
pub page: u64,
|
pub page: u64,
|
||||||
pub per_page: u64,
|
pub per_page: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, utoipa::ToSchema)]
|
||||||
pub struct ApiKeyResponse {
|
pub struct ApiKeyResponse {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub created_at: DateTime<Utc>,
|
pub created_at: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, utoipa::ToSchema)]
|
||||||
pub struct NotificationResponse {
|
pub struct NotificationResponse {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub notification_type: String,
|
pub notification_type: String,
|
||||||
@@ -63,7 +63,15 @@ pub struct NotificationResponse {
|
|||||||
pub created_at: DateTime<Utc>,
|
pub created_at: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, utoipa::ToSchema)]
|
||||||
pub struct ErrorResponse {
|
pub struct ErrorResponse {
|
||||||
pub error: String,
|
pub error: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, utoipa::ToSchema)]
|
||||||
|
pub struct CreatedApiKeyResponse {
|
||||||
|
pub id: Uuid,
|
||||||
|
pub name: String,
|
||||||
|
/// Raw API key — shown only once at creation
|
||||||
|
pub key: String,
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ activitypub-base = { workspace = true }
|
|||||||
postgres-federation = { workspace = true }
|
postgres-federation = { workspace = true }
|
||||||
url = { workspace = true }
|
url = { workspace = true }
|
||||||
activitypub_federation = "0.7.0-beta.11"
|
activitypub_federation = "0.7.0-beta.11"
|
||||||
|
utoipa = { version = "5.5.0", features = ["axum_extras", "uuid", "chrono"] }
|
||||||
|
utoipa-scalar = { version = "0.3.0", features = ["axum"], default-features = false }
|
||||||
|
utoipa-swagger-ui = { version = "9.0.2", features = ["axum", "vendored"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
http-body-util = "0.1"
|
http-body-util = "0.1"
|
||||||
|
|||||||
Reference in New Issue
Block a user