Unclear Breaking change in fastapi-pagination 0.13.0
Hi,
See this diff:
LimitOffsetPaginatedResponse_CountryResponse_:
properties:
details:
items:
$ref: '#/components/schemas/CountryResponse'
title: Details
type: array
limit:
anyOf:
- minimum: 1.0
type: integer
- type: 'null'
title: Limit
links:
$ref: '#/components/schemas/Links'
+ readOnly: true
message:
title: Message
type: string
offset:
anyOf:
- minimum: 0.0
type: integer
- type: 'null'
title: Offset
total:
anyOf:
- minimum: 0.0
type: integer
- type: 'null'
title: Total
required:
- details
- - total
- limit
- offset
- - links
- message
+ - links
title: LimitOffsetPaginatedResponse[CountryResponse]
type: object
Basically, it seems that there are 2 changes:
totalused to be required but nullable. Now, its key is no longer required.linksare nowreadOnly.
And here is the code I use
from fastapi import Query
from fastapi_pagination.customization import (
CustomizedPage,
UseAdditionalFields,
UseFieldsAliases,
UseIncludeTotal,
UseName,
UseParamsFields,
)
from fastapi_pagination.links import LimitOffsetPage
customizers = [
UseFieldsAliases(
items="details", # `details` contains the list of items.
),
UseAdditionalFields(
message=str, # `message` is always there, for all `BaseGenericResponse`.
),
UseIncludeTotal(True),
]
T = TypeVar("T")
GenericLimitOffsetPaginatedResponse = CustomizedPage[
LimitOffsetPage[T],
UseName("LimitOffsetPaginatedResponse"),
UseParamsFields(
limit=Query(10, ge=1, le=100, description="Page size limit"),
offset=Query(0, ge=0, description="Page offset"),
),
*customizers,
]
then
from fastapi_pagination import paginate
from pydantic import BaseModel
class CountryResponse(BaseModel):
...
class CountryService:
# Type of `self._all_countries: list[CountryResponse]`
# ...
def get_all_countries(self) -> GenericLimitOffsetPaginatedResponse[CountryResponse]:
return paginate(self._all_countries, safe=True, additional_data={"message": "OK"})
I checked the changelog (which only contains a link to the migration guide), tried to figure out what I should change to not break. But it's unclear to me. What should I amend?
Was a default changed by mistake?
Also, it's just a thought, but it may be worth having a sample app and dumping its yaml.safe_dump(sample_app.openapi(), indent=2) and detect if a breaking change was introduced in existing features.
Hi @Mulugruntz,
Sorry for long response.
I guess this issue was added in https://github.com/uriyyo/fastapi-pagination/pull/1505
I like your idea of adding tests for OpenAPI schema, it makes sense to me, thanks 🙏
Hi @Mulugruntz,
It's been a long time, and I hope we solved this issue.
Starting from 0.14.0 version total field becomes required by default for non-optional pages, also we added checks for openapi schema changes.
Beta version v0.14.0b1 has been released, I would appreciate any feedback 🙏
Thank you Yurii.
I will try (maybe next week), and if it works, I'll remove fastapi-pagination from the Renovate exclusion list. And I'll come back here and give you some feedback :)
also we added checks for openapi schema changes.
Can you point me to the PR(s) that tackled this? Thank you!
Here is commit - https://github.com/uriyyo/fastapi-pagination/commit/eacf6ba93da9e71179324336281800d430a937ac
Hi @Mulugruntz,
Can I close this issue?
Hi @Mulugruntz,
I'm closing this issue, let me know if you still have any issues.