1use serde::{Deserialize, Serialize};
6
7#[derive(
9 Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Serialize, Deserialize,
10)]
11#[serde(transparent)]
12pub struct TenantId(pub u64);
13
14#[cfg(feature = "utoipa")]
18impl<'s> utoipa::ToSchema<'s> for TenantId {
19 fn schema() -> (&'s str, utoipa::openapi::RefOr<utoipa::openapi::Schema>) {
20 ("TenantId", transparent_u64_schema("Tenant identifier."))
21 }
22}
23
24#[derive(
27 Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Serialize, Deserialize,
28)]
29#[serde(transparent)]
30pub struct ProjectId(pub u64);
31
32#[cfg(feature = "utoipa")]
33impl<'s> utoipa::ToSchema<'s> for ProjectId {
34 fn schema() -> (&'s str, utoipa::openapi::RefOr<utoipa::openapi::Schema>) {
35 ("ProjectId", transparent_u64_schema("Project identifier."))
36 }
37}
38
39#[cfg(feature = "utoipa")]
40fn transparent_u64_schema(description: &str) -> utoipa::openapi::RefOr<utoipa::openapi::Schema> {
41 use utoipa::openapi::schema::{ObjectBuilder, SchemaFormat, SchemaType};
42 ObjectBuilder::new()
43 .schema_type(SchemaType::Integer)
44 .format(Some(SchemaFormat::KnownFormat(
45 utoipa::openapi::KnownFormat::Int64,
46 )))
47 .minimum(Some(0.0))
48 .description(Some(description))
49 .into()
50}
51
52#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
55#[serde(transparent)]
56pub struct Namespace(pub String);
57
58#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
60#[serde(transparent)]
61pub struct TypeName(pub String);
62
63impl TypeName {
64 pub fn qualified(ns: &Namespace, label: &str) -> Self {
66 if label.contains('.') {
67 Self(label.to_owned())
69 } else {
70 Self(format!("{}.{}", ns.0, label))
71 }
72 }
73}
74
75#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
77#[serde(transparent)]
78pub struct VertexId(pub String);
79
80#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
82#[serde(transparent)]
83pub struct EdgeId(pub String);
84
85#[cfg(test)]
86mod tests {
87 use super::*;
88
89 #[test]
90 fn qualified_name_prepends_namespace() {
91 let ns = Namespace("Antares".into());
92 assert_eq!(TypeName::qualified(&ns, "Deal").0, "Antares.Deal");
93 }
94
95 #[test]
96 fn qualified_name_is_idempotent() {
97 let ns = Namespace("Antares".into());
98 assert_eq!(TypeName::qualified(&ns, "Antares.Deal").0, "Antares.Deal");
99 }
100}