Skip to content

Commit

Permalink
Validate default values exist in the enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Qubad786 committed Oct 1, 2024
1 parent cc054c9 commit 5007877
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apps_schema/attrs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ def validate(self, schema, data=None):
except ValidationErrors as e:
verrors.extend(e)

if 'default' in self._schema_data and 'enum' in self._schema_data:
enum_values = [enum['value'] for enum in self._schema_data['enum']]
if self._schema_data['default'] not in enum_values:
verrors.add(f'{schema}.default', 'Default value is not in enum list')

verrors.check()

def json_schema(self):
Expand Down

0 comments on commit 5007877

Please sign in to comment.