Skip to content

Commit d4add30

Browse files
committed
minor update: rely on the default type in schema
1 parent 6242169 commit d4add30

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

fastapi_rest_jsonapi/methods.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ async def wrapper(request: Request, obj_id: int):
3737
return schema_resp(
3838
data={
3939
"id": data_schema.id,
40-
"type": type_,
4140
"attributes": data_schema.dict(),
4241
},
4342
)
@@ -56,7 +55,10 @@ def patch_detail_jsonapi(
5655
type_: str,
5756
schema_resp: Any,
5857
) -> Callable:
59-
"""PATCH method router (Decorator for JSON API)."""
58+
"""
59+
PATCH method router (Decorator for JSON API).
60+
TODO: validate `id` in data!
61+
"""
6062

6163
def inner(func: Callable) -> Callable:
6264
async def wrapper(request: Request, obj_id: int, data: schema_in): # type: ignore
@@ -68,7 +70,6 @@ async def wrapper(request: Request, obj_id: int, data: schema_in): # type: igno
6870
return schema_resp(
6971
data={
7072
"id": data_schema.id,
71-
"type": type_,
7273
"attributes": data_schema.dict(),
7374
},
7475
)
@@ -102,7 +103,7 @@ async def _get_single_response(
102103
data_model: List[Any] = await query.all()
103104
data_schema: List[Any] = [schema.from_orm(i_obj) for i_obj in data_model]
104105
return schema_resp(
105-
data=[{"id": i_obj.id, "type": type_, "attributes": i_obj.dict()} for i_obj in data_schema],
106+
data=[{"id": i_obj.id, "attributes": i_obj.dict()} for i_obj in data_schema],
106107
meta={"count": count, "totalPages": total_pages},
107108
)
108109

@@ -137,7 +138,7 @@ async def wrapper(
137138
if isinstance(query, BaseModel): # JSONAPIResultListSchema
138139
return query
139140
elif isinstance(query, list):
140-
return schema_resp(data=[{"id": i_obj.id, "type": type_, "attributes": i_obj.dict()} for i_obj in query])
141+
return schema_resp(data=[{"id": i_obj.id, "attributes": i_obj.dict()} for i_obj in query])
141142
else:
142143
return await _get_single_response(query, query_params, schema, type_, schema_resp) # QuerySet
143144

@@ -169,7 +170,6 @@ async def wrapper(request: Request, data: schema_in): # type: ignore
169170
return schema_resp(
170171
data={
171172
"id": data_pydantic.id,
172-
"type": type_,
173173
"attributes": data_pydantic.dict(),
174174
},
175175
)

0 commit comments

Comments
 (0)