Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions common/json-schema-to-grammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions examples/json_schema_to_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/test-json-schema-to-grammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)"""
});
Expand Down
Loading