From 3d46eea353cd2b71f24c4442471fae0433687d31 Mon Sep 17 00:00:00 2001 From: Ildar Iskhakov Date: Fri, 18 Aug 2023 14:22:48 +0800 Subject: [PATCH] Set schema url for Swagger via env variable (#2823) # What this PR does ## Which issue(s) this PR fixes ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated - [ ] Documentation added (or `pr:no public docs` PR label added if not required) - [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --- docker-compose-developer.yml | 2 +- engine/settings/base.py | 13 ++++++++++--- engine/settings/prod_without_db.py | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docker-compose-developer.yml b/docker-compose-developer.yml index cdb26987..6d2114ba 100644 --- a/docker-compose-developer.yml +++ b/docker-compose-developer.yml @@ -3,7 +3,7 @@ version: "3.9" x-labels: &oncall-labels - "com.grafana.oncall.env=dev" -x-user: &oncall-user "appuser" +x-user: &oncall-user "root" x-oncall-build: &oncall-build-args context: ./engine diff --git a/engine/settings/base.py b/engine/settings/base.py index e6d83f73..851411f0 100644 --- a/engine/settings/base.py +++ b/engine/settings/base.py @@ -260,11 +260,18 @@ SPECTACULAR_SETTINGS = { "SERVE_INCLUDE_SCHEMA": False, # OTHER SETTINGS "PREPROCESSING_HOOKS": [ - "engine.included_path.custom_preprocessing_hook" - ], # Custom hook to include only paths from SPECTACULAR_INCLUDED_PATHS + "engine.included_path.custom_preprocessing_hook" # Custom hook to include only paths from SPECTACULAR_INCLUDED_PATHS + ], "SERVE_URLCONF": ("apps.api.urls"), - "SWAGGER_UI_SETTINGS": {"supportedSubmitMethods": []}, # Disable "Try it out" button for all endpoints + "SWAGGER_UI_SETTINGS": { + "supportedSubmitMethods": [], # Disable "Try it out" button for all endpoints + }, + "SERVE_PUBLIC": False, } +# Use custom scheme if env var exists +SWAGGER_UI_SETTINGS_URL = os.getenv("SWAGGER_UI_SETTINGS_URL") +if SWAGGER_UI_SETTINGS_URL: + SPECTACULAR_SETTINGS["SWAGGER_UI_SETTINGS"]["url"] = SWAGGER_UI_SETTINGS_URL SPECTACULAR_INCLUDED_PATHS = [ "/features", diff --git a/engine/settings/prod_without_db.py b/engine/settings/prod_without_db.py index 79ca7ee8..efe7033c 100644 --- a/engine/settings/prod_without_db.py +++ b/engine/settings/prod_without_db.py @@ -160,4 +160,5 @@ REST_FRAMEWORK = { ), "DEFAULT_AUTHENTICATION_CLASSES": [], "DEFAULT_RENDERER_CLASSES": ("rest_framework.renderers.JSONRenderer",), + "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", }