-
Notifications
You must be signed in to change notification settings - Fork 184
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
Better support for ModelViewSet (through appropriate router attribution based on settings) - And fix incomplete API paths when recurrence is used #132
base: master
Are you sure you want to change the base?
Conversation
… add router settings for a better integration of viewsets.
UPDATE: I made a PR to django-rest-framework (Transparently keep reference of routers in urls generated by routers) which would enable an easy and automatic discovery of routers when inspecting API endpoints. I also made the change in a branch of my drfdocs fork (https://github.com/dimitri-justeau/django-rest-framework-docs/tree/use-drf-resolvers-with-router-reference) in case the PR gets accepted, and it works like a charm! |
👍 |
Would love to see this merged. Anything I can do to help? |
Any further progress? |
bump? |
This pull request is an attempt to provide a better ModelViewSet support:
ApiEndpoint
objects not being instantiated with adrf_router
, which is necessary to know which http method is bound to which python method. What I did is adding the possibility to indicate in settings how theApiDocumentation
object should bind anApiEndpoint
to a router. There are 3 possibilities:To achieve this, I slightly modified the
ApiEndpoint
model, adding aApiNode
class (which is a super class ofApiEndpoint
). The API is then seen as a tree, with leaves beingApiEndpoint
instances, that will be documented. The ancestors of an ApiEndpoint are inspected to build the full url, and also to know which drf_router should be used to get the http methods.When an
include
pattern is used in a urls module, if the regex pattern is empty, all the urls included are shown as being part of the same group as the current urls module. If the regex is not empty, a new group is show, using this pattern: <parent_group_pattern>/<include_group_pattern>.For instance, consider the following urls:
with those urls being added to the project's url module as:
url(r'^accounts/', view=include('project.accounts.urls', namespace='accounts')),
The documentation will be generated in two sections: accounts, and accounts/viewset_test
If viewset_test were defined as
url(r'^', include(router.urls), name="user_viewset")
, the only generated documentation group would have been accounts with all the urls of viewset_test included in it.Using this tree model, future improvement are also made possible, such as having different documentation sections and levels in the UI.
I can make changes to this pull request, or enhancements if necessary!
EDIT: Using it, I can see a lot of improvements that could be done. So the main idea of this PR is mainly about using this ApiNode / ApiEndpoint model. I don't know for the moment if there would be a way to automatically discover the router(s) associated to a urlpattern, but for sure it would be the perfect solution!