Rename "data" to "items" in multi response
Is your feature request related to a problem? Please describe.
The multi-response field data is generic and doesn't describe the returned data very well.
Describe the solution you'd like
I would like to use a more descriptive term e.g. items that indicate that a list is being returned.
Another option might be to make the key configurable on the FastCRUD instance.
here is my current solution
SchemaType = TypeVar("SchemaType", bound=BaseModel)
class ListResponse(BaseModel, Generic[SchemaType]):
items: list[SchemaType]
class PaginatedListResponses(ListResponse[SchemaType]):
total_count: int
has_more: bool
page: Optional[int] = None
items_per_page: Optional[int] = None
@router.get("/foods", response_model=PaginatedListResponses[FoodRead])
async def get_foods(
db: Annotated[AsyncSession, Depends(async_get_db)],
page: int = 1,
items_per_page: int = 10,
):
food_lists = await crud_foods.get_multi(
db=db,
offset=compute_offset(page, items_per_page),
limit=items_per_page,
)
response: dict[str, Any] = paginated_response(
crud_data=food_lists, page=page, items_per_page=items_per_page
)
if 'data' in response:
response['items'] = response.pop('data')
return response
I've created a possible solution in pull request. https://github.com/igorbenav/fastcrud/pull/203
I'd like you to check it and if you know how to improve it - share a comment.
Closed by #203