diff --git a/crates/cli/src/introspection/validation_schema.rs b/crates/cli/src/introspection/validation_schema.rs index 4328efc3..2fa76cfb 100644 --- a/crates/cli/src/introspection/validation_schema.rs +++ b/crates/cli/src/introspection/validation_schema.rs @@ -150,11 +150,14 @@ fn make_field_type(object_type_name: &str, prop_schema: &Property) -> (Vec = 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) = properties diff --git a/crates/cli/src/tests.rs b/crates/cli/src/tests.rs index da200377..876721f7 100644 --- a/crates/cli/src/tests.rs +++ b/crates/cli/src/tests.rs @@ -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() @@ -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(), }) @@ -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(), diff --git a/crates/mongodb-agent-common/src/schema.rs b/crates/mongodb-agent-common/src/schema.rs index 26fd6845..17122637 100644 --- a/crates/mongodb-agent-common/src/schema.rs +++ b/crates/mongodb-agent-common/src/schema.rs @@ -28,7 +28,8 @@ pub enum Property { description: Option, #[serde(skip_serializing_if = "Vec::is_empty", default)] required: Vec, - properties: IndexMap, + #[serde(skip_serializing_if = "Option::is_none")] + properties: Option>, }, Array { #[serde(rename = "bsonType", default = "default_bson_type")] @@ -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 { @@ -142,7 +143,7 @@ mod test { ) } ) - ]) + ])) } ); @@ -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 { @@ -186,7 +187,7 @@ mod test { description: None } ) - ]) + ])) }), } ); @@ -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 { @@ -268,7 +269,7 @@ mod test { description: None } ), - ]) + ])) } )]) } @@ -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 { @@ -368,7 +369,7 @@ mod test { description: None, } ) - ]) + ])) } ) ]),