@@ -105,9 +105,12 @@ fn adapt_to_json_schema_subset(json: &mut Value) -> Result<()> {
);
}
- const KEYS_TO_REMOVE: [(&str, fn(&Value) -> bool); 5] = [
+ const KEYS_TO_REMOVE: [(&str, fn(&Value) -> bool); 6] = [
("format", |value| value.is_string()),
- ("additionalProperties", |value| value.is_boolean()),
+ // Gemini doesn't support `additionalProperties` in any form (boolean or schema object)
+ ("additionalProperties", |_| true),
+ // Gemini doesn't support `propertyNames`
+ ("propertyNames", |_| true),
("exclusiveMinimum", |value| value.is_number()),
("exclusiveMaximum", |value| value.is_number()),
("optional", |value| value.is_boolean()),
@@ -234,6 +237,28 @@ mod tests {
"format": {},
})
);
+
+ // additionalProperties as an object schema is also unsupported by Gemini
+ let mut json = json!({
+ "type": "object",
+ "properties": {
+ "name": { "type": "string" }
+ },
+ "additionalProperties": { "type": "string" },
+ "propertyNames": { "pattern": "^[A-Za-z]+$" }
+ });
+
+ adapt_to_json_schema_subset(&mut json).unwrap();
+
+ assert_eq!(
+ json,
+ json!({
+ "type": "object",
+ "properties": {
+ "name": { "type": "string" }
+ }
+ })
+ );
}
#[test]