diff --git a/common/json-schema-to-grammar.cpp b/common/json-schema-to-grammar.cpp index 0aee51b26e8..a7a18857d71 100644 --- a/common/json-schema-to-grammar.cpp +++ b/common/json-schema-to-grammar.cpp @@ -748,6 +748,10 @@ class common_schema_converter { 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) { diff --git a/examples/json_schema_to_grammar.py b/examples/json_schema_to_grammar.py index 83abd259da5..02b7ef15ae9 100755 --- a/examples/json_schema_to_grammar.py +++ b/examples/json_schema_to_grammar.py @@ -734,6 +734,9 @@ def _build_object_rule(self, properties: List[Tuple[str, Any]], required: Set[st ) 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) diff --git a/tests/test-json-schema-to-grammar.cpp b/tests/test-json-schema-to-grammar.cpp index 214dbe1993b..2a1b6348c95 100755 --- a/tests/test-json-schema-to-grammar.cpp +++ b/tests/test-json-schema-to-grammar.cpp @@ -994,7 +994,7 @@ static void test_all(const std::string & lang, std::function