Items Transformer
If you want to transform items before passing it to schema validation stage,
you can use transformer
argument of paginate
function.
from fastapi import FastAPI
from fastapi_pagination import Page, add_pagination, paginate
app = FastAPI()
add_pagination(app)
@app.get("/double-nums")
def get_double_nums() -> Page[int]:
return paginate(
[*range(1_000)],
transformer=lambda x: [i * 2 for i in x],
)
transformer
argument is a function that accepts a list of items and returns a list of items that will be passed to
page schema validation stage.