Skip to content

Commit 4abe6e1

Browse files
ClemaXclux
andauthored
Fix nested additional properties with properties inside (#366)
Signed-off-by: Clément Hamada <[email protected]> Co-authored-by: Eirik A <[email protected]>
1 parent 728e335 commit 4abe6e1

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/analyzer.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ fn analyze_(
5858
debug!("Generating map struct for {} (under {})", current, stack);
5959
let c = extract_container(extra_props, stack, &mut array_recurse_level, level, schema, cfg)?;
6060
results.push(c);
61+
} else if dict_type == "object" {
62+
// recurse to see if we eventually find properties
63+
debug!(
64+
"Recursing into nested additional properties for {} (under {})",
65+
current, stack
66+
);
67+
analyze_(s, current, stack, level, results, cfg)?;
6168
} else if !dict_type.is_empty() {
6269
warn!("not generating type {} - using {} map", current, dict_type);
6370
return Ok(()); // no members here - it'll be inlined
@@ -1449,4 +1456,51 @@ type: object
14491456
let structs = analyze(schema, "postgresql", Cfg::default()).unwrap().0;
14501457
assert_eq!(structs[0].members[0].type_, "PostgresqlProp");
14511458
}
1459+
1460+
#[test]
1461+
fn nested_additional_properties_object() {
1462+
init();
1463+
1464+
// as found in rook-cephcluster
1465+
let schema_str = r#"
1466+
properties:
1467+
cephConfigFromSecret:
1468+
additionalProperties:
1469+
additionalProperties:
1470+
description: "SecretKeySelector selects a key of a Secret."
1471+
properties:
1472+
key:
1473+
description: "The key of the secret to select from. Must be a valid secret key."
1474+
type: "string"
1475+
name:
1476+
default: ""
1477+
description: "Name of the referent.\nThis field is effectively required, but due to backwards compatibility is\nallowed to be empty. Instances of this type with an empty value here are\nalmost certainly wrong.\nMore info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names"
1478+
type: "string"
1479+
optional:
1480+
description: "Specify whether the Secret or its key must be defined"
1481+
type: "boolean"
1482+
required:
1483+
- "key"
1484+
type: "object"
1485+
x-kubernetes-map-type: "atomic"
1486+
type: "object"
1487+
description: "CephConfigFromSecret works exactly like CephConfig but takes config value from Secret Key reference."
1488+
nullable: true
1489+
type: "object"
1490+
type: object
1491+
"#;
1492+
1493+
let schema: JSONSchemaProps = serde_yaml::from_str(schema_str).unwrap();
1494+
1495+
let structs = analyze(schema, "CephClusterSpec", Cfg::default()).unwrap().0;
1496+
1497+
// debug!("got: {:#?}", structs);
1498+
1499+
assert_eq!(structs.len(), 2);
1500+
assert_eq!(
1501+
structs[0].members[0].type_,
1502+
"Option<BTreeMap<String, BTreeMap<String, CephClusterSpecCephConfigFromSecret>>>"
1503+
);
1504+
assert_eq!(structs[1].name, "CephClusterSpecCephConfigFromSecret");
1505+
}
14521506
}

0 commit comments

Comments
 (0)