Skip to content

Commit 0e3c0b1

Browse files
crowecawcawepmog
authored andcommitted
fix: allow minLength of 0 for strings and paths
Signed-off-by: Stephen Crowe <6042774+crowecawcaw@users.noreply.github.com>
1 parent 4c2c253 commit 0e3c0b1

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/openjd/model/v2023_09/_model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,8 +1363,8 @@ class JobStringParameterDefinition(OpenJDModel_v2023_09, JobParameterInterface):
13631363
def _validate_min_length(cls, value: Optional[int]) -> Optional[int]:
13641364
if value is None:
13651365
return value
1366-
if value <= 0:
1367-
raise ValueError("Required: 0 < minLength.")
1366+
if value < 0:
1367+
raise ValueError("Required: 0 <= minLength.")
13681368
return value
13691369

13701370
@field_validator("maxLength")
@@ -1607,8 +1607,8 @@ class JobPathParameterDefinition(OpenJDModel_v2023_09, JobParameterInterface):
16071607
def _validate_min_length(cls, value: Optional[int]) -> Optional[int]:
16081608
if value is None:
16091609
return value
1610-
if value <= 0:
1611-
raise ValueError("Required: 0 < minLength.")
1610+
if value < 0:
1611+
raise ValueError("Required: 0 <= minLength.")
16121612
return value
16131613

16141614
@field_validator("maxLength")

test/openjd/model/v2023_09/test_job_parameters.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ class TestJobStringParameterDefinition:
2626
pytest.param(
2727
{"name": "Foo", "type": "STRING", "default": "some value"}, id="has default"
2828
),
29-
pytest.param(
30-
{"name": "Foo", "type": "STRING", "minLength": 1}, id="smallest min length"
31-
),
29+
pytest.param({"name": "Foo", "type": "STRING", "minLength": 0}, id="minLength zero"),
3230
pytest.param(
3331
{"name": "Foo", "type": "STRING", "maxLength": 1}, id="smallest max length"
3432
),
@@ -215,7 +213,9 @@ def test_parse_success(self, data: dict[str, Any]) -> None:
215213
id="allowedValues item not string",
216214
),
217215
#
218-
pytest.param({"name": "Foo", "type": "STRING", "minLength": 0}, id="0 < min"),
216+
pytest.param(
217+
{"name": "Foo", "type": "STRING", "minLength": -1}, id="negative minLength"
218+
),
219219
pytest.param({"name": "Foo", "type": "STRING", "maxLength": 0}, id="0 < max"),
220220
pytest.param(
221221
{"name": "Foo", "type": "STRING", "minLength": 2, "maxLength": 1}, id="min > max"
@@ -495,7 +495,7 @@ class TestJobPathParameterDefinition:
495495
pytest.param(
496496
{"name": "Foo", "type": "PATH", "default": "some value"}, id="has default"
497497
),
498-
pytest.param({"name": "Foo", "type": "PATH", "minLength": 1}, id="smallest min length"),
498+
pytest.param({"name": "Foo", "type": "PATH", "minLength": 0}, id="minLength zero"),
499499
pytest.param({"name": "Foo", "type": "PATH", "maxLength": 1}, id="smallest max length"),
500500
pytest.param(
501501
{"name": "Foo", "type": "PATH", "allowedValues": ["a"]}, id="has allowedValues"
@@ -709,7 +709,7 @@ def test_parse_success(self, data: dict[str, Any]) -> None:
709709
id="allowedValues item not string",
710710
),
711711
#
712-
pytest.param({"name": "Foo", "type": "PATH", "minLength": 0}, id="0 < min"),
712+
pytest.param({"name": "Foo", "type": "PATH", "minLength": -1}, id="negative minLength"),
713713
pytest.param({"name": "Foo", "type": "PATH", "maxLength": 0}, id="0 < max"),
714714
pytest.param(
715715
{"name": "Foo", "type": "PATH", "minLength": 2, "maxLength": 1}, id="min > max"

0 commit comments

Comments
 (0)