Skip to content

Commit cc70d98

Browse files
authored
Fix map of numbers (#367)
Signed-off-by: Clément Hamada <[email protected]>
1 parent c787920 commit cc70d98

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/analyzer.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ fn resolve_additional_properties(
359359
}
360360
}
361361
"boolean" => Some("bool".to_string()),
362+
"number" => Some(extract_number_type(s)?),
362363
"integer" => Some(extract_integer_type(s)?),
363364
// think the type we get is the value type
364365
x => Some(x.to_upper_camel_case()), // best guess
@@ -650,6 +651,32 @@ mod test {
650651
assert_eq!(map.type_, "Option<BTreeMap<String, BTreeMap<String, String>>>");
651652
}
652653

654+
#[test]
655+
fn map_of_number() {
656+
init();
657+
// as found in aws-lambda-services-aliases
658+
let schema_str = r#"
659+
description: "The routing configuration (https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html#configuring-alias-routing)\nof the alias."
660+
properties:
661+
additionalVersionWeights:
662+
additionalProperties:
663+
type: "number"
664+
type: "object"
665+
type: "object"
666+
"#;
667+
let schema: JSONSchemaProps = serde_yaml::from_str(schema_str).unwrap();
668+
669+
let structs = analyze(schema, "AliasRoutingConfig", Cfg::default()).unwrap().0;
670+
//println!("{:?}", structs);
671+
let root = &structs[0];
672+
assert_eq!(root.name, "AliasRoutingConfig");
673+
assert_eq!(root.level, 0);
674+
// should have a member with a key to the map:
675+
let map = &root.members[0];
676+
assert_eq!(map.name, "additionalVersionWeights");
677+
assert_eq!(map.type_, "Option<BTreeMap<String, f64>>");
678+
}
679+
653680
#[test]
654681
fn empty_preserve_unknown_fields() {
655682
init();

0 commit comments

Comments
 (0)