diff --git a/docs/changelog.rst b/docs/changelog.rst index c7cd33f..8bb521f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,12 +4,13 @@ Changelog ********* -**1.7.2** +**1.7.2b** ********* *Release date: May 12, 2018* - **FIXED:** fixed generation of default ``SECURITY_REQUIREMENTS`` to match documented behaviour +- **FIXED:** ordering of ``SECURITY_REQUIREMENTS`` and ``SECURITY_DEFINITIONS`` is now stable ********* diff --git a/src/drf_yasg/generators.py b/src/drf_yasg/generators.py index 0e09c2d..683d300 100644 --- a/src/drf_yasg/generators.py +++ b/src/drf_yasg/generators.py @@ -204,9 +204,14 @@ class OpenAPISchemaGenerator(object): paths, prefix = self.get_paths(endpoints, components, request, public) security_definitions = swagger_settings.SECURITY_DEFINITIONS + if security_definitions is not None: + security_definitions = OrderedDict(sorted([(key, OrderedDict(sorted(sd.items()))) + for key, sd in swagger_settings.SECURITY_DEFINITIONS.items()])) security_requirements = swagger_settings.SECURITY_REQUIREMENTS if security_requirements is None: security_requirements = [{security_scheme: []} for security_scheme in swagger_settings.SECURITY_DEFINITIONS] + else: + security_requirements = [OrderedDict(sorted(sr.items())) for sr in security_requirements] url = self.url if url is None and request is not None: diff --git a/src/drf_yasg/openapi.py b/src/drf_yasg/openapi.py index da0a9c3..177adb3 100644 --- a/src/drf_yasg/openapi.py +++ b/src/drf_yasg/openapi.py @@ -221,7 +221,7 @@ class Swagger(SwaggerDict): :param str _prefix: api path prefix to use in setting basePath; this will be appended to the wsgi SCRIPT_NAME prefix or Django's FORCE_SCRIPT_NAME if applicable :param str _version: version string to override Info - :param list[dict] security_definitions: list of supported authentication mechanisms + :param dict[str,dict[str,str]] security_definitions: list of supported authentication mechanisms :param list[dict] security: authentication mechanisms accepted by default; can be overriden in Operation :param list[str] consumes: consumed MIME types; can be overriden in Operation :param list[str] produces: produced MIME types; can be overriden in Operation diff --git a/tests/reference.yaml b/tests/reference.yaml index 132eacb..f167efc 100644 --- a/tests/reference.yaml +++ b/tests/reference.yaml @@ -24,9 +24,9 @@ securityDefinitions: Basic: type: basic Bearer: - type: apiKey - name: Authorization in: header + name: Authorization + type: apiKey security: - Basic: [] - Bearer: []