Skip to content

Commit

Permalink
#183: Allow openapi.yaml generation to be disabled
Browse files Browse the repository at this point in the history
- This will mean this configurable parameter can be disabled when running the API in production, thereby avoiding any issues with read-only directories
  • Loading branch information
MRichards99 committed Nov 5, 2020
1 parent a694129 commit 1596f73
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions datagateway_api/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,18 @@ 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
log.debug("Reordering OpenAPI docs to alphabetical order")
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())

if config.is_generate_swagger():
# 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
log.debug("Reordering OpenAPI docs to alphabetical order")
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())


@app.route("/openapi.json")
Expand Down

0 comments on commit 1596f73

Please sign in to comment.