Skip to content

Commit

Permalink
Fixed that min/max items/length/properties can be float
Browse files Browse the repository at this point in the history
  • Loading branch information
horejsek committed Jun 16, 2024
1 parent f235717 commit 96a5291
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 39 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
=== UNRELEASED

* Updated test suite
* Fixed detecting when infinity is reqched with multipleOf
* Fixed detecting when infinity is reached with multipleOf
* Fixed that min/max items/lenght/properties can be float

=== 2.20.0 (2024-06-15)

Expand Down
12 changes: 6 additions & 6 deletions fastjsonschema/draft04.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ def generate_not(self):
def generate_min_length(self):
with self.l('if isinstance({variable}, str):'):
self.create_variable_with_length()
if not isinstance(self._definition['minLength'], int):
if not isinstance(self._definition['minLength'], (int, float)):
raise JsonSchemaDefinitionException('minLength must be a number')
with self.l('if {variable}_len < {minLength}:'):
self.exc('{name} must be longer than or equal to {minLength} characters', rule='minLength')

def generate_max_length(self):
with self.l('if isinstance({variable}, str):'):
self.create_variable_with_length()
if not isinstance(self._definition['maxLength'], int):
if not isinstance(self._definition['maxLength'], (int, float)):
raise JsonSchemaDefinitionException('maxLength must be a number')
with self.l('if {variable}_len > {maxLength}:'):
self.exc('{name} must be shorter than or equal to {maxLength} characters', rule='maxLength')
Expand Down Expand Up @@ -328,7 +328,7 @@ def generate_multiple_of(self):
def generate_min_items(self):
self.create_variable_is_list()
with self.l('if {variable}_is_list:'):
if not isinstance(self._definition['minItems'], int):
if not isinstance(self._definition['minItems'], (int, float)):
raise JsonSchemaDefinitionException('minItems must be a number')
self.create_variable_with_length()
with self.l('if {variable}_len < {minItems}:'):
Expand All @@ -337,7 +337,7 @@ def generate_min_items(self):
def generate_max_items(self):
self.create_variable_is_list()
with self.l('if {variable}_is_list:'):
if not isinstance(self._definition['maxItems'], int):
if not isinstance(self._definition['maxItems'], (int, float)):
raise JsonSchemaDefinitionException('maxItems must be a number')
self.create_variable_with_length()
with self.l('if {variable}_len > {maxItems}:'):
Expand Down Expand Up @@ -443,7 +443,7 @@ def generate_items(self):
def generate_min_properties(self):
self.create_variable_is_dict()
with self.l('if {variable}_is_dict:'):
if not isinstance(self._definition['minProperties'], int):
if not isinstance(self._definition['minProperties'], (int, float)):
raise JsonSchemaDefinitionException('minProperties must be a number')
self.create_variable_with_length()
with self.l('if {variable}_len < {minProperties}:'):
Expand All @@ -452,7 +452,7 @@ def generate_min_properties(self):
def generate_max_properties(self):
self.create_variable_is_dict()
with self.l('if {variable}_is_dict:'):
if not isinstance(self._definition['maxProperties'], int):
if not isinstance(self._definition['maxProperties'], (int, float)):
raise JsonSchemaDefinitionException('maxProperties must be a number')
self.create_variable_with_length()
with self.l('if {variable}_len > {maxProperties}:'):
Expand Down
8 changes: 0 additions & 8 deletions tests/json_schema/test_draft04.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ def pytest_generate_tests(metafunc):
'const.json',
'enum.json',

# TODO: fix decimal allowed as number
'maxItems.json',
'maxLength.json',
'maxProperties.json',
'minItems.json',
'minLength.json',
'minProperties.json',

# TODO: fix empty schema == invalid
'not.json',

Expand Down
8 changes: 0 additions & 8 deletions tests/json_schema/test_draft06.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ def pytest_generate_tests(metafunc):
'const.json',
'enum.json',

# TODO: fix decimal allowed as number
'maxItems.json',
'maxLength.json',
'maxProperties.json',
'minItems.json',
'minLength.json',
'minProperties.json',

# TODO: fix empty schema == invalid
'not.json',

Expand Down
8 changes: 0 additions & 8 deletions tests/json_schema/test_draft07.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ def pytest_generate_tests(metafunc):
'const.json',
'enum.json',

# TODO: fix decimal allowed as number
'maxItems.json',
'maxLength.json',
'maxProperties.json',
'minItems.json',
'minLength.json',
'minProperties.json',

# TODO: fix empty schema == invalid
'not.json',

Expand Down
8 changes: 0 additions & 8 deletions tests/json_schema/test_draft2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ def pytest_generate_tests(metafunc):
'const.json',
'enum.json',

# TODO: fix decimal allowed as number
'maxItems.json',
'maxLength.json',
'maxProperties.json',
'minItems.json',
'minLength.json',
'minProperties.json',

# TODO: fix empty schema == invalid
'not.json',

Expand Down

0 comments on commit 96a5291

Please sign in to comment.