Skip to content

Commit

Permalink
🐛 Accept empty body as a valid input for schema validation
Browse files Browse the repository at this point in the history
  • Loading branch information
perdy authored and migduroli committed Sep 3, 2024
1 parent 4e5ba47 commit 9bcd6d7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions flama/schemas/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ def nested_schemas(self, schema: t.Any = UNKNOWN) -> t.List[t.Any]:

return []

@t.overload
def validate(self, values: None, *, partial: bool = False) -> t.Dict[str, t.Any]:
...

@t.overload
def validate(self, values: t.Dict[str, t.Any], *, partial: bool = False) -> t.Dict[str, t.Any]:
...
Expand All @@ -197,11 +201,11 @@ def validate(self, values: t.Dict[str, t.Any], *, partial: bool = False) -> t.Di
def validate(self, values: t.List[t.Dict[str, t.Any]], *, partial: bool = False) -> t.List[t.Dict[str, t.Any]]:
...

def validate(self, values, *, partial=False):
def validate(self, values: t.Union[t.Dict[str, t.Any], t.List[t.Dict[str, t.Any]], None], *, partial=False):
if isinstance(values, (list, tuple)):
return [schemas.adapter.validate(self.schema, value, partial=partial) for value in values]

return schemas.adapter.validate(self.schema, values, partial=partial)
return schemas.adapter.validate(self.schema, values or {}, partial=partial)

@t.overload
def load(self, values: t.Dict[str, t.Any]) -> t.Any:
Expand Down

0 comments on commit 9bcd6d7

Please sign in to comment.