common/json-schema : fix GBNF grammar generation for empty object schemas (#28279)

This commit is contained in:
Sergey Sklyarov
2026-09-03 15:37:50 -05:00
committed by GitHub
parent 95ef7fc160
commit c5a5535e6e
3 changed files with 8 additions and 1 deletions
+4
View File
@@ -748,6 +748,10 @@ private:
optional_props.push_back("*");
}
if (required_props.empty() && optional_props.empty()) {
return "\"{\" space \"}\"";
}
std::string rule = "\"{\" space ";
for (size_t i = 0; i < required_props.size(); i++) {
if (i > 0) {
+3
View File
@@ -734,6 +734,9 @@ class SchemaConverter:
)
optional_props.append("*")
if not required_props and not optional_props:
return '"{" space "}"'
rule = '"{" space '
rule += ' "," space '.join(prop_kv_rule_names[k] for k in required_props)
+1 -1
View File
@@ -994,7 +994,7 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
"additionalProperties": false
})""",
R"""(
root ::= "{" space space "}"
root ::= "{" space "}"
space ::= | " " | "\n"{1,2} [ \t]{0,20}
)"""
});