#![allow(clippy::doc_markdown)]
use alloc::borrow::Cow;
use schemars::{json_schema, JsonSchema, Schema, SchemaGenerator};
macro_rules! string_schema {
($name:ty, $desc:expr, {$($field:tt)*}) => {
impl JsonSchema for $name {
fn schema_name() -> Cow<'static, str> {
stringify!($name).into()
}
fn json_schema(_generator: &mut SchemaGenerator) -> Schema {
json_schema!({
"type": "string",
"description": $desc,
$($field)*
})
}
}
};
}
string_schema!(
crate::EmailAddr,
"A validated email address (RFC 5321 local part, IDNA-normalised domain; \
exactly one '@', no whitespace or control characters).",
{
"format": "email",
"pattern": "^[^@\\s]+@[^@\\s]+$",
"maxLength": 254
}
);
string_schema!(
crate::HttpsUrl,
"A validated HTTPS URL (https scheme, host required, no embedded \
credentials).",
{
"format": "uri",
"pattern": "^https://"
}
);
string_schema!(
crate::PhoneE164,
"A validated E.164 phone number, e.g. '+14155552671'.",
{
"pattern": "^\\+[1-9]\\d{1,14}$",
"minLength": 3,
"maxLength": 16
}
);
string_schema!(
crate::CronExpr,
"A validated 5-field cron expression; each field matches \
'[0-9*,/-]+' (e.g. '*/5 * * * *').",
{
"pattern": "^[\\d*,/-]+([\\s]+[\\d*,/-]+){4}$",
"minLength": 9
}
);
string_schema!(
crate::TenantIdSlug,
"A validated tenant ID slug: 3-63 chars of [a-z0-9-], not starting or \
ending with '-', no '..' and no '.lock' suffix.",
{
"pattern": "^[a-z0-9]([a-z0-9-]{1,61}[a-z0-9])?$",
"minLength": 3,
"maxLength": 63
}
);
string_schema!(
crate::LocaleTag,
"A validated BCP 47 locale tag, e.g. 'en', 'en-US', 'es-419' \
(primary subtag 2-3 lowercase letters, max 35 characters).",
{
"pattern": "^[a-z]{2,3}(-[A-Za-z0-9]+)*$",
"maxLength": 35
}
);
string_schema!(
crate::FlagName,
"A validated flag name: snake-case starting with a lowercase letter, \
only [a-z0-9_].",
{
"pattern": "^[a-z][a-z0-9_]*$"
}
);
string_schema!(
crate::BucketName,
"A validated S3 bucket name: 3-63 chars of [a-z0-9.-], not starting or \
ending with '-' or '.', no adjacent dots, never formatted as an IP \
address.",
{
"pattern": "^[a-z0-9]([a-z0-9.-]{1,61}[a-z0-9])?$",
"minLength": 3,
"maxLength": 63
}
);
string_schema!(
crate::ObjectKey,
"A validated S3 object key: non-empty, at most 1024 bytes, no leading \
'/', no '..' traversal segments, no CR/LF or null bytes.",
{
"pattern": "^[^/].*$",
"minLength": 1,
"maxLength": 1024
}
);