diff --git a/jsonapi_pydantic/__init__.py b/jsonapi_pydantic/__init__.py index c6392ee..058fd9d 100644 --- a/jsonapi_pydantic/__init__.py +++ b/jsonapi_pydantic/__init__.py @@ -1,5 +1,5 @@ from jsonapi_pydantic import constants, v1_0 -__version__ = "0.1.2" +__version__ = "0.1.3" __all__ = ["constants", "v1_0"] diff --git a/jsonapi_pydantic/v1_0/resource/resource.py b/jsonapi_pydantic/v1_0/resource/resource.py index 892d86e..ed37ee7 100644 --- a/jsonapi_pydantic/v1_0/resource/resource.py +++ b/jsonapi_pydantic/v1_0/resource/resource.py @@ -23,10 +23,14 @@ class Resource(BaseModel): @root_validator def check_all_values(cls, values: dict) -> dict: + attributes, relationships = values.get("attributes"), values.get("relationships") + if not attributes and not relationships: + return values + # More about these restrictions: https://jsonapi.org/format/#document-resource-object-fields try: - attributes = dict(values.get("attributes")) - relationships = dict(values.get("relationships")) + attributes = dict(attributes) if attributes else attributes + relationships = dict(relationships) if relationships else relationships except (ValueError, TypeError): raise ValueError("Attributes and relationships must be json objects.") diff --git a/pyproject.toml b/pyproject.toml index f924eaf..445d93f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "jsonapi-pydantic" -version = "0.1.2" +version = "0.1.3" description = "JSON:API implementation with pydantic." authors = ["impocode "]