You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently everything will work correctly except for Swagger. Swagger will correctly display endpoints for users and posts with correct schemas but it will actually send requests only to /users/ (even when you click Try it Out on the posts section) in this case because in the example we've defined add_router("/users"/) first.
I assume its because somewhere under the hood Swagger uses function names to resolve endpoints. Next simple hack fixes this by changing the implementation to:
Notice this line list_records.__name__ = f"list_{self.class_name}_records"
It seems like a dirty hack (it is). And it seems like its not a popular way in python to handle this. I wasn't able to google anything similar. But just in case someone has the same problem, maybe it would be helpful to keep it here.
P.S. If I'm doing something wrong with this approach entirely would be great to get feedback because I'm not yet much experienced in python/django so appreciate any advice :)
Versions:
Python version: 3.12
Django version: 5.0.2
Django-Ninja version: 1.1.0
Pydantic version: 2.6.4
The text was updated successfully, but these errors were encountered:
in general django-ninja generates operation id as string like "<module-name>_<function_name>" - and because you have all in one module that probably gives an issue
Describe the bug
In case you want to create routers dynamically like the following (when you have a lot of similar resources for example):
Where your implementation may look like the following:
Currently everything will work correctly except for Swagger. Swagger will correctly display endpoints for
users
andposts
with correct schemas but it will actually send requests only to/users/
(even when you click Try it Out on theposts
section) in this case because in the example we've definedadd_router("/users"/)
first.I assume its because somewhere under the hood Swagger uses function names to resolve endpoints. Next simple hack fixes this by changing the implementation to:
Notice this line
list_records.__name__ = f"list_{self.class_name}_records"
It seems like a dirty hack (it is). And it seems like its not a popular way in python to handle this. I wasn't able to google anything similar. But just in case someone has the same problem, maybe it would be helpful to keep it here.
P.S. If I'm doing something wrong with this approach entirely would be great to get feedback because I'm not yet much experienced in python/django so appreciate any advice :)
Versions:
The text was updated successfully, but these errors were encountered: