-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use pydantic model on UseAdditionalFields ? #1452
Comments
@uriyyo, any suggestions? I’m happy to contribute to this. |
@Kavan72 But it's kinda required to use, otherwise you will use default Page class. Is there any reason why you don't want to use There is also |
Actually, I don’t like monkey patching, which is why I’m avoiding this. I also have my own OpenAPI build function, and I don’t want any library modifying my OpenAPI schema. While pagination_ctx is fine, it’s not an ideal solution. You mentioned that I’m Depends on this, but that’s not accurate. A custom page is a response class, not something that relies on a dependency. |
Sorry, I guess my message was not clear. When you call
You can see it here: fastapi-pagination/fastapi_pagination/api.py Lines 135 to 136 in f867c15
|
Hey @uriyyo, I understand what you’re trying to say. My idea is that if someone comes from a different framework or language, using |
@uriyyo hey any update 😅, if you are okay then I’m happy to contribute to this. |
@Kavan72 Sorry for long response. I'm thinking about better solution how can we have feature as you suggested.
I was thinking about smth like this: from fastapi_pagination import paginate, LimitOffsetPage
from fastapi_pagination import pagination_for # new function
limit_offset_paginate = pagination_for(paginate, LimitOffsetPage) What do you think about such API? Not sure if it's perfect. Another option might be to introduce from fastapi_pagination import paginate, LimitOffsetPage, Limit0ffsetParams, PaginationConfig
paginate(
range(1_000),
LimitOffsetParams(limit=100, offset=50),
config=PaginationConfig(
page=LimitOffsetPage,
)
) |
Thanks for your response! I think introducing a config parameter is a better approach. It keeps the paginate function cleaner and allows for future extensions without making the function signature even more complex. The first approach, while functional, adds more boilerplate code since every new pagination type would require wrapping with The |
Thanks for feedback, than I will go with introducing config param. |
Welcome! 😊 BTW, if you need any help contributing, feel free to ping me here or on Discord (hidan411). |
Discussed in #1451
Originally posted by Kavan72 January 29, 2025
I've my pydantic model and i want to use on UseAdditionalFields, like this
My code for custom page
Since I’m not using
add_pagination(app)
, FastAPI Pagination can’t find my custom page class. Is there any way to pass the class into the paginate method so it can use my custom page? Sorry, but I don’t prefer usingadd_pagination
orset_page
.The text was updated successfully, but these errors were encountered: