Skip to content

Commit

Permalink
condition include for nicer generated code
Browse files Browse the repository at this point in the history
Signed-off-by: clux <[email protected]>

fmt

Signed-off-by: clux <[email protected]>
  • Loading branch information
clux committed Mar 7, 2024
1 parent d43c4a3 commit 5ac0ce2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ libc = "0.2.153"

[dependencies.k8s-openapi]
version = "0.21.1"
default-features = false
features = ["latest"]

[dependencies.kube]
Expand All @@ -55,5 +54,4 @@ typed-builder = "0.18.1"

[dev-dependencies.k8s-openapi]
version = "0.21.1"
default-features = false
features = ["latest", "schemars"]
2 changes: 1 addition & 1 deletion src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ fn extract_container(
let (mut array_type, recurse_level) = array_recurse_for_type(value, stack, key, 1)?;
trace!("got array {} for {} in level {}", array_type, key, recurse_level);
if !cfg.no_condition && key == "conditions" && is_conditions(value) {
array_type = "Vec<k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition>".into();
array_type = "Vec<Condition>".into();
} else {
array_recurse_level.insert(key.clone(), recurse_level);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ impl Kopium {
if results.iter().any(|o| o.uses_date()) {
println!("use chrono::naive::NaiveDate;");
}
if results.iter().any(|o| o.uses_conditions()) {
println!("use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition;");
}
if results.iter().any(|o| o.uses_int_or_string()) {
println!("use k8s_openapi::apimachinery::pkg::util::intstr::IntOrString;");
}
Expand Down
4 changes: 4 additions & 0 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ impl Container {
self.members.iter().any(|m| m.type_.contains("HashMap"))
}

pub fn uses_conditions(&self) -> bool {
self.members.iter().any(|m| m.type_.contains("Vec<Condition>"))
}

pub fn uses_datetime(&self) -> bool {
self.members.iter().any(|m| m.type_.contains("DateTime"))
}
Expand Down

0 comments on commit 5ac0ce2

Please sign in to comment.