Skip to main content

agentics_domain/models/
mod.rs

1//! Shared API model types used by backend crates and mirrored by the frontend schemas.
2//!
3//! Response DTO policy: optional response fields should serialize absent values
4//! by using `#[serde(skip_serializing_if = "Option::is_none")]`. The public JSON
5//! contract avoids explicit `null` fields so generated frontend schemas can map
6//! these fields to `field?: T`. Use explicit `null` only when the API semantics
7//! require distinguishing "present but empty" from "not present", and document
8//! that exception next to the field.
9
10pub mod auth;
11pub mod challenge;
12pub mod challenge_creation;
13pub mod evaluation;
14pub mod github;
15pub mod hashes;
16pub mod ids;
17pub mod images;
18pub mod localization;
19pub mod names;
20pub mod paths;
21pub mod pioneer_codes;
22pub mod request;
23pub mod urls;
24
25#[cfg(test)]
26mod contract_tests;
27
28use serde::{Deserialize, Serialize};
29
30use agentics_error::ServiceErrorCode;
31
32pub use agentics_error::ErrorDetail;
33
34/// Standard error response shape used by all API extractors and handlers.
35#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
36pub struct ErrorResponse {
37    pub error: ErrorBody,
38}
39
40/// Standard nested API error body.
41#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
42pub struct ErrorBody {
43    pub code: ServiceErrorCode,
44    pub message: String,
45    #[serde(default, skip_serializing_if = "Vec::is_empty")]
46    pub details: Vec<ErrorDetail>,
47}
48
49/// Health-check response returned by the API server.
50#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
51pub struct HealthResponse {
52    pub status: String,
53    pub service: String,
54    pub environment: String,
55    pub database: DatabaseHealth,
56}
57
58/// Database portion of the health-check response.
59#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
60pub struct DatabaseHealth {
61    pub connected: bool,
62    pub current_time: String,
63}
64
65/// Generic response for endpoints that only need to return an id.
66#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
67pub struct IdOnlyResponse {
68    pub id: String,
69}