-
-
Notifications
You must be signed in to change notification settings - Fork 396
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
Implement implicit reverse url name generation #361
Conversation
Hi @SmileyChris Just wondering what would be the best approach when url is the same for get/post methods @api.post('/tasks')
def create_task(request):
pass
@api.get('/tasks')
def list_tasks(request):
pass As I understand the last added name ("list_tasks") will be the name for that path (while some users might expect it to be create_task) also there might be conflicts - if users have the same function name (like maybe the best approach is to generarate url name (and open api operation_id) based on tags and function name f.e.
the resulting url name should be |
Django runs through each URL pattern, in order, and stops at the first one
that matches the requested URL.
I don't think conflicts matter for the automatic name generation. If you
are at a size where you encounter this, you should probably not rely on the
automatic names and specify them explicitly.
The idea about having routers which have their own namespace is probably a
good addition, but I don't think it's anything that should block this. I
don't think it should piggyback on tags, just have the same urls_namespace
option at the router level.
Either way, this should be merged soon or the currently incorrect url
documentation should be altered, since when I wrote those docs I assumed
that this was how it already worked.
…On Tue, 14 Jun 2022 at 20:27, Vitaliy Kucheryaviy ***@***.***> wrote:
Hi @SmileyChris <https://github.com/SmileyChris>
Just wondering what would be the best approach when url is the same for
get/post methods
@api.post('/tasks')def create_task(request):
pass
@api.get('/tasks')def list_tasks(request):
pass
As I understand the last added name ("list_tasks") will be the name for
that path (while some users might expect it to be create_task)
also there might be conflicts - if users have the same function name (like
list_items) in multiple modules/routers...
maybe the best approach is to generarate url name (and open api
operation_id) based on tags and function name
f.e.
@router.get('/')
def list_tasks(request):
return ...
....
api.add_router('/tasks/', router, tags=['tasks'])
the resulting url name should be api-1.0.0:tasks:list_tasks (the "tasks"
taken from the first tag assigned to router)
—
Reply to this email directly, view it on GitHub
<#361 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA2272ZNS56UXJSD4AGCATVPA66NANCNFSM5OMZMV6Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Fixes #355
Huh, I had assumed this is how it worked anyway.