Skip to content

Commit 6bd9a03

Browse files
authored
Merge pull request #602 from ben-vargas/fix-antigravity-propertynames
fix: remove propertyNames from JSON schema for Gemini compatibility
2 parents 26fc65b + 1b8cb7b commit 6bd9a03

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

internal/util/gemini_schema.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ func flattenTypeArrays(jsonStr string) string {
296296
func removeUnsupportedKeywords(jsonStr string) string {
297297
keywords := append(unsupportedConstraints,
298298
"$schema", "$defs", "definitions", "const", "$ref", "additionalProperties",
299+
"propertyNames", // Gemini doesn't support property name validation
299300
)
300301
for _, key := range keywords {
301302
for _, p := range findPaths(jsonStr, key) {

internal/util/gemini_schema_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,71 @@ func TestCleanJSONSchemaForGemini_MultipleNonNullTypes(t *testing.T) {
596596
}
597597
}
598598

599+
func TestCleanJSONSchemaForGemini_PropertyNamesRemoval(t *testing.T) {
600+
// propertyNames is used to validate object property names (e.g., must match a pattern)
601+
// Gemini doesn't support this keyword and will reject requests containing it
602+
input := `{
603+
"type": "object",
604+
"properties": {
605+
"metadata": {
606+
"type": "object",
607+
"propertyNames": {
608+
"pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$"
609+
},
610+
"additionalProperties": {
611+
"type": "string"
612+
}
613+
}
614+
}
615+
}`
616+
617+
expected := `{
618+
"type": "object",
619+
"properties": {
620+
"metadata": {
621+
"type": "object"
622+
}
623+
}
624+
}`
625+
626+
result := CleanJSONSchemaForGemini(input)
627+
compareJSON(t, expected, result)
628+
629+
// Verify propertyNames is completely removed
630+
if strings.Contains(result, "propertyNames") {
631+
t.Errorf("propertyNames keyword should be removed, got: %s", result)
632+
}
633+
}
634+
635+
func TestCleanJSONSchemaForGemini_PropertyNamesRemoval_Nested(t *testing.T) {
636+
// Test deeply nested propertyNames (as seen in real Claude tool schemas)
637+
input := `{
638+
"type": "object",
639+
"properties": {
640+
"items": {
641+
"type": "array",
642+
"items": {
643+
"type": "object",
644+
"properties": {
645+
"config": {
646+
"type": "object",
647+
"propertyNames": {
648+
"type": "string"
649+
}
650+
}
651+
}
652+
}
653+
}
654+
}
655+
}`
656+
657+
result := CleanJSONSchemaForGemini(input)
658+
659+
if strings.Contains(result, "propertyNames") {
660+
t.Errorf("Nested propertyNames should be removed, got: %s", result)
661+
}
662+
}
663+
599664
func compareJSON(t *testing.T, expectedJSON, actualJSON string) {
600665
var expMap, actMap map[string]interface{}
601666
errExp := json.Unmarshal([]byte(expectedJSON), &expMap)

0 commit comments

Comments
 (0)