-
-
Notifications
You must be signed in to change notification settings - Fork 438
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
👋 ❓Proposal - marking parameters with annotations #746
Comments
First impression: I like the idea, it feels cleaner and more pythonic. Some general notes:
Basically, its a good idea, I just don't want to lose the current way of doing things in order to gain it. |
This will work with IDEs. In fact, it will be better in a lot of ways, especially w.r.t. default values. Backwards compatibility with the same name is unfortunately not possible. You can however have it if you use different names. I’d recommend keeping |
I don’t think that will work. You’ll need to do one of:
IMO both are equally ugly and verbose, but they result in the same thing (internally you don’t have to handle them separately or anything). |
So my first impression on this : It's a new way of approaching a rather complex problem. Now my 2 cents on this topic is :
Maybe we can follow current fastapi approach? ( eg : adding a title? ) @api.post("/some")
def some(request, filters:Filters = Query(...), payload: SomeSchema = Form(title="some special schema which does awesome things")):
... Note that fastapi changed quite a lot in the recent times. For example old versions of fastapi ( to my knowledge ) used to have Overall the direction i want ninja to head in is to market itself as the Thanks for reading. It's great to see the development resuming. You have created a really awesome framework @vitalik |
FastAPI actually supports and recommends this approach now: https://github.com/tiangolo/fastapi/releases/tag/0.95.0. also, this doesn’t have to be a breaking change |
Fair enough. As long as we have a step by step migration for
But follow a deprecation like |
I checked Annotated's Test Code because the documentation hasn't been updated yet!
My point: Regular typing and PEP593 is sufficient, it is also a standard, for this proposal, in the source code, |
not sure which part you see different, but this should work iudentical in django-ninja and fastapi: q: Annotated[str, Query()],
# equals to
q: str = Query(...) OR q: Annotated[str, Query()] = "some-defatul",
# equals to
q: str = Query("some-defatul") but the Topic here to make it shorter: q: Query[str] = "some-default" with support of autocompletion and other stutff |
I do like the new syntax a bit more, but I also don't want to change my annotations for every endpoint at once. Some backwards compatible change would be best (although I'd prefer the same naming schema, Migration guide for |
Well the plan is actually to keep all these 3 in working (backwards compatible) q: Query[str] = "some-defatul"
# is equal to
q: Annotated[str, Query()] = "some-defatul",
# and equal to
q: str = Query("some-defatul")
# and all will work in the same codebase it just the default documentation will suggest to use the new syntax by default |
What is the current status of this issue?
|
So right now I understand I can replace this: def list_users(request, params: Get_UsersQueryParams = Query(...)): with def list_users(request, params: Query[Get_UsersQueryParams]): but I do not understand, how I could use the annotations here: def send_reset_password_email(request, user_id: str = Path(..., example="01c8ba9e-25d2-4ad5-9ddb-90eb3d15569c"), params: Put_Users_ResetPasswordEmailQueryParams = Query(...)): If I replace the Query(...) part, I get the problem that I have a parameter with no default value after one with it. And I don't know how to replace the Path(..., example=...) part with the annotation without losing the example value in OpenAPI UI. |
@adriangb in xpresso framework created what I think a nicer approach for marking api function arguments. I think it should be the default way in django-ninja as well
basically this:
can turn into this
Optional params will turn from
to
passing OpenApi parameters:
Pros
Cons
Please share your thoughts
cc: @SmileyChris @OtherBarry @baseplate-admin @stephenrauch @jkeyes
The text was updated successfully, but these errors were encountered: