Better support for ModelViewSet (through appropriate router attribution based on settings) - And fix incomplete API paths when recurrence is used#132
Open
dimitri-justeau wants to merge 8 commits into
Conversation
… add router settings for a better integration of viewsets.
This was referenced Aug 24, 2016
Merged
Author
|
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request is an attempt to provide a better ModelViewSet support:
ApiEndpointobjects 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 theApiDocumentationobject should bind anApiEndpointto a router. There are 3 possibilities:To achieve this, I slightly modified the
ApiEndpointmodel, adding aApiNodeclass (which is a super class ofApiEndpoint). The API is then seen as a tree, with leaves beingApiEndpointinstances, 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
includepattern 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!