openapi-explorer 2.1.656 → 2.1.658
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/openapi-explorer.min.js +2 -2
- package/dist/es/components/api-request.js +58 -140
- package/dist/es/components/api-response.js +9 -34
- package/dist/es/components/json-tree.js +4 -18
- package/dist/es/components/request-form-table.js +13 -36
- package/dist/es/components/schema-table.js +28 -42
- package/dist/es/components/schema-tree.js +31 -61
- package/dist/es/components/syntax-highlighter.js +7 -26
- package/dist/es/components/tag-input.js +2 -14
- package/dist/es/openapi-explorer-oauth-handler.js +0 -2
- package/dist/es/openapi-explorer.js +62 -174
- package/dist/es/react.js +4 -4
- package/dist/es/styles/input-styles.js +1 -1
- package/dist/es/styles/schema-styles.js +1 -1
- package/dist/es/templates/advance-search-template.js +1 -5
- package/dist/es/templates/callback-template.js +2 -2
- package/dist/es/templates/code-samples-template.js +1 -3
- package/dist/es/templates/components-template.js +41 -4
- package/dist/es/templates/endpoint-template.js +6 -17
- package/dist/es/templates/expanded-endpoint-template.js +4 -7
- package/dist/es/templates/focused-endpoint-template.js +0 -10
- package/dist/es/templates/mainBodyTemplate.js +3 -2
- package/dist/es/templates/navbar-template.js +9 -12
- package/dist/es/templates/overview-template.js +1 -1
- package/dist/es/templates/security-scheme-template.js +12 -73
- package/dist/es/templates/server-template.js +1 -8
- package/dist/es/utils/color-utils.js +2 -21
- package/dist/es/utils/common-utils.js +3 -20
- package/dist/es/utils/schema-utils.js +35 -132
- package/dist/es/utils/spec-parser.js +35 -120
- package/dist/es/utils/theme.js +3 -6
- package/dist/es/utils/xml/xml.js +1 -40
- package/dist/lib/components/api-request.js +58 -157
- package/dist/lib/components/api-response.js +9 -54
- package/dist/lib/components/json-tree.js +4 -27
- package/dist/lib/components/request-form-table.js +14 -42
- package/dist/lib/components/schema-table.js +28 -52
- package/dist/lib/components/schema-tree.js +31 -72
- package/dist/lib/components/syntax-highlighter.js +6 -49
- package/dist/lib/components/tag-input.js +2 -18
- package/dist/lib/languages/en.js +2 -3
- package/dist/lib/languages/fr.js +2 -3
- package/dist/lib/languages/index.js +0 -6
- package/dist/lib/openapi-explorer-oauth-handler.js +0 -6
- package/dist/lib/openapi-explorer.js +61 -197
- package/dist/lib/react.js +4 -5
- package/dist/lib/styles/advanced-search-styles.js +1 -5
- package/dist/lib/styles/api-request-styles.js +1 -5
- package/dist/lib/styles/border-styles.js +1 -5
- package/dist/lib/styles/endpoint-styles.js +1 -5
- package/dist/lib/styles/flex-styles.js +1 -5
- package/dist/lib/styles/font-styles.js +1 -5
- package/dist/lib/styles/info-styles.js +1 -5
- package/dist/lib/styles/input-styles.js +1 -5
- package/dist/lib/styles/key-frame-styles.js +1 -5
- package/dist/lib/styles/nav-styles.js +1 -5
- package/dist/lib/styles/prism-styles.js +1 -5
- package/dist/lib/styles/schema-styles.js +1 -5
- package/dist/lib/styles/tab-styles.js +1 -5
- package/dist/lib/styles/table-styles.js +1 -5
- package/dist/lib/styles/tag-input-styles.js +1 -5
- package/dist/lib/templates/advance-search-template.js +0 -6
- package/dist/lib/templates/callback-template.js +1 -3
- package/dist/lib/templates/code-samples-template.js +0 -4
- package/dist/lib/templates/components-template.js +43 -9
- package/dist/lib/templates/endpoint-template.js +6 -29
- package/dist/lib/templates/expanded-endpoint-template.js +3 -17
- package/dist/lib/templates/focused-endpoint-template.js +0 -19
- package/dist/lib/templates/mainBodyTemplate.js +2 -13
- package/dist/lib/templates/navbar-template.js +9 -20
- package/dist/lib/templates/overview-template.js +0 -5
- package/dist/lib/templates/security-scheme-template.js +12 -79
- package/dist/lib/templates/server-template.js +1 -12
- package/dist/lib/utils/color-utils.js +4 -25
- package/dist/lib/utils/common-utils.js +3 -33
- package/dist/lib/utils/schema-utils.js +33 -141
- package/dist/lib/utils/spec-parser.js +35 -128
- package/dist/lib/utils/theme.js +3 -16
- package/dist/lib/utils/xml/xml.js +1 -42
- package/package.json +2 -2
@@ -4,51 +4,37 @@ exports.__esModule = true;
|
|
4
4
|
exports.checkForAuthToken = checkForAuthToken;
|
5
5
|
exports.default = securitySchemeTemplate;
|
6
6
|
exports.pathSecurityTemplate = pathSecurityTemplate;
|
7
|
-
|
8
7
|
var _lit = require("lit");
|
9
|
-
|
10
8
|
var _unsafeHtml = require("lit/directives/unsafe-html.js");
|
11
|
-
|
12
9
|
var _marked = require("marked");
|
13
|
-
|
14
10
|
var _base64url = _interopRequireDefault(require("base64url"));
|
15
|
-
|
16
11
|
var _index = require("../languages/index.js");
|
17
|
-
|
18
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
|
-
|
20
13
|
function onApiKeyChange(apiKeyId, e) {
|
21
14
|
e.preventDefault();
|
22
15
|
let apiKeyValue = '';
|
23
16
|
const securityObj = this.resolvedSpec.securitySchemes.find(v => v.apiKeyId === apiKeyId);
|
24
|
-
|
25
17
|
if (!securityObj) {
|
26
18
|
return;
|
27
19
|
}
|
28
|
-
|
29
20
|
const trEl = e.target.closest('tr');
|
30
|
-
|
31
21
|
if (securityObj.type && securityObj.type === 'http' && securityObj.scheme && securityObj.scheme.toLowerCase() === 'basic') {
|
32
22
|
const userVal = trEl.querySelector('.api-key-user').value.trim();
|
33
23
|
const passwordVal = trEl.querySelector('.api-key-password').value.trim();
|
34
|
-
|
35
24
|
if (passwordVal) {
|
36
25
|
apiKeyValue = `Basic ${btoa(`${userVal}:${passwordVal}`)}`;
|
37
26
|
}
|
38
27
|
} else {
|
39
28
|
apiKeyValue = trEl.querySelector('.api-key-input').value.trim();
|
40
|
-
|
41
29
|
if (apiKeyValue) {
|
42
30
|
if (securityObj.scheme && securityObj.scheme.toLowerCase() === 'bearer') {
|
43
31
|
apiKeyValue = `Bearer ${apiKeyValue.replace(/^Bearer\s+/i, '')}`;
|
44
32
|
}
|
45
33
|
}
|
46
34
|
}
|
47
|
-
|
48
35
|
securityObj.finalKeyValue = apiKeyValue;
|
49
36
|
this.requestUpdate();
|
50
37
|
}
|
51
|
-
|
52
38
|
function onClearAllApiKeys() {
|
53
39
|
this.resolvedSpec.securitySchemes.forEach(v => {
|
54
40
|
v.user = '';
|
@@ -57,17 +43,17 @@ function onClearAllApiKeys() {
|
|
57
43
|
v.finalKeyValue = '';
|
58
44
|
});
|
59
45
|
this.requestUpdate();
|
60
|
-
}
|
61
|
-
|
46
|
+
}
|
62
47
|
|
48
|
+
// Updates the OAuth Access Token (API key), so it reflects in UI and gets used in TRY calls
|
63
49
|
function updateOAuthKey(apiKeyId, tokenType = 'Bearer', accessToken) {
|
64
50
|
const securityObj = this.resolvedSpec.securitySchemes.find(v => v.apiKeyId === apiKeyId);
|
65
51
|
const tokenPrefix = tokenType && tokenType.toLowerCase() === 'bearer' ? 'Bearer' : tokenType;
|
66
52
|
securityObj.finalKeyValue = `${tokenPrefix}${tokenPrefix ? ' ' : ''}${accessToken}`;
|
67
53
|
this.requestUpdate();
|
68
|
-
}
|
69
|
-
|
54
|
+
}
|
70
55
|
|
56
|
+
// Gets Access-Token in exchange of Authorization Code
|
71
57
|
async function fetchAccessToken(tokenUrl, suggestedClientId, clientSecret, redirectUrl, grantType, authCode, sendClientSecretIn = 'header', apiKeyId, authFlowDivEl, scopes = null) {
|
72
58
|
const respDisplayEl = authFlowDivEl ? authFlowDivEl.querySelector('.oauth-resp-display') : undefined;
|
73
59
|
const {
|
@@ -79,33 +65,26 @@ async function fetchAccessToken(tokenUrl, suggestedClientId, clientSecret, redir
|
|
79
65
|
const urlFormParams = new URLSearchParams();
|
80
66
|
const headers = new Headers();
|
81
67
|
urlFormParams.append('grant_type', grantType);
|
82
|
-
|
83
68
|
if (redirectUrl) {
|
84
69
|
urlFormParams.append('redirect_uri', redirectUrl);
|
85
70
|
}
|
86
|
-
|
87
71
|
if (authCode) {
|
88
72
|
urlFormParams.append('code', authCode);
|
89
73
|
}
|
90
|
-
|
91
74
|
if (sendClientSecretIn === 'header') {
|
92
75
|
headers.set('Authorization', `Basic ${btoa(`${clientId}:${clientSecret}`)}`);
|
93
76
|
} else {
|
94
77
|
urlFormParams.append('client_id', clientId);
|
95
|
-
|
96
78
|
if (clientSecret) {
|
97
79
|
urlFormParams.append('client_secret', clientSecret);
|
98
80
|
}
|
99
81
|
}
|
100
|
-
|
101
82
|
if (scopes) {
|
102
83
|
urlFormParams.append('scope', scopes);
|
103
84
|
}
|
104
|
-
|
105
85
|
if (codeVerifier) {
|
106
86
|
urlFormParams.append('code_verifier', codeVerifier);
|
107
87
|
}
|
108
|
-
|
109
88
|
try {
|
110
89
|
const resp = await fetch(tokenUrl, {
|
111
90
|
method: 'POST',
|
@@ -113,18 +92,14 @@ async function fetchAccessToken(tokenUrl, suggestedClientId, clientSecret, redir
|
|
113
92
|
body: urlFormParams
|
114
93
|
});
|
115
94
|
const tokenResp = await resp.json();
|
116
|
-
|
117
95
|
if (!resp.ok) {
|
118
96
|
if (respDisplayEl) {
|
119
97
|
respDisplayEl.innerHTML = `<span style="color:var(--red)">${tokenResp.error_description || tokenResp.error_description || 'Unable to get access token'}</span>`;
|
120
98
|
}
|
121
|
-
|
122
99
|
return;
|
123
100
|
}
|
124
|
-
|
125
101
|
if (tokenResp.token_type && tokenResp.access_token) {
|
126
102
|
updateOAuthKey.call(this, apiKeyId, tokenResp.token_type, tokenResp.access_token);
|
127
|
-
|
128
103
|
if (respDisplayEl) {
|
129
104
|
respDisplayEl.innerHTML = '<span style="color:var(--green)">Access Token Received</span>';
|
130
105
|
}
|
@@ -135,24 +110,20 @@ async function fetchAccessToken(tokenUrl, suggestedClientId, clientSecret, redir
|
|
135
110
|
}
|
136
111
|
}
|
137
112
|
}
|
138
|
-
|
139
113
|
function getCookieValue(keyId) {
|
140
114
|
const foundCookie = (document.cookie || '').split(';').find(c => c.split('=')[0] === keyId);
|
141
115
|
return foundCookie && foundCookie.split('=')[1] || '';
|
142
116
|
}
|
143
|
-
|
144
117
|
function toObject(urlSearchParams) {
|
145
118
|
const result = {};
|
146
119
|
const entries = urlSearchParams && urlSearchParams.entries() || [];
|
147
|
-
|
148
120
|
for (const [key, value] of entries) {
|
149
121
|
result[key] = value;
|
150
122
|
}
|
151
|
-
|
152
123
|
return result;
|
153
|
-
}
|
154
|
-
|
124
|
+
}
|
155
125
|
|
126
|
+
// Gets invoked when it receives the Authorization Code from the other window via message-event
|
156
127
|
async function checkForAuthToken(redirectToApiLocation) {
|
157
128
|
const parameters = toObject(new URLSearchParams(window.location.search));
|
158
129
|
const hashQuery = toObject(new URLSearchParams(window.location.hash.slice(1)));
|
@@ -171,15 +142,12 @@ async function checkForAuthToken(redirectToApiLocation) {
|
|
171
142
|
newUrl.searchParams.delete('hd');
|
172
143
|
newUrl.searchParams.delete('authuser');
|
173
144
|
newUrl.searchParams.delete('redirect_auth');
|
174
|
-
|
175
145
|
if (!parameters.state) {
|
176
146
|
return;
|
177
147
|
}
|
178
|
-
|
179
148
|
const sanitizedUrlWithHash = newUrl.toString().replace(/#((code|state|access_token|id_token|authuser|expires_in|hd|prompt|scope|token_type)=[^&]+&?)*$/ig, '');
|
180
149
|
history.replaceState({}, undefined, sanitizedUrlWithHash);
|
181
150
|
let parsedState;
|
182
|
-
|
183
151
|
try {
|
184
152
|
// If somehow the state contains a question mark, just remove it, a ? is not a valid here
|
185
153
|
parsedState = JSON.parse(_base64url.default.decode(parameters.state.replace(/\?.*$/, '')));
|
@@ -188,13 +156,11 @@ async function checkForAuthToken(redirectToApiLocation) {
|
|
188
156
|
console.error('The state parameter in the OAuth response is invalid', error, parameters.state);
|
189
157
|
return;
|
190
158
|
}
|
191
|
-
|
192
159
|
const {
|
193
160
|
apiKeyId,
|
194
161
|
flowId,
|
195
162
|
url
|
196
163
|
} = parsedState;
|
197
|
-
|
198
164
|
if (redirectToApiLocation && url && !parameters.redirect_auth) {
|
199
165
|
const apiExplorerLocation = new URL(url);
|
200
166
|
Object.keys(parameters).forEach(key => apiExplorerLocation.searchParams.append(key, parameters[key]));
|
@@ -202,19 +168,15 @@ async function checkForAuthToken(redirectToApiLocation) {
|
|
202
168
|
window.location.replace(apiExplorerLocation.toString());
|
203
169
|
return;
|
204
170
|
}
|
205
|
-
|
206
171
|
if (parameters.code) {
|
207
172
|
var _this$selectedServer;
|
208
|
-
|
209
173
|
const securityObj = this.resolvedSpec.securitySchemes.find(v => v.apiKeyId === apiKeyId);
|
210
174
|
const tokenUrl = securityObj && securityObj.flows[flowId] && new URL(securityObj.flows[flowId].tokenUrl || '', (_this$selectedServer = this.selectedServer) === null || _this$selectedServer === void 0 ? void 0 : _this$selectedServer.computedUrl);
|
211
175
|
await fetchAccessToken.call(this, tokenUrl, securityObj.clientId, securityObj.clientSecret, securityObj.redirectUri || window.location.href, 'authorization_code', parameters.code, null, apiKeyId);
|
212
176
|
return;
|
213
177
|
}
|
214
|
-
|
215
178
|
updateOAuthKey.call(this, apiKeyId, parameters.token_type, parameters.access_token);
|
216
179
|
}
|
217
|
-
|
218
180
|
async function onInvokeOAuthFlow(apiKeyId, flowType, authUrl, tokenUrl, e) {
|
219
181
|
const authFlowDivEl = e.target.closest('.oauth-flow');
|
220
182
|
const clientId = authFlowDivEl.querySelector('#oauth-client-id') ? authFlowDivEl.querySelector('#oauth-client-id').value.trim() : '';
|
@@ -223,18 +185,17 @@ async function onInvokeOAuthFlow(apiKeyId, flowType, authUrl, tokenUrl, e) {
|
|
223
185
|
const checkedScopeEls = [...authFlowDivEl.querySelectorAll('input[type="checkbox"]:checked')];
|
224
186
|
const securityObj = this.resolvedSpec.securitySchemes.find(v => v.apiKeyId === apiKeyId);
|
225
187
|
let grantType = '';
|
226
|
-
let responseType = '';
|
188
|
+
let responseType = '';
|
227
189
|
|
190
|
+
// clear previous error messages
|
228
191
|
const errEls = [...authFlowDivEl.parentNode.querySelectorAll('.oauth-resp-display')];
|
229
192
|
errEls.forEach(v => {
|
230
193
|
v.innerHTML = '';
|
231
194
|
});
|
232
|
-
|
233
195
|
if (flowType === 'authorizationCode' || flowType === 'implicit') {
|
234
196
|
const authUrlObj = new URL(authUrl);
|
235
197
|
const authCodeParams = new URLSearchParams(authUrlObj.search);
|
236
198
|
let codeVerifier;
|
237
|
-
|
238
199
|
if (flowType === 'authorizationCode') {
|
239
200
|
const randomBytes = new Uint32Array(12);
|
240
201
|
(window.crypto || window.msCrypto).getRandomValues(randomBytes);
|
@@ -249,7 +210,6 @@ async function onInvokeOAuthFlow(apiKeyId, flowType, authUrl, tokenUrl, e) {
|
|
249
210
|
} else if (flowType === 'implicit') {
|
250
211
|
responseType = 'token';
|
251
212
|
}
|
252
|
-
|
253
213
|
localStorage.setItem('openapi-explorer-oauth', JSON.stringify({
|
254
214
|
codeVerifier,
|
255
215
|
clientId,
|
@@ -257,11 +217,9 @@ async function onInvokeOAuthFlow(apiKeyId, flowType, authUrl, tokenUrl, e) {
|
|
257
217
|
flowId: flowType
|
258
218
|
}));
|
259
219
|
const selectedScopes = checkedScopeEls.map(v => v.value).join(' ');
|
260
|
-
|
261
220
|
if (selectedScopes) {
|
262
221
|
authCodeParams.set('scope', selectedScopes);
|
263
222
|
}
|
264
|
-
|
265
223
|
authCodeParams.set('client_id', clientId);
|
266
224
|
authCodeParams.set('redirect_uri', securityObj.redirectUri || window.location.href);
|
267
225
|
authCodeParams.set('response_type', responseType);
|
@@ -278,25 +236,20 @@ async function onInvokeOAuthFlow(apiKeyId, flowType, authUrl, tokenUrl, e) {
|
|
278
236
|
fetchAccessToken.call(this, tokenUrl, clientId, clientSecret, '', grantType, '', sendClientSecretIn, apiKeyId, authFlowDivEl, selectedScopes);
|
279
237
|
}
|
280
238
|
}
|
281
|
-
/* eslint-disable indent */
|
282
239
|
|
240
|
+
/* eslint-disable indent */
|
283
241
|
|
284
242
|
function oAuthFlowTemplate(flowName, securityObj, authFlow) {
|
285
243
|
var _this$selectedServer3, _this$selectedServer4, _this$selectedServer5;
|
286
|
-
|
287
244
|
const apiKeyId = securityObj.apiKeyId;
|
288
|
-
|
289
245
|
const getFullUrl = url => {
|
290
246
|
var _this$selectedServer2;
|
291
|
-
|
292
247
|
return url ? new URL(url, (_this$selectedServer2 = this.selectedServer) === null || _this$selectedServer2 === void 0 ? void 0 : _this$selectedServer2.computedUrl) : undefined;
|
293
248
|
};
|
294
|
-
|
295
249
|
const authorizationUrl = getFullUrl(authFlow.authorizationUrl, (_this$selectedServer3 = this.selectedServer) === null || _this$selectedServer3 === void 0 ? void 0 : _this$selectedServer3.computedUrl);
|
296
250
|
const tokenUrl = getFullUrl(authFlow.tokenUrl, (_this$selectedServer4 = this.selectedServer) === null || _this$selectedServer4 === void 0 ? void 0 : _this$selectedServer4.computedUrl);
|
297
251
|
const refreshUrl = getFullUrl(authFlow.refreshUrl, (_this$selectedServer5 = this.selectedServer) === null || _this$selectedServer5 === void 0 ? void 0 : _this$selectedServer5.computedUrl);
|
298
252
|
let flowNameDisplay;
|
299
|
-
|
300
253
|
if (flowName === 'authorizationCode') {
|
301
254
|
flowNameDisplay = 'Authorization Code Flow';
|
302
255
|
} else if (flowName === 'clientCredentials') {
|
@@ -306,20 +259,16 @@ function oAuthFlowTemplate(flowName, securityObj, authFlow) {
|
|
306
259
|
} else {
|
307
260
|
flowNameDisplay = flowName;
|
308
261
|
}
|
309
|
-
|
310
262
|
return (0, _lit.html)` <div class="oauth-flow" style="padding:10px 0;margin-bottom:10px"> <div class="tiny-title upper" style="margin-bottom:5px">${flowNameDisplay}</div> ${authorizationUrl ? (0, _lit.html)`<div><span style="width:75px;display:inline-block">Auth URL</span> <span class="mono-font"> ${authorizationUrl} </span></div>` : ''} ${tokenUrl ? (0, _lit.html)`<div><span style="width:75px;display:inline-block">Token URL</span> <span class="mono-font">${tokenUrl}</span></div>` : ''} ${refreshUrl ? (0, _lit.html)`<div><span style="width:75px;display:inline-block">Refresh URL</span> <span class="mono-font">${refreshUrl}</span></div>` : ''} ${flowName === 'authorizationCode' || flowName === 'clientCredentials' || flowName === 'implicit' ? (0, _lit.html)` ${authFlow.scopes ? (0, _lit.html)` <span> Scopes </span> <div class="oauth-scopes" part="section-auth-scopes" style="width:100%;display:flex;flex-direction:column;flex-wrap:wrap;margin:0 0 .125rem 0"> ${Object.entries(authFlow.scopes).map((scopeAndDescr, index) => (0, _lit.html)` <div class="m-checkbox" style="display:inline-flex;align-items:center"> <input type="checkbox" checked="checked" part="checkbox checkbox-auth-scope" id="${flowName}${index}" value="${scopeAndDescr[0]}"> <label for="${flowName}${index}" style="margin-left:5px"> <span class="mono-font">${scopeAndDescr[0]}</span> ${scopeAndDescr[0] !== scopeAndDescr[1] ? ` - ${scopeAndDescr[1] || ''}` : ''} </label> </div> `)} </div> ` : ''} <div style="display:flex"> <div> <input id="oauth-client-id" type="text" part="textbox textbox-auth-client-id" value="${securityObj.clientId || ''}" placeholder="Client ID" spellcheck="false" class="oauth-client-input"> ${flowName === 'clientCredentials' ? (0, _lit.html)` <input id="oauth-client-secret" type="password" part="textbox textbox-auth-client-secret" value="" placeholder="Client Secret" spellcheck="false" class="oauth-client-input"> <select id="oauth-send-client-secret-in" aria-label="oauth client secret location" style="margin-right:5px" class="oauth-client-input"> <option value="header" selected="selected"> Authorization Header </option> <option value="request-body"> Request Body </option> </select> ` : (0, _lit.html)`<div style="width:5px"></div>`} </div> ${flowName === 'authorizationCode' || flowName === 'clientCredentials' || flowName === 'implicit' ? (0, _lit.html)` <div class="oauth-client-input" style="margin-left:1rem"> <button class="m-btn thin-border" part="btn btn-outline" @click="${e => {
|
311
263
|
onInvokeOAuthFlow.call(this, apiKeyId, flowName, authorizationUrl, tokenUrl, e);
|
312
264
|
}}">GET TOKEN</button> </div>` : ''} </div> <div class="oauth-resp-display red-text small-font-size"></div> ` : ''} </div> `;
|
313
265
|
}
|
314
|
-
|
315
266
|
function renderSecurityScheme(v) {
|
316
267
|
if (!v.type) {
|
317
268
|
return '';
|
318
269
|
}
|
319
|
-
|
320
270
|
if (v.type.toLowerCase() === 'apikey' || v.type.toLowerCase() === 'http' && v.scheme && v.scheme.toLowerCase() === 'bearer') {
|
321
271
|
var _v$bearerFormat, _v$bearerFormat2;
|
322
|
-
|
323
272
|
return (0, _lit.html)` <div style="padding-top:1rem"> ${v.type.toLowerCase() === 'apikey' ? (0, _lit.html)`Send <code>${v.name || 'API key'}</code> in <code>${v.in || 'the request'}</code> with the given value:` : (0, _lit.html)`Send <code>Authorization</code> in <code>header</code> containing the word <code>Bearer</code> followed by a space and then the ${(_v$bearerFormat = v.bearerFormat) !== null && _v$bearerFormat !== void 0 ? _v$bearerFormat : 'Token String'}.`} </div> <form style="height:50px;margin-top:1rem;padding:10px 0;margin-bottom:10px"> ${v.in === 'cookie' ? (0, _lit.html)` <div style="display:block"> <input type="text" value="${getCookieValue(v.apiKeyId)}" disabled="disabled" class="api-key-input" placeholder="IygRVGf54B59e0GAkKmigGfuiVlp/uhFfk2ifA+jMMJzau2F1jPldc09gPTfnMw13BFBxqUZIFDm55DPfwkb0A==" spellcheck="false" style="resize:horizontal;width:100%"> <br> <small> <strong>Cookies</strong> are set and configured by the remote service, therefore it is not possible to configure them from the browser. </small> </div>` : !v.finalKeyValue ? (0, _lit.html)` <input type="text" value="${v.value}" placeholder="${(_v$bearerFormat2 = v.bearerFormat) !== null && _v$bearerFormat2 !== void 0 ? _v$bearerFormat2 : 'api-token'}" spellcheck="false" class="api-key-input fs-exclude" data-hj-suppress data-sl="mask"> <button type="submit" class="m-btn thin-border" style="margin-left:5px" part="btn btn-outline" @click="${e => {
|
324
273
|
onApiKeyChange.call(this, v.apiKeyId, e);
|
325
274
|
}}"> ${(0, _index.getI18nText)('authentication.set')} </button>` : (0, _lit.html)`<span class="blue-text" style="margin-right:1rem">Key Applied</span> <button class="m-btn thin-border small" part="btn btn-outline" @click="${() => {
|
@@ -327,7 +276,6 @@ function renderSecurityScheme(v) {
|
|
327
276
|
this.requestUpdate();
|
328
277
|
}}">REMOVE</button>`} </form>`;
|
329
278
|
}
|
330
|
-
|
331
279
|
if (v.type.toLowerCase() === 'http' && v.scheme && v.scheme.toLowerCase() === 'basic') {
|
332
280
|
if (v.finalKeyValue) {
|
333
281
|
return (0, _lit.html)` <div style="padding-top:1rem">${(0, _index.getI18nText)('authentication.http-basic-desc')}</div> <div style="height:50px;margin-top:1rem;padding:10px 0;margin-bottom:10px"> <span class="blue-text" style="margin-right:1rem">Key Applied</span> <button class="m-btn thin-border small" part="btn btn-outline" @click="${() => {
|
@@ -335,61 +283,46 @@ function renderSecurityScheme(v) {
|
|
335
283
|
this.requestUpdate();
|
336
284
|
}}">REMOVE</button> </div>`;
|
337
285
|
}
|
338
|
-
|
339
286
|
return (0, _lit.html)` <div style="padding-top:1rem">${(0, _index.getI18nText)('authentication.http-basic-desc')}</div> <div style="height:50px;margin-top:1rem;padding:10px 0;margin-bottom:10px"> <form style="display:flex"> <input type="text" value="${v.user}" placeholder="${(0, _index.getI18nText)('authentication.username')}" spellcheck="false" class="api-key-user" style="width:100px"> <input class="api-key-password fs-exclude" data-hj-suppress data-sl="mask" type="password" value="${v.password}" placeholder="${(0, _index.getI18nText)('authentication.password')}" spellcheck="false" style="width:100px;margin:0 5px"> <button type="submit" class="m-btn thin-border" @click="${e => {
|
340
287
|
onApiKeyChange.call(this, v.apiKeyId, e);
|
341
288
|
}}" part="btn btn-outline"> ${v.finalKeyValue ? 'UPDATE' : (0, _index.getI18nText)('authentication.set')} </button> </form> </div>`;
|
342
289
|
}
|
343
|
-
|
344
290
|
if (v.type.toLowerCase() === 'oauth2' && Object.keys(v.flows).length) {
|
345
291
|
return (0, _lit.html)`${Object.keys(v.flows).map(f => oAuthFlowTemplate.call(this, f, v, v.flows[f]))}`;
|
346
292
|
}
|
347
|
-
|
348
293
|
return '';
|
349
294
|
}
|
350
|
-
|
351
295
|
function securitySchemeTemplate() {
|
352
296
|
const schemes = this.resolvedSpec && this.resolvedSpec.securitySchemes;
|
353
|
-
|
354
297
|
if (!schemes) {
|
355
298
|
return undefined;
|
356
299
|
}
|
357
|
-
|
358
300
|
const providedApiKeys = schemes.filter(v => v.finalKeyValue);
|
359
301
|
return (0, _lit.html)` <section id="auth" part="section-auth" class="observe-me ${this.renderStyle === 'focused' ? 'section-gap--focused-mode' : 'section-gap'}"> <slot name="authentication"> <div class="section-padding"> <slot name="authentication-header"> <div class="sub-title regular-font">${(0, _index.getI18nText)('headers.authentication')}</div> </slot> <div class="small-font-size" style="display:flex;align-items:center;min-height:40px"> ${providedApiKeys.length > 0 ? (0, _lit.html)` <div class="blue-text"> ${providedApiKeys.length} API key applied </div> <div style="flex:1"></div> <button class="m-btn thin-border" part="btn btn-outline" @click="${() => {
|
360
302
|
onClearAllApiKeys.call(this);
|
361
303
|
}}">CLEAR ALL API KEYS</button>` : (0, _lit.html)`<div class="red-text">${(0, _index.getI18nText)('authentication.no-api-key-applied')}</div>`} </div> ${schemes.length > 0 ? (0, _lit.html)` <table role="presentation" class="m-table" style="width:100%"> ${schemes.map(v => (0, _lit.html)` <tr> <td colspan="1" style="max-width:500px;overflow-wrap:break-word"> <div style="min-height:24px;display:flex;flex-direction:column;justify-content:center;align-items:center"> <div style="display:flex;justify-content:center"> <span style="font-weight:700">${getTypeDisplayHeader(v)}</span> </div> </div> ${v.description ? (0, _lit.html)` <div class="m-markdown"> ${(0, _unsafeHtml.unsafeHTML)((0, _marked.marked)(v.description || ''))} </div>` : ''} </td> <td colspan="3">${renderSecurityScheme.call(this, v)}</td> </tr>`)} </table>` : ''} <slot name="authentication-footer"></slot> </div> </slot> </section> `;
|
362
304
|
}
|
363
|
-
|
364
305
|
function getOauthScopeTemplate(rawScopes) {
|
365
306
|
const scopes = Array.isArray(rawScopes) ? rawScopes.map(s => s === null || s === void 0 ? void 0 : s.trim()).filter(s => s) : [];
|
366
|
-
|
367
307
|
if (!scopes.length) {
|
368
308
|
return '';
|
369
309
|
}
|
370
|
-
|
371
310
|
return (0, _lit.html)` <div> <b>Required scopes:</b> <br> <div style="margin-left:8px"> ${scopes.map(scope => (0, _lit.html)`<span>${scope}</span> `)} </div> </div>`;
|
372
311
|
}
|
373
|
-
|
374
312
|
function getTypeDisplayHeader(securityScheme) {
|
375
313
|
if (securityScheme.type === 'apiKey') {
|
376
314
|
return `API Key (${securityScheme.name})`;
|
377
315
|
}
|
378
|
-
|
379
316
|
if (securityScheme.type === 'oauth2') {
|
380
317
|
return 'OAuth2.0';
|
381
318
|
}
|
382
|
-
|
383
319
|
if (securityScheme.type === 'http') {
|
384
320
|
return securityScheme.scheme === 'basic' ? (0, _index.getI18nText)('authentication.http-basic') : 'HTTP Bearer';
|
385
321
|
}
|
386
|
-
|
387
322
|
return securityScheme.type;
|
388
323
|
}
|
389
|
-
|
390
324
|
function pathSecurityTemplate(pathSecurityOptions) {
|
391
325
|
const requiredSecurityOptions = (pathSecurityOptions === null || pathSecurityOptions === void 0 ? void 0 : pathSecurityOptions.filter(o => o && Object.keys(o).length)) || [];
|
392
|
-
|
393
326
|
if (this.resolvedSpec.securitySchemes && requiredSecurityOptions.length) {
|
394
327
|
const orSecurityKeys1 = [];
|
395
328
|
requiredSecurityOptions.forEach(pSecurity => {
|
@@ -397,10 +330,10 @@ function pathSecurityTemplate(pathSecurityOptions) {
|
|
397
330
|
const andKeyTypes = [];
|
398
331
|
Object.keys(pSecurity).forEach(pathSecurityKey => {
|
399
332
|
const s = this.resolvedSpec.securitySchemes.find(ss => ss.apiKeyId === pathSecurityKey);
|
400
|
-
|
401
333
|
if (s) {
|
402
334
|
andKeyTypes.push(getTypeDisplayHeader(s));
|
403
|
-
andSecurityKeys1.push({
|
335
|
+
andSecurityKeys1.push({
|
336
|
+
...s,
|
404
337
|
scopes: pSecurity[pathSecurityKey]
|
405
338
|
});
|
406
339
|
}
|
@@ -412,7 +345,7 @@ function pathSecurityTemplate(pathSecurityOptions) {
|
|
412
345
|
});
|
413
346
|
return (0, _lit.html)`<div class="security-info-button" data-content-id="auth" @click="${e => this.scrollToEventTarget(e, false)}"> <div style="position:relative;display:flex;min-width:350px;max-width:700px;justify-content:flex-end"> <svg width="16" height="24" style="cursor:pointer"> <g> <path style="fill:var(--fg3)" d="m13.8,8.5l0,-2.6l0,0c0,-3.2 -2.6,-5.8 -5.8,-5.8s-5.8,2.6 -5.8,5.8l0,0l0,2.6l-2.1,0l0,11.2l16,0l0,-11.2l-2.1,0l-0,0l0,0l0,0l-0,0zm-9.8,-2.6c0,0 0,0 0,0c0,-2.2 1.8,-4 4,-4c2.2,0 4,1.8 4,4c0,0 0,0 0,0l0,2.6l-8.03,0l0,-2.6l0,0l0,0z"/> </g> </svg> ${orSecurityKeys1.map((orSecurityItem1, i) => (0, _lit.html)` ${i !== 0 ? (0, _lit.html)`<div style="padding:3px 4px"> OR </div>` : ''} <div class="security-tooltip tooltip" style="cursor:pointer"> <div style="padding:2px 4px;white-space:nowrap;text-overflow:ellipsis;max-width:150px;overflow:hidden"> <span part="anchor anchor-operation-security"> ${orSecurityItem1.securityTypes} </span> </div> <div class="tooltip-text" style="position:absolute;color:var(--fg);top:26px;right:0;border:1px solid var(--border-color);padding:2px 4px;display:block"> ${orSecurityItem1.securityDefs.length > 1 ? (0, _lit.html)`<div>Requires <b>all</b> of the following </div>` : ''} <div style="padding-left:8px"> ${orSecurityItem1.securityDefs.map((andSecurityItem, j) => (0, _lit.html)` ${andSecurityItem.type === 'oauth2' ? (0, _lit.html)` <div> ${orSecurityItem1.securityDefs.length > 1 ? (0, _lit.html)`<b>${j + 1}.</b> ` : (0, _lit.html)`Requires`} OAuth token (${andSecurityItem.apiKeyId}) in <b>Authorization header</b> ${getOauthScopeTemplate(andSecurityItem.scopes)} </div>` : andSecurityItem.type === 'http' ? (0, _lit.html)` <div> ${orSecurityItem1.securityDefs.length > 1 ? (0, _lit.html)`<b>${j + 1}.</b> ` : (0, _lit.html)`${(0, _index.getI18nText)('authentication.requires')}`} ${andSecurityItem.scheme === 'basic' ? (0, _index.getI18nText)('authentication.http-basic-note') : 'Bearer Token'} ${(0, _index.getI18nText)('authentication.in-auth-header')} ${getOauthScopeTemplate(andSecurityItem.scopes)} </div>` : (0, _lit.html)` <div> ${orSecurityItem1.securityDefs.length > 1 ? (0, _lit.html)`<b>${j + 1}.</b> ` : (0, _lit.html)`Requires`} Token in <b>${andSecurityItem.name} ${andSecurityItem.in}</b> ${getOauthScopeTemplate(andSecurityItem.scopes)} </div>`} `)} </div> </div> </div> `)} </div> </div>`;
|
414
347
|
}
|
415
|
-
|
416
348
|
return '';
|
417
349
|
}
|
350
|
+
|
418
351
|
/* eslint-enable indent */
|
@@ -2,22 +2,16 @@
|
|
2
2
|
|
3
3
|
exports.__esModule = true;
|
4
4
|
exports.default = serverTemplate;
|
5
|
-
|
6
5
|
var _lit = require("lit");
|
7
|
-
|
8
6
|
var _marked = require("marked");
|
9
|
-
|
10
7
|
var _unsafeHtml = require("lit/directives/unsafe-html.js");
|
11
|
-
|
12
8
|
var _index = require("../languages/index.js");
|
13
|
-
|
14
9
|
function onApiServerChange(e, server) {
|
15
10
|
if (e && e.target.checked) {
|
16
11
|
this.selectedServer = server;
|
17
12
|
this.requestUpdate();
|
18
13
|
}
|
19
14
|
}
|
20
|
-
|
21
15
|
function onApiServerVarChange(e, serverObj) {
|
22
16
|
const inputEls = [...e.currentTarget.closest('table').querySelectorAll('input, select')];
|
23
17
|
let tempUrl = serverObj.url;
|
@@ -28,26 +22,21 @@ function onApiServerVarChange(e, serverObj) {
|
|
28
22
|
serverObj.computedUrl = tempUrl;
|
29
23
|
this.requestUpdate();
|
30
24
|
}
|
31
|
-
/* eslint-disable indent */
|
32
|
-
|
33
25
|
|
26
|
+
/* eslint-disable indent */
|
34
27
|
function serverVarsTemplate() {
|
35
28
|
var _this$selectedServer;
|
36
|
-
|
37
29
|
return Object.keys(((_this$selectedServer = this.selectedServer) === null || _this$selectedServer === void 0 ? void 0 : _this$selectedServer.variables) || {}).length ? (0, _lit.html)` <div class="table-title">${(0, _index.getI18nText)('api-servers.server-variables')}</div> <table role="presentation" class="m-table"> ${Object.entries(this.selectedServer.variables).map(kv => (0, _lit.html)` <tr> <td colspan="1" style="vertical-align:middle">${kv[0]}</td> <td colspan="2"> ${kv[1].enum ? (0, _lit.html)` <select data-var="${kv[0]}" @input="${e => {
|
38
30
|
onApiServerVarChange.call(this, e, this.selectedServer);
|
39
31
|
}}"> ${Object.entries(kv[1].enum).map(e => kv[1].default === e[1] ? (0, _lit.html)` <option selected="selected" label="${e[1]}" value="${e[1]}">` : (0, _lit.html)` <option label="${e[1]}" value="${e[1]}">`)} </select>` : (0, _lit.html)` <input type="text" part="textbox textbox-server-var" spellcheck="false" data-var="${kv[0]}" value="${kv[1].default}" @input="${e => {
|
40
32
|
onApiServerVarChange.call(this, e, this.selectedServer);
|
41
33
|
}}">`} </td> </tr> ${kv[1].description ? (0, _lit.html)`<tr><td colspan="2" style="border:none"><span class="m-markdown-small"> ${(0, _unsafeHtml.unsafeHTML)((0, _marked.marked)(kv[1].description))} </span></td></tr>` : ''} `)} </table> ` : '';
|
42
34
|
}
|
43
|
-
|
44
35
|
function serverTemplate() {
|
45
36
|
var _this$selectedServer2;
|
46
|
-
|
47
37
|
if (!this.resolvedSpec) {
|
48
38
|
return undefined;
|
49
39
|
}
|
50
|
-
|
51
40
|
return (0, _lit.html)` <section id="servers" part="section-servers" style="margin-top:24px;margin-bottom:24px" class="regular-font observe-me section-padding ${this.renderStyle === 'read' ? 'section-gap--read-mode' : this.renderStyle === 'focused' ? 'section-gap--focused-mode' : 'section-gap'}"> <div class="sub-title">${(0, _index.getI18nText)('headers.api-servers')}</div> <div class="mono-font" style="margin:12px 0;font-size:calc(var(--font-size-small) + 1px)"> ${!this.resolvedSpec.servers || !this.resolvedSpec.servers.length ? '' : (0, _lit.html)` ${this.resolvedSpec.servers.map((server, i) => (0, _lit.html)` <input type="radio" name="api_server" id="srvr-opt-${i}" value="${server.url}" @change="${e => {
|
52
41
|
onApiServerChange.call(this, e, server);
|
53
42
|
}}" .checked="${this.selectedServer.url === server.url}" style="margin:4px 0;cursor:pointer"> <label style="cursor:pointer" for="srvr-opt-${i}"> ${server.url} ${server.description ? (0, _lit.html)`- <span class="regular-font">${server.description} </span>` : ''} </label> <br> `)} `} <div class="table-title primary-text" part="label-selected-server"> ${(0, _index.getI18nText)('api-servers.selected')}: ${((_this$selectedServer2 = this.selectedServer) === null || _this$selectedServer2 === void 0 ? void 0 : _this$selectedServer2.computedUrl) || 'none'}</div> </div> <slot name="servers"></slot> ${serverVarsTemplate.call(this)} </section>`;
|
@@ -2,28 +2,22 @@
|
|
2
2
|
|
3
3
|
exports.__esModule = true;
|
4
4
|
exports.default = void 0;
|
5
|
-
|
6
5
|
/* eslint-disable no-mixed-operators */
|
7
|
-
|
8
6
|
/* eslint-disable no-bitwise */
|
9
|
-
var _default = {
|
7
|
+
var _default = exports.default = {
|
10
8
|
color: {
|
11
9
|
inputReverseFg: '#fff',
|
12
10
|
inputReverseBg: '#333',
|
13
11
|
headerBg: '#444',
|
14
|
-
|
15
12
|
getRgb(hexStr) {
|
16
13
|
let hex = (hexStr || '').trim();
|
17
|
-
|
18
14
|
if (hex.indexOf('#') === 0) {
|
19
15
|
hex = hex.slice(1, 7);
|
20
|
-
}
|
21
|
-
|
22
|
-
|
16
|
+
}
|
17
|
+
// convert 3-digit hex to 6-digits.
|
23
18
|
if (hex.length === 3 || hex.length === 4) {
|
24
19
|
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
|
25
20
|
}
|
26
|
-
|
27
21
|
if (hex.length !== 6) {
|
28
22
|
// eslint-disable-next-line no-console
|
29
23
|
console.error(`Invalid HEX color: '${hexStr}'`);
|
@@ -33,24 +27,20 @@ var _default = {
|
|
33
27
|
b: 0
|
34
28
|
};
|
35
29
|
}
|
36
|
-
|
37
30
|
return {
|
38
31
|
r: parseInt(hex.slice(0, 2), 16),
|
39
32
|
g: parseInt(hex.slice(2, 4), 16),
|
40
33
|
b: parseInt(hex.slice(4, 6), 16)
|
41
34
|
};
|
42
35
|
},
|
43
|
-
|
44
36
|
luminanace(hexColorCode) {
|
45
37
|
const rgb = this.getRgb(hexColorCode);
|
46
38
|
return rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114;
|
47
39
|
},
|
48
|
-
|
49
40
|
invert(hexColorCode) {
|
50
41
|
// compare with `>=128`, but giving little more preference to white over black
|
51
42
|
return this.luminanace(hexColorCode) > 149 ? '#000000' : '#ffffff';
|
52
43
|
},
|
53
|
-
|
54
44
|
// https://stackoverflow.com/a/41491220/5091874
|
55
45
|
selectTextColorFromBackground(bcHexColor) {
|
56
46
|
const {
|
@@ -63,50 +53,39 @@ var _default = {
|
|
63
53
|
if (col <= 0.03928) {
|
64
54
|
return col / 12.92;
|
65
55
|
}
|
66
|
-
|
67
56
|
return ((col + 0.055) / 1.055) ** 2.4;
|
68
57
|
});
|
69
58
|
const L = 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
|
70
59
|
return L > 0.179 ? '#000000' : '#FFFFFF';
|
71
60
|
},
|
72
|
-
|
73
61
|
opacity(hex, opacity) {
|
74
62
|
const rgb = this.getRgb(hex);
|
75
63
|
return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${opacity})`;
|
76
64
|
},
|
77
|
-
|
78
65
|
brightness(hex, amt) {
|
79
66
|
const rgb = this.getRgb(hex);
|
80
67
|
rgb.r += amt;
|
81
68
|
rgb.g += amt;
|
82
69
|
rgb.b += amt;
|
83
|
-
|
84
70
|
if (rgb.r > 255) {
|
85
71
|
rgb.r = 255;
|
86
72
|
} else if (rgb.r < 0) {
|
87
73
|
rgb.r = 0;
|
88
74
|
}
|
89
|
-
|
90
75
|
if (rgb.g > 255) {
|
91
76
|
rgb.g = 255;
|
92
77
|
} else if (rgb.g < 0) {
|
93
78
|
rgb.g = 0;
|
94
79
|
}
|
95
|
-
|
96
80
|
if (rgb.b > 255) {
|
97
81
|
rgb.b = 255;
|
98
82
|
} else if (rgb.b < 0) {
|
99
83
|
rgb.b = 0;
|
100
84
|
}
|
101
|
-
|
102
85
|
return `#${rgb.r.toString(16).padStart(2, '0')}${rgb.g.toString(16).padStart(2, '0')}${rgb.b.toString(16).padStart(2, '0')}`;
|
103
86
|
}
|
104
|
-
|
105
87
|
},
|
106
|
-
|
107
88
|
isValidHexColor(colorCode) {
|
108
89
|
return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/i.test(colorCode);
|
109
90
|
}
|
110
|
-
|
111
|
-
};
|
112
|
-
exports.default = _default;
|
91
|
+
};
|