use serde::{Deserialize, Serialize};
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Serialize, Deserialize,
)]
#[serde(transparent)]
pub struct TenantId(pub u64);
#[cfg(feature = "utoipa")]
impl<'s> utoipa::ToSchema<'s> for TenantId {
fn schema() -> (&'s str, utoipa::openapi::RefOr<utoipa::openapi::Schema>) {
("TenantId", transparent_u64_schema("Tenant identifier."))
}
}
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Serialize, Deserialize,
)]
#[serde(transparent)]
pub struct ProjectId(pub u64);
#[cfg(feature = "utoipa")]
impl<'s> utoipa::ToSchema<'s> for ProjectId {
fn schema() -> (&'s str, utoipa::openapi::RefOr<utoipa::openapi::Schema>) {
("ProjectId", transparent_u64_schema("Project identifier."))
}
}
#[cfg(feature = "utoipa")]
fn transparent_u64_schema(description: &str) -> utoipa::openapi::RefOr<utoipa::openapi::Schema> {
use utoipa::openapi::schema::{ObjectBuilder, SchemaFormat, SchemaType};
ObjectBuilder::new()
.schema_type(SchemaType::Integer)
.format(Some(SchemaFormat::KnownFormat(
utoipa::openapi::KnownFormat::Int64,
)))
.minimum(Some(0.0))
.description(Some(description))
.into()
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct Namespace(pub String);
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct TypeName(pub String);
impl TypeName {
pub fn qualified(ns: &Namespace, label: &str) -> Self {
if label.contains('.') {
Self(label.to_owned())
} else {
Self(format!("{}.{}", ns.0, label))
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct VertexId(pub String);
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct EdgeId(pub String);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn qualified_name_prepends_namespace() {
let ns = Namespace("Antares".into());
assert_eq!(TypeName::qualified(&ns, "Deal").0, "Antares.Deal");
}
#[test]
fn qualified_name_is_idempotent() {
let ns = Namespace("Antares".into());
assert_eq!(TypeName::qualified(&ns, "Antares.Deal").0, "Antares.Deal");
}
}