Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
057bbdc
json: support minimum for positive integer values
Apr 30, 2024
d69ccb0
json: fix min 0
Apr 30, 2024
c37c484
json: min + max integer constraints
May 1, 2024
af63f4f
json: handle negative min / max integer bounds
May 1, 2024
a381deb
json: fix missing paren min/max bug
May 1, 2024
f8db478
json: proper paren fix
May 1, 2024
5a86c6f
json: integration test for schemas
May 18, 2024
431edb8
json: fix bounds tests
May 18, 2024
b6b6a6c
Update json-schema-to-grammar.cpp
May 19, 2024
a786c03
Merge remote-tracking branch 'origin/master' into json-bounds2
Jun 8, 2024
931b543
json: fix negative max
Jun 8, 2024
4c1c293
json: fix negative min (w/ more than 1 digit)
Jun 8, 2024
ac2a8f8
Update test-grammar-integration.cpp
Jun 8, 2024
3549702
json: nit: move string rules together
Jun 8, 2024
e933680
json: port min/max integer support to Python & JS
Jun 8, 2024
a0f1904
nit: move + rename _build_min_max_int
Jun 8, 2024
dcc27d1
fix min in [1, 9]
Jun 9, 2024
d1f6791
Update test-grammar-integration.cpp
Jun 9, 2024
cad377d
add C++11-compatible replacement for std::string_view
Jun 9, 2024
d6483a9
add min/max constrained int field to pydantic json schema example
Jun 10, 2024
f03e9b9
Merge remote-tracking branch 'origin/master' into json-bounds2
Jun 12, 2024
6fa7364
Merge remote-tracking branch 'origin/master' into json-bounds2
Jun 22, 2024
948e55e
fix merge
Jun 22, 2024
670d5a6
json: add integration tests for min/max bounds
Jun 22, 2024
9fb8a75
Merge remote-tracking branch 'origin/master' into json-bounds2
Jun 23, 2024
d7d957d
Merge remote-tracking branch 'origin/master' into json-bounds2
Jun 24, 2024
3a80d1e
reshuffle/merge min/max integ test cases
Jun 24, 2024
09a9b75
nits / cleanups
Jun 24, 2024
48f417d
Merge remote-tracking branch 'origin/master' into json-bounds2
Jun 25, 2024
36bf003
defensive code against string out of bounds (apparently different beh…
Jun 25, 2024
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
Prev Previous commit
Next Next commit
json: fix missing paren min/max bug
  • Loading branch information
ochafik committed Jun 6, 2024
commit a381deb1b6be0739acbebe10ea963d007a8cbc69
2 changes: 2 additions & 0 deletions common/json-schema-to-grammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ static void _generate_min_max_int(int min_value, int max_value, std::stringstrea
more_digits(sub_len, sub_len);
} else {
out << "[" << from[i] << "] ";
out << "(";
uniform_range(from_sub, sub_nines);
if (from[i] < to[i] - 1) {
out << " | ";
Expand All @@ -226,6 +227,7 @@ static void _generate_min_max_int(int min_value, int max_value, std::stringstrea
out << " ";
more_digits(sub_len, sub_len);
}
out << ")";
}
if (!to_reached) {
out << " | ";
Expand Down
40 changes: 39 additions & 1 deletion tests/test-json-schema-to-grammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
"maximum": 300
})""",
R"""(
root ::= ([1] [5-9] | [2-9] [0-9] | [1-2] [0-9]{2} | [3] "00") space
root ::= ([1] ([5-9] | [2-9] [0-9]) | [1-2] [0-9]{2} | [3] "00") space
space ::= " "?
)"""
});
Expand Down Expand Up @@ -576,6 +576,44 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
)"""
});

test({
SUCCESS,
"min + max items with min + max values across zero",
R"""({
"items": {
"type": "integer",
"minimum": -122,
"maximum": 207
},
"minItems": 3,
"maxItems": 5
})""",
R"""(
item ::= ("-" ([0-9] | [1-8] [0-9] | [9] [0-9] | "1" [0-1] [0-9] | [2] [0-2]) | [0-9] | [1-8] [0-9] | [9] [0-9] | [1] [0-9]{2} | [2] "0" [0-7]) space
root ::= "[" space item ("," space item){2,4} "]" space
space ::= " "?
)"""
});

test({
SUCCESS,
"min + max items with min + max values",
R"""({
"items": {
"type": "integer",
"minimum": 122,
"maximum": 207
},
"minItems": 3,
"maxItems": 5
})""",
R"""(
item ::= ([1] ([2] ([2-9] | [3-9] [0-9])) | [2] "0" [0-7]) space
root ::= "[" space item ("," space item){2,4} "]" space
space ::= " "?
)"""
});

test({
SUCCESS,
"simple regexp",
Expand Down