Skip to content

Commit

Permalink
Make repetitions lower bound explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonwillard committed Oct 9, 2024
1 parent 5df5ac0 commit 6fc2cc4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/json_schema/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ fn parse_string_type(obj: &serde_json::Map<String, Value>) -> Result<String> {
.map_or("".to_string(), |n| format!("{}", n));
let formatted_min = min_items
.and_then(Value::as_u64)
.map_or("".to_string(), |n| format!("{}", n));
.map_or("0".to_string(), |n| format!("{}", n));

Ok(format!(
r#""{}{{{},{}}}""#,
Expand Down Expand Up @@ -416,14 +416,14 @@ fn parse_number_type(obj: &serde_json::Map<String, Value>) -> Result<String> {
let fraction_quantifier = match (min_digits_fraction, max_digits_fraction) {
(Some(min), Some(max)) => format!("{{{},{}}}", min, max),
(Some(min), None) => format!("{{{},}}", min),
(None, Some(max)) => format!("{{,{}}}", max),
(None, Some(max)) => format!("{{0,{}}}", max),
(None, None) => "+".to_string(),
};

let exponent_quantifier = match (min_digits_exponent, max_digits_exponent) {
(Some(min), Some(max)) => format!("{{{},{}}}", min, max),
(Some(min), None) => format!("{{{},}}", min),
(None, Some(max)) => format!("{{,{}}}", max),
(None, Some(max)) => format!("{{0,{}}}", max),
(None, None) => "+".to_string(),
};

Expand All @@ -448,7 +448,7 @@ fn parse_integer_type(obj: &serde_json::Map<String, Value>) -> Result<String> {
let quantifier = match (min_digits, max_digits) {
(Some(min), Some(max)) => format!("{{{},{}}}", min, max),
(Some(min), None) => format!("{{{},}}", min),
(None, Some(max)) => format!("{{,{}}}", max),
(None, Some(max)) => format!("{{0,{}}}", max),
(None, None) => "*".to_string(),
};

Expand Down
4 changes: 2 additions & 2 deletions tests/fsm/test_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_match_number(pattern, does_match):
# String with maximum length
(
{"title": "Foo", "type": "string", "maxLength": 3},
f'"{STRING_INNER}{{,3}}"',
f'"{STRING_INNER}{{0,3}}"',
[('"ab"', True), ('"a""', False), ('"abcd"', False)],
),
# String with minimum length
Expand Down Expand Up @@ -283,7 +283,7 @@ def test_match_number(pattern, does_match):
},
"required": ["count"],
},
'\\{[ ]?"count"[ ]?:[ ]?(-)?(0|[1-9][0-9]{,2})[ ]?\\}',
'\\{[ ]?"count"[ ]?:[ ]?(-)?(0|[1-9][0-9]{0,2})[ ]?\\}',
[('{ "count": 100 }', True), ('{ "count": 1000 }', False)],
),
# integer with minimum and maximum digits
Expand Down

0 comments on commit 6fc2cc4

Please sign in to comment.