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
+5 -13
View File
@@ -90,25 +90,17 @@
filter: true,
showExtensions: true,
showCommonExtensions: true,
// Предзаполняем токен
// Предзаполняем токен для _mock/*
onComplete: function () {
// Предзаполнить Bearer токен
const authToken = "{{ auth_token }}";
if (authToken) {
// Swagger UI хранит авторизацию в localStorage
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 */ }
ui.preauthorizeApiKey("mockAuth", authToken);
}
},
requestInterceptor: function (req) {
// Добавляем заголовок Authorization если Swagger UI его не добавил
if (!req.headers.Authorization && "{{ auth_token }}") {
req.headers.Authorization = "Bearer {{ auth_token }}";
// Добавляем X-Mock-Auth только для _mock/* эндпоинтов
if (req.url.indexOf("/_mock/") !== -1 && "{{ auth_token }}") {
req.headers["X-Mock-Auth"] = "{{ auth_token }}";
}
return req;
},