Skip to content

Commit 96a5291

Browse files
committed
Fixed that min/max items/length/properties can be float
1 parent f235717 commit 96a5291

File tree

6 files changed

+8
-39
lines changed

6 files changed

+8
-39
lines changed

CHANGELOG.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
=== UNRELEASED
22

33
* Updated test suite
4-
* Fixed detecting when infinity is reqched with multipleOf
4+
* Fixed detecting when infinity is reached with multipleOf
5+
* Fixed that min/max items/lenght/properties can be float
56

67
=== 2.20.0 (2024-06-15)
78

fastjsonschema/draft04.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,15 @@ def generate_not(self):
223223
def generate_min_length(self):
224224
with self.l('if isinstance({variable}, str):'):
225225
self.create_variable_with_length()
226-
if not isinstance(self._definition['minLength'], int):
226+
if not isinstance(self._definition['minLength'], (int, float)):
227227
raise JsonSchemaDefinitionException('minLength must be a number')
228228
with self.l('if {variable}_len < {minLength}:'):
229229
self.exc('{name} must be longer than or equal to {minLength} characters', rule='minLength')
230230

231231
def generate_max_length(self):
232232
with self.l('if isinstance({variable}, str):'):
233233
self.create_variable_with_length()
234-
if not isinstance(self._definition['maxLength'], int):
234+
if not isinstance(self._definition['maxLength'], (int, float)):
235235
raise JsonSchemaDefinitionException('maxLength must be a number')
236236
with self.l('if {variable}_len > {maxLength}:'):
237237
self.exc('{name} must be shorter than or equal to {maxLength} characters', rule='maxLength')
@@ -328,7 +328,7 @@ def generate_multiple_of(self):
328328
def generate_min_items(self):
329329
self.create_variable_is_list()
330330
with self.l('if {variable}_is_list:'):
331-
if not isinstance(self._definition['minItems'], int):
331+
if not isinstance(self._definition['minItems'], (int, float)):
332332
raise JsonSchemaDefinitionException('minItems must be a number')
333333
self.create_variable_with_length()
334334
with self.l('if {variable}_len < {minItems}:'):
@@ -337,7 +337,7 @@ def generate_min_items(self):
337337
def generate_max_items(self):
338338
self.create_variable_is_list()
339339
with self.l('if {variable}_is_list:'):
340-
if not isinstance(self._definition['maxItems'], int):
340+
if not isinstance(self._definition['maxItems'], (int, float)):
341341
raise JsonSchemaDefinitionException('maxItems must be a number')
342342
self.create_variable_with_length()
343343
with self.l('if {variable}_len > {maxItems}:'):
@@ -443,7 +443,7 @@ def generate_items(self):
443443
def generate_min_properties(self):
444444
self.create_variable_is_dict()
445445
with self.l('if {variable}_is_dict:'):
446-
if not isinstance(self._definition['minProperties'], int):
446+
if not isinstance(self._definition['minProperties'], (int, float)):
447447
raise JsonSchemaDefinitionException('minProperties must be a number')
448448
self.create_variable_with_length()
449449
with self.l('if {variable}_len < {minProperties}:'):
@@ -452,7 +452,7 @@ def generate_min_properties(self):
452452
def generate_max_properties(self):
453453
self.create_variable_is_dict()
454454
with self.l('if {variable}_is_dict:'):
455-
if not isinstance(self._definition['maxProperties'], int):
455+
if not isinstance(self._definition['maxProperties'], (int, float)):
456456
raise JsonSchemaDefinitionException('maxProperties must be a number')
457457
self.create_variable_with_length()
458458
with self.l('if {variable}_len > {maxProperties}:'):

tests/json_schema/test_draft04.py

-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ def pytest_generate_tests(metafunc):
1919
'const.json',
2020
'enum.json',
2121

22-
# TODO: fix decimal allowed as number
23-
'maxItems.json',
24-
'maxLength.json',
25-
'maxProperties.json',
26-
'minItems.json',
27-
'minLength.json',
28-
'minProperties.json',
29-
3022
# TODO: fix empty schema == invalid
3123
'not.json',
3224

tests/json_schema/test_draft06.py

-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ def pytest_generate_tests(metafunc):
1919
'const.json',
2020
'enum.json',
2121

22-
# TODO: fix decimal allowed as number
23-
'maxItems.json',
24-
'maxLength.json',
25-
'maxProperties.json',
26-
'minItems.json',
27-
'minLength.json',
28-
'minProperties.json',
29-
3022
# TODO: fix empty schema == invalid
3123
'not.json',
3224

tests/json_schema/test_draft07.py

-8
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ def pytest_generate_tests(metafunc):
2121
'const.json',
2222
'enum.json',
2323

24-
# TODO: fix decimal allowed as number
25-
'maxItems.json',
26-
'maxLength.json',
27-
'maxProperties.json',
28-
'minItems.json',
29-
'minLength.json',
30-
'minProperties.json',
31-
3224
# TODO: fix empty schema == invalid
3325
'not.json',
3426

tests/json_schema/test_draft2019.py

-8
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ def pytest_generate_tests(metafunc):
2121
'const.json',
2222
'enum.json',
2323

24-
# TODO: fix decimal allowed as number
25-
'maxItems.json',
26-
'maxLength.json',
27-
'maxProperties.json',
28-
'minItems.json',
29-
'minLength.json',
30-
'minProperties.json',
31-
3224
# TODO: fix empty schema == invalid
3325
'not.json',
3426

0 commit comments

Comments
 (0)