helm_schema_core/
output_path.rs1use std::collections::BTreeSet;
2
3use crate::YamlPath;
4
5pub const DYNAMIC_MAPPING_VALUE_SEGMENT: &str = "{*}";
8
9#[must_use]
11pub fn values_path_has_descendant(path: &str, sources: &BTreeSet<String>) -> bool {
12 sources
13 .iter()
14 .any(|source| values_path_is_descendant(source, path))
15}
16
17#[must_use]
19pub fn values_path_is_descendant(path: &str, ancestor: &str) -> bool {
20 let path = crate::split_value_path(path);
21 let ancestor = crate::split_value_path(ancestor);
22 path.len() > ancestor.len() && path.starts_with(&ancestor)
23}
24
25#[must_use]
27pub fn append_relative_path(base: &YamlPath, relative: &YamlPath) -> YamlPath {
28 let mut out = base.clone();
29 out.0.extend(relative.0.iter().cloned());
30 out
31}
32
33#[must_use]
35pub fn sequence_item_path(relative_path: &YamlPath) -> YamlPath {
36 let mut path = relative_path.clone();
37 if let Some(last) = path.0.last_mut() {
38 if !last.ends_with("[*]") {
39 last.push_str("[*]");
40 }
41 } else {
42 path.0.push("[*]".to_string());
43 }
44 path
45}
46
47#[must_use]
49pub fn dynamic_mapping_value_path(relative_path: &YamlPath) -> YamlPath {
50 let mut path = relative_path.clone();
51 path.0.push(DYNAMIC_MAPPING_VALUE_SEGMENT.to_string());
52 path
53}