Skip to main content

cognee_http_server/dto/
configuration.rs

1//! DTOs for `/api/v1/configuration/*` per `routers/configuration.md §4`.
2
3use serde::{Deserialize, Serialize};
4use utoipa::ToSchema;
5use uuid::Uuid;
6
7/// Body for `POST /store_user_configuration`. Mirrors Python's
8/// `StorePrincipalConfigurationPayloadDTO` — JSON body, **not** multipart.
9///
10/// Inherits `InDTO` in Python — wire is camelCase per Decision 10. All fields
11/// are single-word, so the rename has no current wire effect; the attribute
12/// is kept for forward consistency.
13#[derive(Debug, Clone, Deserialize, ToSchema)]
14#[serde(rename_all = "camelCase")]
15pub struct StorePrincipalConfigurationPayloadDTO {
16    pub name: String,
17    pub config: serde_json::Value,
18}
19
20/// Response shape for `GET /get_user_configuration/`. Mixed snake/camel keys
21/// per `routers/configuration.md §4` (`PrincipalConfiguration.to_json()`).
22#[derive(Debug, Clone, Serialize, ToSchema)]
23pub struct PrincipalConfigurationDTO {
24    pub id: Uuid,
25    #[serde(rename = "ownerId")]
26    pub owner_id: Uuid,
27    pub name: String,
28    pub configuration: serde_json::Value,
29    #[serde(rename = "createdAt")]
30    pub created_at: chrono::DateTime<chrono::Utc>,
31    #[serde(rename = "updatedAt")]
32    pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
33}
34
35#[cfg(test)]
36#[allow(
37    clippy::unwrap_used,
38    clippy::expect_used,
39    reason = "test code — panics are acceptable failures"
40)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn dto_serializes_with_camel_and_snake_keys() {
46        let dto = PrincipalConfigurationDTO {
47            id: Uuid::nil(),
48            owner_id: Uuid::nil(),
49            name: "default".into(),
50            configuration: serde_json::json!({}),
51            created_at: chrono::Utc::now(),
52            updated_at: None,
53        };
54        let s = serde_json::to_string(&dto).expect("serialize");
55        assert!(s.contains(r#""id":"#));
56        assert!(s.contains(r#""ownerId":"#));
57        assert!(s.contains(r#""name":"default""#));
58        assert!(s.contains(r#""configuration":"#));
59        assert!(s.contains(r#""createdAt":"#));
60        assert!(s.contains(r#""updatedAt":null"#));
61        assert!(!s.contains(r#""owner_id":"#));
62    }
63}