v0.4.3: swagger.html — mockAuth + X-Mock-Auth, _mock/* работают из Swagger UI

This commit is contained in:
2026-08-01 19:41:52 +04:00
parent 0539011ca4
commit 9241229e03
2 changed files with 6 additions and 14 deletions
+1 -1
View File
@@ -71,4 +71,4 @@ DELAY = float(os.getenv("MOCK_OP_DELAY", "0.1"))
# Версия полигона — единый источник правды для app.py и routes/root.py. # Версия полигона — единый источник правды для app.py и routes/root.py.
# Меняется при КАЖДОМ изменении кода. # Меняется при КАЖДОМ изменении кода.
VERSION = "0.4.2" VERSION = "0.4.3"
+5 -13
View File
@@ -90,25 +90,17 @@
filter: true, filter: true,
showExtensions: true, showExtensions: true,
showCommonExtensions: true, showCommonExtensions: true,
// Предзаполняем токен // Предзаполняем токен для _mock/*
onComplete: function () { onComplete: function () {
// Предзаполнить Bearer токен
const authToken = "{{ auth_token }}"; const authToken = "{{ auth_token }}";
if (authToken) { if (authToken) {
// Swagger UI хранит авторизацию в localStorage ui.preauthorizeApiKey("mockAuth", authToken);
try {
const key = "swagger_auth_bearerAuth_" + encodeURIComponent(window.location.origin);
const auth = JSON.parse(localStorage.getItem(key) || "{}");
auth.value = "Bearer " + authToken;
localStorage.setItem(key, JSON.stringify(auth));
ui.preauthorizeApiKey("bearerAuth", authToken);
} catch (e) { /* ignore */ }
} }
}, },
requestInterceptor: function (req) { requestInterceptor: function (req) {
// Добавляем заголовок Authorization если Swagger UI его не добавил // Добавляем X-Mock-Auth только для _mock/* эндпоинтов
if (!req.headers.Authorization && "{{ auth_token }}") { if (req.url.indexOf("/_mock/") !== -1 && "{{ auth_token }}") {
req.headers.Authorization = "Bearer {{ auth_token }}"; req.headers["X-Mock-Auth"] = "{{ auth_token }}";
} }
return req; return req;
}, },