Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing tests for CephCluster #212

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ fn analyze_(
let c = extract_container(extra_props, stack, &mut array_recurse_level, level, schema, cfg)?;
results.push(c);
} else if !dict_type.is_empty() {
warn!("not generating type {} - using {} map", current, dict_type);
if schema.x_kubernetes_preserve_unknown_fields.unwrap_or(false) {
warn!("preserve map")
} else {
warn!("not generating type {} - using {} map", current, dict_type);
}
return Ok(()); // no members here - it'll be inlined
}
} else {
Expand Down Expand Up @@ -1144,6 +1148,40 @@ type: object
);
}

#[test]
fn map_of_preserve_unknown_objects() {
init();
// example from ceph cluster crd
let schema_str = r#"
properties:
annotations:
additionalProperties:
additionalProperties:
type: string
description: Annotations are annotations
type: object
description: The annotations-related configuration to add/set on each Pod related object.
nullable: true
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
"#;

let schema: JSONSchemaProps = serde_yaml::from_str(schema_str).unwrap();
let structs = analyze(schema, "CephCluster", Cfg::default()).unwrap().0;
println!("got {:?}", structs);
let root = &structs[0];
assert_eq!(root.name, "CephCluster");
assert_eq!(root.level, 0);
assert_eq!(root.is_enum, false);
assert_eq!(&root.members[0].name, "annotations");
assert_eq!(
&root.members[0].type_,
// TODO: unclear what is the best type to have here
"Option<BTreeMap<String, BTreeMap<String, CephClusterAnnotations>>>"
);
}

#[test]
fn nested_properties_in_additional_properties() {
init();
Expand Down
Loading