From 88c623a1c507694b2d6b7f34025df933687759bf Mon Sep 17 00:00:00 2001 From: Matthew Richards Date: Thu, 15 Oct 2020 13:43:40 +0000 Subject: [PATCH] #173: Order OpenAPI YAML request types alphabetically - Things like get, patch, post, delete etc. weren't alphabetically ordered as changing the order of the YAML file on startup --- src/main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.py b/src/main.py index a19c2b94..e3939582 100644 --- a/src/main.py +++ b/src/main.py @@ -102,6 +102,12 @@ def handle_error(e): ) spec.path(resource=InstrumentsFacilityCyclesInvestigationsCount, api=api) +# Reorder paths (e.g. get, patch, post) so openapi.yaml only changes when there's a +# change to the Swagger docs, rather than changing on each startup +for entity_data in spec._paths.values(): + for endpoint_name in sorted(entity_data.keys()): + entity_data.move_to_end(endpoint_name) + openapi_spec_path = Path(__file__).parent / "swagger/openapi.yaml" with open(openapi_spec_path, "w") as f: f.write(spec.to_yaml())