django-rest-framework
django-rest-framework copied to clipboard
Schemas generated by generators.py exclude urlpatterns with same root node and action
Checklist
- [X] I have verified that that issue exists against the
masterbranch of Django REST framework. - [X] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- [X] This is not a usage question. (Those should be directed to the discussion group instead.)
- [X] This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
- [X] I have reduced the issue to the simplest possible case.
- [] I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)
Steps to reproduce
- Use DRF with coreAPI and pyyaml support
- Include multiple
list-action type URLpatterns in urls.py, e.g.
urlpatterns = [
url(r"^api/status/", views.status, name="aggregated_status"), # aggregated status of page and system
url(r"^api/status/page/", views.status_page, name="status_page"), # page status only
]
- Generate a schema
./manage.py generateschema --format=openapi - NOTE: problem only occurs with formats openapi and openapi-json. With corejson there is no issue.
Expected behavior
- Schema including all paths
info:
description: Get statuses yay
title: Status API
version: ''
openapi: 3.0.0
paths:
/api/status/:
get:
description: Aggregated system and page status
operationId: status_list
tags:
- status
/api/status/page/:
get:
description: Page status
operationId: status_page_list
tags:
- status
servers:
- url: ''
Actual behavior
- Only top-level pattern is included (i.e. /api/status/)
info:
description: Get statuses yay
title: Status API
version: ''
openapi: 3.0.0
paths:
/api/status/:
get:
description: Aggregated system and page status
operationId: status_list
tags:
- status
servers:
- url: ''
Code
I believe the culprit to be here:
renderers.py::_BaseOpenAPIRenderer
def get_paths(self, document):
paths = {}
tag = None
for name, link in document.links.items():
path = urlparse.urlparse(link.url).path
method = link.action.lower()
paths.setdefault(path, {})
paths[path][method] = self.get_operation(link, name, tag=tag)
for tag, section in document.data.items():
for name, link in section.links.items():
path = urlparse.urlparse(link.url).path
method = link.action.lower()
paths.setdefault(path, {})
paths[path][method] = self.get_operation(link, name, tag=tag)
return paths
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
activity
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
closing as not planned anymore