Better support for ModelViewSet (through appropriate router attribution based on settings) - And fix incomplete API paths when recurrence is used #132
+264
−43
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:
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!