File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
genlm/control/potential/built_in Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -855,6 +855,11 @@ async def parse(self, input: Input):
855
855
while True :
856
856
await input .skip_whitespace ()
857
857
if await input .current_char () == "}" :
858
+ if not self .required_keys .issubset (keys_seen ):
859
+ raise ParseError (
860
+ "Missing keys: "
861
+ + ", " .join (map (json .dumps , self .required_keys ))
862
+ )
858
863
await input .read (1 )
859
864
break
860
865
if not first :
Original file line number Diff line number Diff line change @@ -1553,3 +1553,23 @@ def test_trie_adding_prefix_of_existing():
1553
1553
1554
1554
assert trie .root .children ["b" ].prefix == "ar"
1555
1555
assert trie .root .children ["b" ].accepting
1556
+
1557
+
1558
+ @pytest .mark .asyncio
1559
+ async def test_rejects_if_required_keys_are_missing ():
1560
+ parser = json_schema_parser (
1561
+ {
1562
+ "type" : "object" ,
1563
+ "properties" : {"foo" : {"type" : "string" }, "bar" : {"type" : "number" }},
1564
+ "required" : ["foo" ],
1565
+ }
1566
+ )
1567
+
1568
+ for incomplete in [
1569
+ "{}" ,
1570
+ '{"bar": 0.0}' ,
1571
+ ]:
1572
+ with pytest .raises (ParseError ):
1573
+ await parser .parse_string (incomplete )
1574
+
1575
+ assert await parser .parse_string ('{"foo": "hello"}' ) == {"foo" : "hello" }
You can’t perform that action at this time.
0 commit comments