Skip to content

Commit

Permalink
make the test pass
Browse files Browse the repository at this point in the history
  • Loading branch information
hallettj committed Jan 15, 2025
1 parent dc632e0 commit 60e4ecf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
5 changes: 4 additions & 1 deletion crates/cli/src/introspection/validation_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ fn make_field_type(object_type_name: &str, prop_schema: &Property) -> (Vec<Objec
let mut collected_otds: Vec<ObjectType> = vec![];

match prop_schema {
Property::Object {
properties: None, ..
} => (vec![], Type::ExtendedJSON),
Property::Object {
bson_type: _,
description: _,
required,
properties,
properties: Some(properties),
} => {
let type_prefix = format!("{object_type_name}_");
let (otds, otd_fields): (Vec<Vec<ObjectType>>, Vec<ObjectField>) = properties
Expand Down
32 changes: 22 additions & 10 deletions crates/cli/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ async fn required_field_from_validator_is_non_nullable() -> anyhow::Result<()> {
"title": { "bsonType": "string", "maxLength": 100 },
"author": { "bsonType": "string", "maxLength": 100 },
}
}).await?;
})
.await?;

assert_eq!(
collection_object_type.fields.get(&FieldName::new("title".into())),
collection_object_type
.fields
.get(&FieldName::new("title".into())),
Some(&ObjectField {
r#type: Type::Named {
name: "String".into()
Expand All @@ -31,11 +34,15 @@ async fn required_field_from_validator_is_non_nullable() -> anyhow::Result<()> {
);

assert_eq!(
collection_object_type.fields.get(&FieldName::new("author".into())),
collection_object_type
.fields
.get(&FieldName::new("author".into())),
Some(&ObjectField {
r#type: Type::Nullable { underlying_type: Box::new(Type::Named {
name: "String".into()
}) },
r#type: Type::Nullable {
underlying_type: Box::new(Type::Named {
name: "String".into()
})
},
arguments: Default::default(),
description: Default::default(),
})
Expand All @@ -54,13 +61,18 @@ async fn validator_object_with_no_properties_becomes_extended_json_object() -> a
"properties": {
"reactions": { "bsonType": "object" },
}
}).await?;
})
.await?;

assert_eq!(
collection_object_type.fields.get(&FieldName::new("reactions".into())),
collection_object_type
.fields
.get(&FieldName::new("reactions".into())),
Some(&ObjectField {
r#type: Type::Named {
name: "ExtendedJSON".into()
r#type: Type::Nullable {
underlying_type: Box::new(Type::Named {
name: "ExtendedJSON".into()
})
},
arguments: Default::default(),
description: Default::default(),
Expand Down
19 changes: 10 additions & 9 deletions crates/mongodb-agent-common/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ pub enum Property {
description: Option<String>,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
required: Vec<String>,
properties: IndexMap<String, Property>,
#[serde(skip_serializing_if = "Option::is_none")]
properties: Option<IndexMap<String, Property>>,
},
Array {
#[serde(rename = "bsonType", default = "default_bson_type")]
Expand Down Expand Up @@ -125,7 +126,7 @@ mod test {
bson_type: BsonType::Object,
description: Some("Name of places".to_owned()),
required: vec!["name".to_owned(), "description".to_owned()],
properties: IndexMap::from([
properties: Some(IndexMap::from([
(
"name".to_owned(),
Property::Scalar {
Expand All @@ -142,7 +143,7 @@ mod test {
)
}
)
])
]))
}
);

Expand Down Expand Up @@ -171,7 +172,7 @@ mod test {
bson_type: BsonType::Object,
description: None,
required: vec!["name".to_owned(), "size".to_owned()],
properties: IndexMap::from([
properties: Some(IndexMap::from([
(
"name".to_owned(),
Property::Scalar {
Expand All @@ -186,7 +187,7 @@ mod test {
description: None
}
)
])
]))
}),
}
);
Expand Down Expand Up @@ -253,7 +254,7 @@ mod test {
bson_type: BsonType::Object,
description: None,
required: vec!["xs".to_owned()],
properties: IndexMap::from([
properties: Some(IndexMap::from([
(
"xs".to_owned(),
Property::Scalar {
Expand All @@ -268,7 +269,7 @@ mod test {
description: None
}
),
])
]))
}
)])
}
Expand Down Expand Up @@ -353,7 +354,7 @@ mod test {
bson_type: BsonType::Object,
description: None,
required: vec![],
properties: IndexMap::from([
properties: Some(IndexMap::from([
(
"city".to_owned(),
Property::Scalar {
Expand All @@ -368,7 +369,7 @@ mod test {
description: None,
}
)
])
]))
}
)
]),
Expand Down

0 comments on commit 60e4ecf

Please sign in to comment.