Skip to content

Commit

Permalink
Failing tests for CephCluter #202
Browse files Browse the repository at this point in the history
Signed-off-by: clux <[email protected]>
  • Loading branch information
clux committed Mar 16, 2024
1 parent 503c3a6 commit 9850809
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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 @@ -1045,6 +1049,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

0 comments on commit 9850809

Please sign in to comment.