Skip to content

Commit

Permalink
Merge pull request #187 from ral-facilities/feature/disable-openapi-y…
Browse files Browse the repository at this point in the history
…aml-write-#183

Disable openapi.yaml Generation
  • Loading branch information
MRichards99 authored Nov 18, 2020
2 parents b752c85 + 463e3db commit 2caae79
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"ICAT_URL": "https://localhost.localdomain:8181",
"icat_check_cert": false,
"log_level": "WARN",
"log_location": "/home/user1/datagateway-api/logs.log",
"debug_mode": false,
"generate_swagger": false,
"host": "127.0.0.1",
Expand Down
6 changes: 6 additions & 0 deletions datagateway_api/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def get_log_level(self):
except KeyError:
sys.exit("Missing config value, log_level")

def get_log_location(self):
try:
return self.config["log_location"]
except KeyError:
sys.exit("Missing config value, log_location")

def is_debug_mode(self):
try:
return self.config["debug_mode"]
Expand Down
3 changes: 1 addition & 2 deletions datagateway_api/common/logger_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

from datagateway_api.common.config import config

log_level = "DEBUG"
LOG_FILE_NAME = Path(__file__).parent.parent / "logs.log"
LOG_FILE_NAME = Path(config.get_log_location())
logger_config = {
"version": 1,
"formatters": {
Expand Down
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 2caae79

Please sign in to comment.