diff --git a/docs/changelog.rst b/docs/changelog.rst index 8594e96..07f0f9a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -3,6 +3,14 @@ Changelog ######### +********* +**1.6.2** +********* + +*Release date: TODO, 2018* + +- **FIXED:** made documentation ordering of parameters stable for urls with multiple parameters (:issue:`105`, :pr:`106`) + ********* **1.6.1** ********* diff --git a/src/drf_yasg/generators.py b/src/drf_yasg/generators.py index d9e6400..4dc9ca5 100644 --- a/src/drf_yasg/generators.py +++ b/src/drf_yasg/generators.py @@ -403,7 +403,7 @@ class OpenAPISchemaGenerator(object): queryset = getattr(view_cls, 'queryset', None) model = getattr(getattr(view_cls, 'queryset', None), 'model', None) - for variable in uritemplate.variables(path): + for variable in sorted(uritemplate.variables(path)): model, model_field = get_queryset_field(queryset, variable) attrs = get_basic_type_info(model_field) or {'type': openapi.TYPE_STRING} if getattr(view_cls, 'lookup_field', None) == variable and attrs['type'] == openapi.TYPE_STRING: diff --git a/testproj/todo/urls.py b/testproj/todo/urls.py index 391b5bf..cb0a3ba 100644 --- a/testproj/todo/urls.py +++ b/testproj/todo/urls.py @@ -1,3 +1,4 @@ +from django.conf.urls import url from rest_framework import routers from todo import views @@ -8,3 +9,8 @@ router.register(r'another', views.TodoAnotherViewSet) router.register(r'yetanother', views.TodoYetAnotherViewSet) urlpatterns = router.urls + +urlpatterns += [ + url(r'^(?P\d+)/yetanother/(?P\d+)/$', + views.NestedTodoView.as_view(),), +] diff --git a/testproj/todo/views.py b/testproj/todo/views.py index 7de6a52..848e461 100644 --- a/testproj/todo/views.py +++ b/testproj/todo/views.py @@ -1,4 +1,5 @@ from rest_framework import viewsets +from rest_framework.generics import RetrieveAPIView from .models import Todo, TodoAnother, TodoYetAnother from .serializer import TodoAnotherSerializer, TodoSerializer, TodoYetAnotherSerializer @@ -20,3 +21,7 @@ class TodoAnotherViewSet(viewsets.ReadOnlyModelViewSet): class TodoYetAnotherViewSet(viewsets.ReadOnlyModelViewSet): queryset = TodoYetAnother.objects.all() serializer_class = TodoYetAnotherSerializer + + +class NestedTodoView(RetrieveAPIView): + serializer_class = TodoYetAnotherSerializer diff --git a/tests/reference.yaml b/tests/reference.yaml index 673b873..f0d917c 100644 --- a/tests/reference.yaml +++ b/tests/reference.yaml @@ -546,6 +546,27 @@ paths: description: A unique integer value identifying this todo. required: true type: integer + /todo/{todo_id}/yetanother/{yetanother_id}/: + get: + operationId: todo_yetanother_read + description: '' + parameters: [] + responses: + '200': + description: '' + schema: + $ref: '#/definitions/TodoYetAnother' + tags: + - todo + parameters: + - name: todo_id + in: path + required: true + type: string + - name: yetanother_id + in: path + required: true + type: string /users/: get: operationId: users_list