| use codex_utils_path_uri::LegacyAppPathString; |
| use codex_utils_path_uri::PathUri; |
| use schemars::JsonSchema; |
| use serde::Deserialize; |
| use serde::Serialize; |
| use ts_rs::TS; |
|
|
| |
| #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, TS)] |
| #[serde(rename_all = "camelCase")] |
| #[ts(export_to = "v2/")] |
| pub struct SelectedCapabilityRoot { |
| |
| pub id: String, |
| |
| pub location: CapabilityRootLocation, |
| } |
|
|
| |
| #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, TS)] |
| #[serde(tag = "type", rename_all = "camelCase")] |
| #[ts(tag = "type")] |
| #[ts(export_to = "v2/")] |
| pub enum CapabilityRootLocation { |
| |
| Environment { |
| #[serde(rename = "environmentId")] |
| #[ts(rename = "environmentId")] |
| environment_id: String, |
| |
| #[serde(deserialize_with = "deserialize_path_uri_from_api_path")] |
| #[schemars(with = "String")] |
| #[ts(type = "string")] |
| path: PathUri, |
| }, |
| } |
|
|
| fn deserialize_path_uri_from_api_path<'de, D>(deserializer: D) -> Result<PathUri, D::Error> |
| where |
| D: serde::Deserializer<'de>, |
| { |
| let path = LegacyAppPathString::deserialize(deserializer)?; |
| if let Ok(path_uri) = PathUri::parse(path.as_str()) { |
| return Ok(path_uri); |
| } |
| path.try_into().map_err(serde::de::Error::custom) |
| } |
|
|
| #[cfg(test)] |
| #[path = "capabilities_tests.rs"] |
| mod tests; |
|
|