File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass
5
+ class JsonApiVersion :
6
+ v1_0 = "1.0"
7
+ v1_1 = "1.1"
8
+
9
+
10
+ JSON_API_VERSION = JsonApiVersion
11
+ JSON_API_MEDIA_TYPE = "application/vnd.api+json"
12
+
13
+ __all__ = ["JSON_API_MEDIA_TYPE" ]
Original file line number Diff line number Diff line change 1
1
from jsonapi_pydantic .v1_0 .error import *
2
2
from jsonapi_pydantic .v1_0 .jsonapi import *
3
3
from jsonapi_pydantic .v1_0 .links import *
4
+ from jsonapi_pydantic .v1_0 .meta import *
4
5
from jsonapi_pydantic .v1_0 .resource import *
5
6
from jsonapi_pydantic .v1_0 .resource_identifier import *
6
7
from jsonapi_pydantic .v1_0 .toplevel import *
Original file line number Diff line number Diff line change @@ -25,16 +25,24 @@ class Resource(BaseModel):
25
25
def check_all_values (cls , values : dict ) -> dict :
26
26
# More about these restrictions: https://jsonapi.org/format/#document-resource-object-fields
27
27
attributes , relationships = values .get ("attributes" ), values .get ("relationships" )
28
+ try :
29
+ attributes , relationships = dict (attributes ), dict (relationships )
30
+ except ValueError :
31
+ raise ValueError ("Attributes and relationships must be json objects." )
32
+
28
33
if attributes and (attributes .get ("id" ) or attributes .get ("type" )):
29
34
raise ValueError ("Attributes can not have keys named id or type." )
35
+
30
36
if relationships and (relationships .get ("id" ) or relationships .get ("type" )):
31
37
raise ValueError ("Relationships can not have keys named id or type." )
38
+
32
39
if attributes and relationships :
33
40
for key in attributes :
34
41
if relationships .get (key ):
35
42
raise ValueError (
36
43
f"A resource can not have an attribute and relationship with the same name. Name: { key } ."
37
44
)
45
+
38
46
return values
39
47
40
48
You can’t perform that action at this time.
0 commit comments