use serde::{Deserialize, Serialize};
use super::ExtensionMap;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
pub struct ExtensionDefinition {
pub id: String,
pub namespace: String,
pub version: String,
pub owner: String,
pub scope: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub semantics: Option<String>,
#[serde(default, flatten)]
pub extensions: ExtensionMap,
}
pub fn is_reserved_root_field(key: &str) -> bool {
matches!(
key,
"dpcsVersion"
| "id"
| "name"
| "version"
| "metadata"
| "interface"
| "graph"
| "steps"
| "contractReferences"
| "dataFlow"
| "controlFlow"
| "execution"
| "scheduling"
| "qualityGates"
| "failureSemantics"
| "lineage"
| "compatibility"
| "security"
| "governance"
)
}
pub fn is_valid_extension_namespace(key: &str) -> bool {
let key = key.trim();
if key.is_empty() {
return false;
}
if key.starts_with("x-") || key.starts_with("X-") {
return key.len() > 2
&& key
.chars()
.all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '_' | '.'));
}
if key.contains("://") {
return key.split("://").nth(1).is_some_and(|rest| !rest.is_empty());
}
if let Some((ns, local)) = key.split_once(':') {
return !ns.is_empty()
&& !local.is_empty()
&& ns
.chars()
.all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '_' | '.'))
&& local
.chars()
.all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '_' | '.'));
}
false
}