Retain declared path ordering in OpenAPI YAML output. (#6680)

* Add pyyaml.dump(..., sort_keys=False) to not sort openapi keys alphabetically
* Retain ordering of paths as provided in urlconf in OpenAPI schemas.
This commit is contained in:
Alan Crosswell 2019-06-09 08:58:02 -04:00 committed by Carlton Gibson
parent 819c46ea80
commit 4d228257ac
4 changed files with 5 additions and 3 deletions

View File

@ -44,6 +44,7 @@ You can determine your currently installed version using `pip show`:
**Date**: [Unreleased][3.10.0-milestone]
* Updated PyYaml dependency for OpenAPI schema generation to `pyyaml>=5.1` [#6680][gh6680]
* Resolve DeprecationWarning with markdown. [#6317][gh6317]
* Add `generateschema --generator_class` CLI option
@ -2138,4 +2139,5 @@ For older release notes, [please see the version 2.x documentation][old-release-
[gh6613]: https://github.com/encode/django-rest-framework/issues/6613
<!-- 3.10.0 -->
[gh6680]: https://github.com/encode/django-rest-framework/issues/6680
[gh6317]: https://github.com/encode/django-rest-framework/issues/6317

View File

@ -6,4 +6,4 @@ django-guardian==1.5.0
django-filter>=2.1.0, <2.2
coreapi==2.3.1
coreschema==0.0.4
pyyaml
pyyaml>=5.1

View File

@ -1049,7 +1049,7 @@ class OpenAPIRenderer(BaseRenderer):
assert yaml, 'Using OpenAPIRenderer, but `pyyaml` is not installed.'
def render(self, data, media_type=None, renderer_context=None):
return yaml.dump(data, default_flow_style=False).encode('utf-8')
return yaml.dump(data, default_flow_style=False, sort_keys=False).encode('utf-8')
class JSONOpenAPIRenderer(BaseRenderer):

View File

@ -54,7 +54,7 @@ def endpoint_ordering(endpoint):
'PATCH': 3,
'DELETE': 4
}.get(method, 5)
return (path, method_priority)
return (method_priority,)
_PATH_PARAMETER_COMPONENT_RE = re.compile(