django-rest-framework icon indicating copy to clipboard operation
django-rest-framework copied to clipboard

Schemas generated by generators.py exclude urlpatterns with same root node and action

Open bluppfisk opened this issue 5 years ago • 3 comments

Checklist

  • [X] I have verified that that issue exists against the master branch 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

bluppfisk avatar Sep 28 '20 12:09 bluppfisk

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.

stale[bot] avatar May 02 '22 02:05 stale[bot]

activity

bluppfisk avatar May 02 '22 08:05 bluppfisk

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.

stale[bot] avatar Jul 14 '22 06:07 stale[bot]

closing as not planned anymore

auvipy avatar Jan 03 '23 12:01 auvipy