Skip to content

Commit 99410a3

Browse files
committed
even more .to_upper_camel_case()
Signed-off-by: Sebastian Hoß <[email protected]>
1 parent 8dfa70c commit 99410a3

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/analyzer.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct Config {
2323
pub fn analyze(schema: JSONSchemaProps, kind: &str, cfg: Config) -> Result<Output> {
2424
let mut res = vec![];
2525

26-
analyze_(&schema, "", &kind.to_upper_camel_case(), 0, &mut res, &cfg)?;
26+
analyze_(&schema, "", kind, 0, &mut res, &cfg)?;
2727
Ok(Output(res))
2828
}
2929

@@ -45,6 +45,8 @@ fn analyze_(
4545
let props = schema.properties.clone().unwrap_or_default();
4646
let mut array_recurse_level: HashMap<String, u8> = Default::default();
4747

48+
let camel_cased_stack = &stack.to_upper_camel_case();
49+
4850
// create a Container if we have a container type:
4951
//trace!("analyze_ with {} + {}", current, stack);
5052
if schema.type_.clone().unwrap_or_default() == "object" {
@@ -55,29 +57,29 @@ fn analyze_(
5557
// object with additionalProperties == map
5658
if let Some(extra_props) = &s.properties {
5759
// map values is an object with properties
58-
debug!("Generating map struct for {} (under {})", current, stack);
59-
let c = extract_container(extra_props, stack, &mut array_recurse_level, level, schema, cfg)?;
60+
debug!("Generating map struct for {} (under {})", current, camel_cased_stack);
61+
let c = extract_container(extra_props, camel_cased_stack, &mut array_recurse_level, level, schema, cfg)?;
6062
results.push(c);
6163
} else if dict_type == "object" {
6264
// recurse to see if we eventually find properties
6365
debug!(
6466
"Recursing into nested additional properties for {} (under {})",
65-
current, stack
67+
current, camel_cased_stack
6668
);
67-
analyze_(s, current, stack, level, results, cfg)?;
69+
analyze_(s, current, camel_cased_stack, level, results, cfg)?;
6870
} else if !dict_type.is_empty() {
6971
warn!("not generating type {} - using {} map", current, dict_type);
7072
return Ok(()); // no members here - it'll be inlined
7173
}
7274
} else {
7375
// else, regular properties only
74-
debug!("Generating struct for {} (under {})", current, stack);
76+
debug!("Generating struct for {} (under {})", current, camel_cased_stack);
7577
// initial analysis of properties (we do not recurse here, we need to find members first)
7678
if props.is_empty() && schema.x_kubernetes_preserve_unknown_fields.unwrap_or(false) {
7779
warn!("not generating type {} - using map", current);
7880
return Ok(());
7981
}
80-
let c = extract_container(&props, stack, &mut array_recurse_level, level, schema, cfg)?;
82+
let c = extract_container(&props, camel_cased_stack, &mut array_recurse_level, level, schema, cfg)?;
8183
results.push(c);
8284
}
8385
}
@@ -91,10 +93,10 @@ fn analyze_(
9193
// again; additionalProperties XOR properties
9294
let extras = if let Some(JSONSchemaPropsOrBool::Schema(s)) = schema.additional_properties.as_ref() {
9395
let extra_props = s.properties.clone().unwrap_or_default();
94-
find_containers(&extra_props, stack, &mut array_recurse_level, level, schema, cfg)?
96+
find_containers(&extra_props, camel_cased_stack, &mut array_recurse_level, level, schema, cfg)?
9597
} else {
9698
// regular properties only
97-
find_containers(&props, stack, &mut array_recurse_level, level, schema, cfg)?
99+
find_containers(&props, camel_cased_stack, &mut array_recurse_level, level, schema, cfg)?
98100
};
99101
results.extend(extras);
100102

src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,10 @@ impl Kopium {
308308
}
309309
} else {
310310
self.print_derives(s, &structs);
311-
let spec_trimmed_name = s.name.as_str().replace(&format!("{}Spec", kind), kind);
311+
let spec_trimmed_name = s.name.as_str().replace(
312+
&format!("{}Spec", kind.to_upper_camel_case()),
313+
&kind.to_upper_camel_case(),
314+
);
312315
if s.is_enum {
313316
println!("pub enum {} {{", spec_trimmed_name);
314317
} else {
@@ -324,7 +327,10 @@ impl Kopium {
324327
for annot in &m.extra_annot {
325328
println!(" {}", annot);
326329
}
327-
let spec_trimmed_type = m.type_.as_str().replace(&format!("{}Spec", kind), kind);
330+
let spec_trimmed_type = m.type_.as_str().replace(
331+
&format!("{}Spec", kind.to_upper_camel_case()),
332+
&kind.to_upper_camel_case(),
333+
);
328334
if s.is_enum {
329335
// NB: only supporting plain enumerations atm, not oneOf
330336
println!(" {},", name);

0 commit comments

Comments
 (0)