scim_server/schema/
types.rs

1//! Core schema type definitions for SCIM resources.
2//!
3//! This module contains the fundamental data structures that define SCIM schemas,
4//! attribute definitions, and their characteristics as specified in RFC 7643.
5
6use serde::{Deserialize, Serialize};
7
8/// A SCIM schema definition.
9///
10/// Represents a complete schema with its metadata and attribute definitions.
11/// Each schema defines the structure and validation rules for a specific
12/// resource type like User or Group.
13#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct Schema {
15    /// Unique schema identifier (URI)
16    pub id: String,
17    /// Human-readable schema name
18    pub name: String,
19    /// Schema description
20    pub description: String,
21    /// List of attribute definitions
22    pub attributes: Vec<AttributeDefinition>,
23}
24
25/// Definition of a SCIM attribute.
26///
27/// Defines all characteristics of an attribute including type,
28/// constraints, and validation rules.
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(rename_all = "camelCase")]
31pub struct AttributeDefinition {
32    /// Attribute name
33    pub name: String,
34    /// Data type of the attribute
35    #[serde(rename = "type")]
36    pub data_type: AttributeType,
37    /// Whether this attribute can have multiple values
38    #[serde(rename = "multiValued")]
39    pub multi_valued: bool,
40    /// Whether this attribute is required
41    pub required: bool,
42    /// Whether string comparison is case-sensitive
43    #[serde(rename = "caseExact")]
44    pub case_exact: bool,
45    /// Mutability characteristics
46    pub mutability: Mutability,
47    /// Uniqueness constraints
48    pub uniqueness: Uniqueness,
49    /// Allowed values for string attributes
50    #[serde(rename = "canonicalValues", default)]
51    pub canonical_values: Vec<String>,
52    /// Sub-attributes for complex types
53    #[serde(rename = "subAttributes", default)]
54    pub sub_attributes: Vec<AttributeDefinition>,
55    /// How the attribute is returned in responses
56    #[serde(default)]
57    pub returned: Option<String>,
58}
59
60impl Default for AttributeDefinition {
61    fn default() -> Self {
62        Self {
63            name: String::new(),
64            data_type: AttributeType::String,
65            multi_valued: false,
66            required: false,
67            case_exact: false,
68            mutability: Mutability::ReadWrite,
69            uniqueness: Uniqueness::None,
70            canonical_values: Vec::new(),
71            sub_attributes: Vec::new(),
72            returned: None,
73        }
74    }
75}
76
77/// SCIM attribute data types.
78///
79/// Represents the valid data types for SCIM attributes as defined in RFC 7643.
80#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
81#[serde(rename_all = "camelCase")]
82pub enum AttributeType {
83    /// String value
84    String,
85    /// Boolean value
86    Boolean,
87    /// Decimal number
88    Decimal,
89    /// Integer number
90    Integer,
91    /// DateTime in RFC3339 format
92    DateTime,
93    /// Binary data (base64 encoded)
94    Binary,
95    /// URI reference
96    Reference,
97    /// Complex attribute with sub-attributes
98    Complex,
99}
100
101impl Default for AttributeType {
102    fn default() -> Self {
103        Self::String
104    }
105}
106
107/// Attribute mutability characteristics.
108///
109/// Defines whether and how an attribute can be modified.
110#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
111#[serde(rename_all = "camelCase")]
112pub enum Mutability {
113    /// Read-only attribute (managed by server)
114    ReadOnly,
115    /// Read-write attribute (can be modified by clients)
116    ReadWrite,
117    /// Immutable attribute (set once, never modified)
118    Immutable,
119    /// Write-only attribute (passwords, etc.)
120    WriteOnly,
121}
122
123impl Default for Mutability {
124    fn default() -> Self {
125        Self::ReadWrite
126    }
127}
128
129/// Attribute uniqueness constraints.
130///
131/// Defines the scope of uniqueness for attribute values.
132#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
133#[serde(rename_all = "camelCase")]
134pub enum Uniqueness {
135    /// No uniqueness constraint
136    None,
137    /// Unique within the server
138    Server,
139    /// Globally unique
140    Global,
141}
142
143impl Default for Uniqueness {
144    fn default() -> Self {
145        Self::None
146    }
147}