openapi-explorer 2.1.654 → 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 +2 -2
- 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 +1 -6
- 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
@@ -2,41 +2,25 @@
|
|
2
2
|
|
3
3
|
exports.__esModule = true;
|
4
4
|
exports.default = void 0;
|
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 _keyed = require("lit/directives/keyed.js");
|
13
|
-
|
14
9
|
var _xmlButPrettier = _interopRequireDefault(require("xml-but-prettier"));
|
15
|
-
|
16
10
|
var _index = require("../languages/index.js");
|
17
|
-
|
18
11
|
var _schemaUtils = require("../utils/schema-utils.js");
|
19
|
-
|
20
12
|
require("./schema-tree.js");
|
21
|
-
|
22
13
|
var _requestFormTable = _interopRequireDefault(require("./request-form-table.js"));
|
23
|
-
|
24
14
|
require("./tag-input.js");
|
25
|
-
|
26
15
|
require("./syntax-highlighter.js");
|
27
|
-
|
28
16
|
var _json = _interopRequireDefault(require("json5"));
|
29
|
-
|
30
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
31
|
-
|
32
18
|
const textFileRegex = RegExp('^font/|tar$|zip$|7z$|rtf$|msword$|excel$|/pdf$|/octet-stream$|^application/vnd.');
|
33
19
|
const mediaFileRegex = RegExp('^audio/|^image/|^video/');
|
34
|
-
|
35
20
|
class ApiRequest extends _lit.LitElement {
|
36
21
|
createRenderRoot() {
|
37
22
|
return this;
|
38
23
|
}
|
39
|
-
|
40
24
|
constructor() {
|
41
25
|
super();
|
42
26
|
this.duplicatedRowsByKey = {};
|
@@ -50,11 +34,9 @@ class ApiRequest extends _lit.LitElement {
|
|
50
34
|
this.responseElapsedMs = 0;
|
51
35
|
this.curlSyntax = '';
|
52
36
|
this.activeResponseTab = 'curl'; // allowed values: response, headers, curl
|
53
|
-
|
54
37
|
this.selectedRequestBodyType = '';
|
55
38
|
this.selectedRequestBodyExample = '';
|
56
39
|
}
|
57
|
-
|
58
40
|
static get properties() {
|
59
41
|
return {
|
60
42
|
serverUrl: {
|
@@ -127,11 +109,9 @@ class ApiRequest extends _lit.LitElement {
|
|
127
109
|
includeNulls: {
|
128
110
|
type: Boolean,
|
129
111
|
attribute: 'display-nulls',
|
130
|
-
|
131
112
|
converter(value) {
|
132
113
|
return value === 'true';
|
133
114
|
}
|
134
|
-
|
135
115
|
},
|
136
116
|
allowTry: {
|
137
117
|
type: String,
|
@@ -179,46 +159,38 @@ class ApiRequest extends _lit.LitElement {
|
|
179
159
|
type: String,
|
180
160
|
attribute: 'selected-request-body-example'
|
181
161
|
} // internal tracking of selected request-body example
|
182
|
-
|
183
162
|
};
|
184
163
|
}
|
185
|
-
|
186
164
|
render() {
|
187
165
|
const id = this.elementId || `${this.method}-${this.path}`;
|
188
166
|
return (0, _keyed.keyed)(id, (0, _lit.html)` <div id="api-request-${id}" class="api-request col regular-font request-panel ${this.renderStyle === 'focused' || this.callback === 'true' ? 'focused-mode' : 'view-mode'}"> <div class="${this.callback === 'true' ? 'tiny-title' : 'req-res-title'}"> ${this.callback === 'true' ? 'CALLBACK REQUEST' : (0, _index.getI18nText)('operations.request')} </div> <div> ${this.inputParametersTemplate('path')} ${this.inputParametersTemplate('query')} ${this.requestBodyTemplate()} ${this.inputParametersTemplate('header')} ${this.inputParametersTemplate('cookie')} ${this.allowTry === 'false' ? '' : (0, _lit.html)`${this.apiCallTemplate()}`} </div> </div> `);
|
189
167
|
}
|
190
|
-
|
191
168
|
updated(changedProperties) {
|
192
169
|
// In focused mode after rendering the request component, update the text-areas(which contains examples) using the original values from hidden textareas.
|
193
170
|
// This is done coz, user may update the dom by editing the textarea's and once the DOM is updated externally change detection wont happen, therefore update the values manually
|
194
171
|
if (this.renderStyle !== 'focused') {
|
195
172
|
return;
|
196
|
-
}
|
197
|
-
|
173
|
+
}
|
198
174
|
|
175
|
+
// dont update example as only tabs is switched
|
199
176
|
if (changedProperties.size === 1 && changedProperties.has('activeSchemaTab')) {
|
200
177
|
return;
|
201
178
|
}
|
202
|
-
|
203
179
|
const exampleTextAreaEls = [...this.querySelectorAll('textarea[data-ptype="form-data"]')];
|
204
180
|
exampleTextAreaEls.forEach(el => {
|
205
181
|
const origExampleEl = this.querySelector(`textarea[data-pname='hidden-${el.dataset.pname}']`);
|
206
|
-
|
207
182
|
if (origExampleEl) {
|
208
183
|
el.value = origExampleEl.value;
|
209
184
|
}
|
210
185
|
});
|
211
186
|
}
|
212
|
-
/* eslint-disable indent */
|
213
|
-
|
214
187
|
|
188
|
+
/* eslint-disable indent */
|
215
189
|
inputParametersTemplate(paramLocation) {
|
216
190
|
const filteredParams = this.parameters ? this.parameters.filter(param => param.in === paramLocation) : [];
|
217
|
-
|
218
191
|
if (filteredParams.length === 0) {
|
219
192
|
return '';
|
220
193
|
}
|
221
|
-
|
222
194
|
const title = {
|
223
195
|
path: 'PATH PARAMETERS',
|
224
196
|
query: 'QUERY-STRING PARAMETERS',
|
@@ -226,36 +198,28 @@ class ApiRequest extends _lit.LitElement {
|
|
226
198
|
cookie: 'COOKIES'
|
227
199
|
}[paramLocation];
|
228
200
|
const tableRows = [];
|
229
|
-
|
230
201
|
for (const param of filteredParams) {
|
231
202
|
var _this$storedParamValu;
|
232
|
-
|
233
203
|
if (!param.schema) {
|
234
204
|
continue;
|
235
205
|
}
|
236
|
-
|
237
206
|
const paramSchema = (0, _schemaUtils.getTypeInfo)(param.schema, {
|
238
207
|
includeNulls: this.includeNulls
|
239
208
|
});
|
240
|
-
|
241
209
|
if (!paramSchema) {
|
242
210
|
continue;
|
243
211
|
}
|
244
|
-
|
245
212
|
const defaultVal = Array.isArray(paramSchema.default) ? paramSchema.default : `${paramSchema.default}`;
|
246
213
|
let paramStyle = 'form';
|
247
214
|
let paramExplode = true;
|
248
|
-
|
249
215
|
if (paramLocation === 'query') {
|
250
216
|
if (param.style && 'form spaceDelimited pipeDelimited'.includes(param.style)) {
|
251
217
|
paramStyle = param.style;
|
252
218
|
}
|
253
|
-
|
254
219
|
if (typeof param.explode === 'boolean') {
|
255
220
|
paramExplode = param.explode;
|
256
221
|
}
|
257
222
|
}
|
258
|
-
|
259
223
|
tableRows.push((0, _lit.html)` <tr> <td colspan="1" style="width:160px;min-width:50px;vertical-align:top"> <div class="param-name ${paramSchema.deprecated ? 'deprecated' : ''}" style="margin-top:1rem"> ${param.name}${!paramSchema.deprecated && param.required ? (0, _lit.html)`<span style="color:var(--red)">*</span>` : ''} </div> <div class="param-type" style="margin-bottom:1rem"> ${paramSchema.type === 'array' ? `${paramSchema.arrayType}` : `${paramSchema.format ? paramSchema.format : paramSchema.type}`}${!paramSchema.deprecated && param.required ? (0, _lit.html)`<span style="opacity:0">*</span>` : ''} </div> </td> <td colspan="2" style="min-width:160px;vertical-align:top"> ${this.allowTry === 'true' ? paramSchema.type === 'array' && (0, _lit.html)` <div style="margin-top:1rem;margin-bottom:1rem"> <tag-input class="request-param" style="width:100%" data-ptype="${paramLocation}" data-pname="${param.name}" data-default="${Array.isArray(defaultVal) ? defaultVal.join('~|~') : defaultVal}" data-param-serialize-style="${paramStyle}" data-param-serialize-explode="${paramExplode}" data-array="true" placeholder="add-multiple ↩" @change="${e => {
|
260
224
|
this.storedParamValues[param.name] = e.detail.value;
|
261
225
|
this.computeCurlSyntax();
|
@@ -265,41 +229,33 @@ class ApiRequest extends _lit.LitElement {
|
|
265
229
|
this.computeCurlSyntax();
|
266
230
|
}}" placeholder="${paramSchema.example || defaultVal || ''}" class="request-param" part="textbox textbox-param" data-ptype="${paramLocation}" data-pname="${param.name}" data-default="${Array.isArray(defaultVal) ? defaultVal.join('~|~') : defaultVal}" data-array="false" @keyup="${this.requestParamFunction}" .value="${this.fillRequestWithDefault === 'true' ? defaultVal : ''}">` : ''} ${this.exampleListTemplate.call(this, param, paramSchema.type)} </td> ${this.renderStyle === 'focused' ? (0, _lit.html)` <td colspan="2" style="vertical-align:top"> ${param.description ? (0, _lit.html)` <div class="param-description" style="margin-top:1rem"> ${(0, _unsafeHtml.unsafeHTML)((0, _marked.marked)(param.description))} </div>` : ''} ${paramSchema.constraints.length || paramSchema.allowedValues || paramSchema.pattern ? (0, _lit.html)` <div class="param-constraint" style="margin-top:1rem"> ${paramSchema.constraints.length ? (0, _lit.html)`<span style="font-weight:700">Constraints: </span>${paramSchema.constraints.join(', ')}<br>` : ''} ${paramSchema.pattern ? (0, _lit.html)` <div class="tooltip tooltip-replace" style="cursor:pointer;max-width:100%;display:flex"> <div style="white-space:nowrap;font-weight:700;margin-right:2px">Pattern: </div> <div style="white-space:nowrap;text-overflow:ellipsis;max-width:100%;overflow:hidden">${paramSchema.pattern}</div> <br> <div class="tooltip-text" style="position:absolute;display:block">${paramSchema.pattern}</div> </div> ` : ''} ${paramSchema.allowedValues && paramSchema.allowedValues.split('┃').map((v, i) => (0, _lit.html)` ${i > 0 ? '|' : (0, _lit.html)`<span style="font-weight:700">Allowed: </span>`} ${(0, _lit.html)` <a part="anchor anchor-param-constraint" class="${this.allowTry === 'true' ? '' : 'inactive-link'}" data-type="${paramSchema.type === 'array' ? 'array' : 'string'}" data-enum="${v.trim()}" @click="${e => {
|
267
231
|
const inputEl = e.target.closest('table').querySelector(`[data-pname="${param.name}"]`);
|
268
|
-
|
269
232
|
if (inputEl) {
|
270
233
|
inputEl.value = e.target.dataset.type === 'array' ? [e.target.dataset.enum] : e.target.dataset.enum;
|
271
234
|
}
|
272
235
|
}}"> ${v} </a>`}`)} </div>` : ''} </td> ` : ''} </tr>`);
|
273
236
|
}
|
274
|
-
|
275
237
|
return (0, _lit.html)` <div class="table-title top-gap">${title}${paramLocation === 'path' ? (0, _lit.html)`<span style="color:var(--red)">*</span>` : ''}</div> <div style="display:block;overflow-x:auto;max-width:100%"> <table role="presentation" class="m-table" style="width:100%;word-break:break-word"> ${tableRows} </table> </div>`;
|
276
238
|
}
|
277
|
-
|
278
239
|
renderExample(example, paramType, paramName) {
|
279
240
|
var _example$exampleValue, _example$exampleValue2;
|
280
|
-
|
281
241
|
return (0, _lit.html)` <a part="anchor anchor-param-example" class="${this.allowTry === 'true' ? '' : 'inactive-link'}" data-example-type="${paramType === 'array' ? paramType : 'string'}" data-example="${Array.isArray(example.exampleValue) ? (_example$exampleValue = example.exampleValue) === null || _example$exampleValue === void 0 ? void 0 : _example$exampleValue.join('~|~') : example.exampleValue}" @click="${e => {
|
282
242
|
const inputEl = e.target.closest('table').querySelector(`[data-pname="${paramName}"]`);
|
283
|
-
|
284
243
|
if (inputEl) {
|
285
244
|
inputEl.value = paramType === 'array' ? e.target.dataset.example.split('~|~') || [] : e.target.dataset.example;
|
286
245
|
}
|
287
246
|
}}">${Array.isArray(example.exampleValue) ? (_example$exampleValue2 = example.exampleValue) === null || _example$exampleValue2 === void 0 ? void 0 : _example$exampleValue2.join(', ') : example.exampleValue} </a> `;
|
288
247
|
}
|
289
|
-
|
290
248
|
renderShortFormatExamples(examples, paramType, paramName) {
|
291
249
|
return (0, _lit.html)`${examples.map((example, i) => (0, _lit.html)` ${i === 0 ? '' : '┃'} ${this.renderExample(example, paramType, paramName)}`)}`;
|
292
250
|
}
|
293
|
-
|
294
251
|
renderLongFormatExamples(exampleList, paramType, paramName) {
|
295
252
|
return (0, _lit.html)` <ul style="margin-block-start:.25em"> ${exampleList.map(example => {
|
296
253
|
var _example$exampleSumma, _example$exampleDescr;
|
297
|
-
|
298
254
|
return (0, _lit.html)` <li> ${this.renderExample(example, paramType, paramName)} ${((_example$exampleSumma = example.exampleSummary) === null || _example$exampleSumma === void 0 ? void 0 : _example$exampleSumma.length) > 0 ? (0, _lit.html)`<span>(${example.exampleSummary})</span>` : ''} ${((_example$exampleDescr = example.exampleDescription) === null || _example$exampleDescr === void 0 ? void 0 : _example$exampleDescr.length) > 0 ? (0, _lit.html)`<p>${(0, _unsafeHtml.unsafeHTML)((0, _marked.marked)(example.exampleDescription))}</p>` : ''} </li>`;
|
299
255
|
})} </ul>`;
|
300
256
|
}
|
301
|
-
/* eslint-disable indent */
|
302
257
|
|
258
|
+
/* eslint-disable indent */
|
303
259
|
|
304
260
|
exampleListTemplate(param, paramType) {
|
305
261
|
const paramName = param.name;
|
@@ -317,30 +273,26 @@ class ApiRequest extends _lit.LitElement {
|
|
317
273
|
}, null, param.schema, null, false, true, 'json', false);
|
318
274
|
const someExampleWithSummaryOrDescription = examples.some(x => {
|
319
275
|
var _x$exampleSummary, _x$exampleDescription;
|
320
|
-
|
321
276
|
return ((_x$exampleSummary = x.exampleSummary) === null || _x$exampleSummary === void 0 ? void 0 : _x$exampleSummary.length) > 0 || ((_x$exampleDescription = x.exampleDescription) === null || _x$exampleDescription === void 0 ? void 0 : _x$exampleDescription.length) > 0;
|
322
277
|
});
|
323
|
-
|
324
278
|
if (!examples.length) {
|
325
279
|
return '';
|
326
|
-
}
|
327
|
-
|
280
|
+
}
|
328
281
|
|
282
|
+
// Don't show an example if there is just one without a description because it is the same as the placeholder for the field
|
329
283
|
if (examples.length === 1 && !someExampleWithSummaryOrDescription) {
|
330
284
|
return '';
|
331
285
|
}
|
332
|
-
|
333
286
|
return (0, _lit.html)`<div style="min-width:50px;margin-bottom:1rem"> <span style="font-weight:700">Examples: </span> ${someExampleWithSummaryOrDescription ? this.renderLongFormatExamples(examples, paramType, paramName) : this.renderShortFormatExamples(examples, paramType, paramName)} </div>`;
|
334
287
|
}
|
335
|
-
|
336
288
|
resetRequestBodySelection() {
|
337
289
|
this.selectedRequestBodyType = '';
|
338
290
|
this.selectedRequestBodyExample = '';
|
339
291
|
this.computeCurlSyntax();
|
340
292
|
this.clearResponseData();
|
341
|
-
}
|
342
|
-
|
293
|
+
}
|
343
294
|
|
295
|
+
// Request-Body Event Handlers
|
344
296
|
onSelectExample(e) {
|
345
297
|
this.selectedRequestBodyExample = e.target.value;
|
346
298
|
const exampleDropdownEl = e.target;
|
@@ -351,37 +303,31 @@ class ApiRequest extends _lit.LitElement {
|
|
351
303
|
this.computeCurlSyntax();
|
352
304
|
}, 0, exampleDropdownEl);
|
353
305
|
}
|
354
|
-
|
355
306
|
onMimeTypeChange(e) {
|
356
307
|
this.selectedRequestBodyType = e.target.value;
|
357
308
|
const mimeDropdownEl = e.target;
|
358
309
|
this.selectedRequestBodyExample = '';
|
359
310
|
window.setTimeout(selectEl => {
|
360
311
|
const exampleTextareaEl = selectEl.closest('.request-body-container').querySelector('.request-body-param');
|
361
|
-
|
362
312
|
if (exampleTextareaEl) {
|
363
313
|
const userInputExampleTextareaEl = selectEl.closest('.request-body-container').querySelector('.request-body-param-user-input');
|
364
314
|
userInputExampleTextareaEl.value = exampleTextareaEl.value;
|
365
315
|
}
|
366
|
-
|
367
316
|
this.computeCurlSyntax();
|
368
317
|
}, 0, mimeDropdownEl);
|
369
318
|
}
|
370
|
-
|
371
319
|
requestBodyTemplate() {
|
372
320
|
if (!this.request_body) {
|
373
321
|
return '';
|
374
322
|
}
|
375
|
-
|
376
323
|
if (Object.keys(this.request_body).length === 0) {
|
377
324
|
return '';
|
378
325
|
}
|
379
|
-
|
380
326
|
if (this.method === 'get' || this.method === 'head') {
|
381
327
|
return '';
|
382
|
-
}
|
383
|
-
|
328
|
+
}
|
384
329
|
|
330
|
+
// Variable to store partial HTMLs
|
385
331
|
let reqBodyTypeSelectorHtml = '';
|
386
332
|
let reqBodyFileInputHtml = '';
|
387
333
|
let reqBodySchemaHtml = '';
|
@@ -389,7 +335,6 @@ class ApiRequest extends _lit.LitElement {
|
|
389
335
|
let bodyTabNameUseBody = true;
|
390
336
|
const requestBodyTypes = [];
|
391
337
|
const content = this.request_body.content;
|
392
|
-
|
393
338
|
for (const mimeType in content) {
|
394
339
|
requestBodyTypes.push({
|
395
340
|
mimeType,
|
@@ -398,25 +343,22 @@ class ApiRequest extends _lit.LitElement {
|
|
398
343
|
examples: content[mimeType].examples
|
399
344
|
});
|
400
345
|
}
|
401
|
-
|
402
346
|
if (!content[this.selectedRequestBodyType]) {
|
403
347
|
var _requestBodyTypes$;
|
404
|
-
|
405
348
|
this.selectedRequestBodyType = (_requestBodyTypes$ = requestBodyTypes[0]) === null || _requestBodyTypes$ === void 0 ? void 0 : _requestBodyTypes$.mimeType;
|
406
|
-
}
|
407
|
-
|
408
|
-
|
409
|
-
reqBodyTypeSelectorHtml = requestBodyTypes.length === 1 ? '' : (0, _lit.html)` <select aria-label="mime type" style="min-width:100px;max-width:100%;margin-bottom:-1px" @change="${e => this.onMimeTypeChange(e)}"> ${requestBodyTypes.map(reqBody => (0, _lit.html)` <option value="${reqBody.mimeType}" ?selected="${reqBody.mimeType === this.selectedRequestBodyType}"> ${reqBody.mimeType} </option> `)} </select> `; // For Loop - Main
|
349
|
+
}
|
410
350
|
|
411
|
-
|
351
|
+
// MIME Type selector
|
352
|
+
reqBodyTypeSelectorHtml = requestBodyTypes.length === 1 ? '' : (0, _lit.html)` <select aria-label="mime type" style="min-width:100px;max-width:100%;margin-bottom:-1px" @change="${e => this.onMimeTypeChange(e)}"> ${requestBodyTypes.map(reqBody => (0, _lit.html)` <option value="${reqBody.mimeType}" ?selected="${reqBody.mimeType === this.selectedRequestBodyType}"> ${reqBody.mimeType} </option> `)} </select> `;
|
412
353
|
|
354
|
+
// For Loop - Main
|
355
|
+
const reqBody = requestBodyTypes.find(req => req.mimeType === this.selectedRequestBodyType);
|
356
|
+
// Generate Example
|
413
357
|
if (this.selectedRequestBodyType.includes('json') || this.selectedRequestBodyType.includes('xml') || this.selectedRequestBodyType.includes('text')) {
|
414
358
|
const reqBodyExamples = (0, _schemaUtils.generateExample)(reqBody.examples ? reqBody.examples : '', reqBody.example ? reqBody.example : '', reqBody.schema, reqBody.mimeType, false, true, 'text', true);
|
415
|
-
|
416
359
|
if (!this.selectedRequestBodyExample) {
|
417
360
|
this.selectedRequestBodyExample = reqBodyExamples.length > 0 ? reqBodyExamples[0].exampleId : '';
|
418
361
|
}
|
419
|
-
|
420
362
|
const displayedBodyExample = reqBodyExamples.find(v => v.exampleId === this.selectedRequestBodyExample) || reqBodyExamples[0];
|
421
363
|
reqBodyDefaultHtml = (0, _lit.html)` <div class="example-panel border-top pad-top-8"> ${reqBodyExamples.length === 1 ? '' : (0, _lit.html)` <select aria-label="request body example" style="min-width:100px;max-width:100%;margin-bottom:-1px" @change="${e => this.onSelectExample(e)}"> ${reqBodyExamples.map(v => (0, _lit.html)`<option value="${v.exampleId}" ?selected="${v.exampleId === this.selectedRequestBodyExample}"> ${v.exampleSummary.length > 80 ? v.exampleId : v.exampleSummary ? v.exampleSummary : v.exampleId} </option>`)} </select>`} ${displayedBodyExample ? (0, _lit.html)` <div class="example" data-default="${displayedBodyExample.exampleId}"> ${displayedBodyExample.exampleSummary && displayedBodyExample.exampleSummary.length > 80 ? (0, _lit.html)`<div style="padding:4px 0"> ${displayedBodyExample.exampleSummary} </div>` : ''} ${displayedBodyExample.exampleDescription ? (0, _lit.html)`<div class="m-markdown-small" style="padding:4px 0"> ${(0, _unsafeHtml.unsafeHTML)((0, _marked.marked)(displayedBodyExample.exampleDescription || ''))} </div>` : ''} <slot name="${this.elementId}--request-body"> <textarea @input="${() => {
|
422
364
|
this.computeCurlSyntax();
|
@@ -429,27 +371,27 @@ class ApiRequest extends _lit.LitElement {
|
|
429
371
|
reqBodyDefaultHtml = _requestFormTable.default.call(this, schemaAsObj, this.selectedRequestBodyType);
|
430
372
|
} else if (mediaFileRegex.test(this.selectedRequestBodyType) || textFileRegex.test(this.selectedRequestBodyType)) {
|
431
373
|
reqBodyFileInputHtml = (0, _lit.html)` <div class="small-font-size bold-text row"> <input type="file" part="file-input" style="max-width:100%" class="request-body-param-file" data-ptype="${reqBody.mimeType}" spellcheck="false"> </div> `;
|
432
|
-
}
|
433
|
-
|
374
|
+
}
|
434
375
|
|
376
|
+
// Generate Schema
|
435
377
|
if (reqBody.mimeType.includes('json') || reqBody.mimeType.includes('xml') || reqBody.mimeType.includes('text') || reqBody.mimeType.includes('form-')) {
|
436
378
|
const schemaAsObj = (0, _schemaUtils.schemaInObjectNotation)(reqBody.schema, {
|
437
379
|
includeNulls: this.includeNulls
|
438
380
|
});
|
439
|
-
|
440
381
|
if (this.schemaStyle === 'table') {
|
441
382
|
reqBodySchemaHtml = (0, _lit.html)` ${reqBodySchemaHtml} <schema-table class="${reqBody.mimeType.substring(reqBody.mimeType.indexOf('/') + 1)} pad-top-8" style="display:${this.selectedRequestBodyType === reqBody.mimeType ? 'block' : 'none'}" .data="${schemaAsObj}" schema-expand-level="${this.schemaExpandLevel}" schema-hide-read-only="${this.schemaHideReadOnly.includes(this.method)}" schema-hide-write-only="false"> </schema-table> `;
|
442
383
|
} else {
|
443
384
|
reqBodySchemaHtml = (0, _lit.html)` ${reqBodySchemaHtml} <schema-tree class="${reqBody.mimeType.substring(reqBody.mimeType.indexOf('/') + 1)} pad-top-8" style="display:${this.selectedRequestBodyType === reqBody.mimeType ? 'block' : 'none'}" .data="${schemaAsObj}" schema-expand-level="${this.schemaExpandLevel}" schema-hide-read-only="${this.schemaHideReadOnly.includes(this.method)}" schema-hide-write-only="false"> </schema-tree> `;
|
444
385
|
}
|
445
386
|
}
|
446
|
-
|
447
387
|
return (0, _lit.html)` <div class="request-body-container" data-selected-request-body-type="${this.selectedRequestBodyType}"> <div class="table-title top-gap row"> ${(0, _index.getI18nText)('operations.request-body')} ${this.request_body.required ? (0, _lit.html)`<span class="mono-font" style="color:var(--red)">*</span>` : ''} <span style="font-weight:400;margin-left:5px"> ${this.selectedRequestBodyType}</span> <span style="flex:1"></span> ${reqBodyTypeSelectorHtml} </div> ${this.request_body.description ? (0, _lit.html)`<div class="m-markdown" style="margin-bottom:12px">${(0, _unsafeHtml.unsafeHTML)((0, _marked.marked)(this.request_body.description))}</div>` : ''} ${reqBodySchemaHtml || reqBodyDefaultHtml ? (0, _lit.html)` <div class="tab-panel col" style="border-width:0 0 1px 0"> <div class="tab-buttons row" @click="${e => {
|
448
388
|
if (e.target.tagName.toLowerCase() === 'button') {
|
449
389
|
this.activeSchemaTab = e.target.dataset.tab;
|
450
390
|
}
|
451
391
|
}}"> <button class="tab-btn ${this.activeSchemaTab === 'model' ? 'active' : ''}" data-tab="model">${(0, _index.getI18nText)('operations.model')}</button> <button class="tab-btn ${this.activeSchemaTab !== 'model' ? 'active' : ''}" data-tab="body">${bodyTabNameUseBody ? (0, _index.getI18nText)('operations.body') : (0, _index.getI18nText)('operations.form')}</button> </div> ${(0, _lit.html)`<div class="tab-content col" style="display:${this.activeSchemaTab === 'model' ? 'block' : 'none'}"> ${reqBodySchemaHtml}</div>`} ${(0, _lit.html)`<div class="tab-content col" style="display:${this.activeSchemaTab === 'model' ? 'none' : 'block'}"> ${reqBodyDefaultHtml}</div>`} </div>` : (0, _lit.html)`${reqBodyFileInputHtml}`} </div> `;
|
452
|
-
}
|
392
|
+
}
|
393
|
+
|
394
|
+
// formDataTemplate(schema, mimeType, exampleValue = '') {
|
453
395
|
// return html`
|
454
396
|
// <textarea
|
455
397
|
// class = "textarea dynamic-form-param ${mimeType}"
|
@@ -463,7 +405,6 @@ class ApiRequest extends _lit.LitElement {
|
|
463
405
|
// `;
|
464
406
|
// }
|
465
407
|
|
466
|
-
|
467
408
|
apiResponseTabTemplate() {
|
468
409
|
const curlSyntax = this.curlSyntax || this.computeCurlSyntax() || '';
|
469
410
|
const hasResponse = this.responseMessage !== '';
|
@@ -471,17 +412,14 @@ class ApiRequest extends _lit.LitElement {
|
|
471
412
|
if (e.target.classList.contains('tab-btn') === false) {
|
472
413
|
return;
|
473
414
|
}
|
474
|
-
|
475
415
|
this.activeResponseTab = e.target.dataset.tab;
|
476
416
|
}}"> <br> <div style="width:100%"> ${!hasResponse ? '' : (0, _lit.html)` <button class="tab-btn ${this.activeResponseTab === 'response' ? 'active' : ''}" data-tab="response">${(0, _index.getI18nText)('operations.response')}</button> <button class="tab-btn ${this.activeResponseTab === 'headers' ? 'active' : ''}" data-tab="headers">${(0, _index.getI18nText)('operations.response-headers')}</button>`} <button class="tab-btn ${!hasResponse || this.activeResponseTab === 'curl' ? 'active' : ''}" data-tab="curl">FULL REQUEST</button> </div> </div> ${this.responseIsBlob ? (0, _lit.html)` <div class="tab-content col" style="flex:1;display:${this.activeResponseTab === 'response' ? 'flex' : 'none'}"> ${this.responseBlobType === 'image' ? (0, _lit.html)`<img style="max-height:var(--resp-area-height,300px);object-fit:contain" class="mar-top-8" src="${this.responseBlobUrl}">` : ''} <div style="display:flex;justify-content:center"> <div> <button class="m-btn thin-border mar-top-8" style="width:135px" @click="${this.downloadResponseBlob}" part="btn btn-outline">DOWNLOAD</button> ${this.responseBlobType === 'view' || this.responseBlobType === 'image' ? (0, _lit.html)`<button class="m-btn thin-border mar-top-8" style="width:135px" @click="${this.viewResponseBlob}" part="btn btn-outline">VIEW (NEW TAB)</button>` : ''} </div> </div> </div>` : (0, _lit.html)` <div class="tab-content col m-markdown" style="flex:1;display:${this.activeResponseTab === 'response' ? 'flex' : 'none'}"> <syntax-highlighter style="min-height:60px" mime-type="${this.responseContentType}" .content="${this.responseText}"> </div>`} <div class="tab-content col m-markdown" style="flex:1;display:${this.activeResponseTab === 'headers' ? 'flex' : 'none'}"> <syntax-highlighter language="http" .content="${this.responseHeaders}"> </div> <div class="tab-content m-markdown col" style="flex:1;display:${this.activeResponseTab === 'curl' ? 'flex' : 'none'}"> <syntax-highlighter class="fs-exclude" data-hj-suppress data-sl="mask" language="shell" .content="${curlSyntax.trim()}"> </div> </div>`;
|
477
417
|
}
|
478
|
-
|
479
418
|
apiCallTemplate() {
|
480
419
|
return (0, _lit.html)` <div style="display:flex;align-items:flex-end;margin:16px 0;font-size:var(--font-size-small)"> ${this.parameters.length > 0 || this.request_body ? (0, _lit.html)` <button class="m-btn thin-border" part="btn btn-outline" style="margin-right:5px" @click="${this.onClearRequestData}"> ${(0, _index.getI18nText)('operations.clear')} </button>` : ''} <button class="m-btn primary btn-execute thin-border" part="btn btn-fill btn-try" @click="${this.onTryClick}">${(0, _index.getI18nText)('operations.execute')}</button> </div> ${this.apiResponseTabTemplate()} `;
|
481
420
|
}
|
482
421
|
/* eslint-enable indent */
|
483
422
|
|
484
|
-
|
485
423
|
onClearRequestData(e) {
|
486
424
|
const requestPanelEl = e.target.closest('.request-panel');
|
487
425
|
const requestPanelInputEls = [...requestPanelEl.querySelectorAll('input, tag-input, textarea:not(.is-hidden)')];
|
@@ -503,7 +441,6 @@ class ApiRequest extends _lit.LitElement {
|
|
503
441
|
this.dispatchEvent(new CustomEvent('event', event));
|
504
442
|
this.computeCurlSyntax();
|
505
443
|
}
|
506
|
-
|
507
444
|
recomputeFetchOptions() {
|
508
445
|
const closestRespContainer = this.closest('.expanded-req-resp-container, .req-resp-container');
|
509
446
|
const respEl = closestRespContainer && closestRespContainer.getElementsByTagName('api-response')[0];
|
@@ -514,25 +451,27 @@ class ApiRequest extends _lit.LitElement {
|
|
514
451
|
const queryParamObjTypeEls = [...requestPanelEl.querySelectorAll("[data-ptype='query-object']")];
|
515
452
|
const headerParamEls = [...requestPanelEl.querySelectorAll("[data-ptype='header']")];
|
516
453
|
const requestBodyContainerEl = requestPanelEl.querySelector('.request-body-container');
|
517
|
-
let pathUrl = `${this.serverUrl.replace(/\/$/, '')}${this.path.replaceAll(' ', '')}`;
|
454
|
+
let pathUrl = `${this.serverUrl.replace(/\/$/, '')}${this.path.replaceAll(' ', '')}`;
|
518
455
|
|
456
|
+
// Generate URL using Path Params
|
519
457
|
const pathParameterMap = {};
|
520
458
|
pathParamEls.map(el => {
|
521
459
|
pathParameterMap[el.dataset.pname] = el.value;
|
522
460
|
pathUrl = pathUrl.replace(`{${el.dataset.pname}}`, encodeURIComponent(el.value) || '-');
|
523
|
-
});
|
461
|
+
});
|
524
462
|
|
463
|
+
// Handle relative serverUrls
|
525
464
|
if (!pathUrl.startsWith('http')) {
|
526
465
|
const newUrl = new URL(pathUrl, window.location.href);
|
527
466
|
pathUrl = newUrl.toString();
|
528
467
|
}
|
529
|
-
|
530
468
|
const fetchUrl = new URL(pathUrl);
|
531
469
|
const fetchOptions = {
|
532
470
|
method: this.method.toUpperCase(),
|
533
471
|
headers: new Headers()
|
534
|
-
};
|
472
|
+
};
|
535
473
|
|
474
|
+
// Query Params
|
536
475
|
const queryParameterMap = {};
|
537
476
|
queryParamEls.forEach(el => {
|
538
477
|
if (!el.dataset.array || el.dataset.array === 'false') {
|
@@ -545,7 +484,6 @@ class ApiRequest extends _lit.LitElement {
|
|
545
484
|
const paramSerializeExplode = el.dataset.paramSerializeExplode;
|
546
485
|
const values = Array.isArray(el.value) ? el.value.filter(v => v !== '') : [];
|
547
486
|
queryParameterMap[el.dataset.pname] = values;
|
548
|
-
|
549
487
|
if (values.length > 0) {
|
550
488
|
if (paramSerializeStyle === 'spaceDelimited') {
|
551
489
|
fetchUrl.searchParams.append(el.dataset.pname, values.join(' ').replace(/^\s|\s$/g, ''));
|
@@ -563,15 +501,15 @@ class ApiRequest extends _lit.LitElement {
|
|
563
501
|
}
|
564
502
|
}
|
565
503
|
}
|
566
|
-
});
|
504
|
+
});
|
567
505
|
|
506
|
+
// Query Params (Dynamic - create from JSON)
|
568
507
|
queryParamObjTypeEls.map(el => {
|
569
508
|
try {
|
570
509
|
let queryParamObj = {};
|
571
510
|
const paramSerializeStyle = el.dataset.paramSerializeStyle;
|
572
511
|
const paramSerializeExplode = el.dataset.paramSerializeExplode;
|
573
512
|
queryParamObj = Object.assign(queryParamObj, JSON.parse(el.value.replace(/\s+/g, ' ')));
|
574
|
-
|
575
513
|
for (const key in queryParamObj) {
|
576
514
|
if (typeof queryParamObj[key] === 'object') {
|
577
515
|
if (Array.isArray(queryParamObj[key])) {
|
@@ -597,52 +535,51 @@ class ApiRequest extends _lit.LitElement {
|
|
597
535
|
} catch (err) {
|
598
536
|
console.log('OpenAPI Explorer: unable to parse %s into object', el.value); // eslint-disable-line no-console
|
599
537
|
}
|
600
|
-
});
|
538
|
+
});
|
601
539
|
|
540
|
+
// Add Authentication api keys if provided
|
602
541
|
this.api_keys.filter(v => v.finalKeyValue).forEach(v => {
|
603
542
|
if (v.in === 'query') {
|
604
543
|
fetchUrl.searchParams.append(v.name, v.finalKeyValue);
|
605
544
|
return;
|
606
|
-
}
|
607
|
-
|
545
|
+
}
|
608
546
|
|
547
|
+
// Otherwise put it in the header
|
609
548
|
fetchOptions.headers.append(v.name, v.finalKeyValue);
|
610
549
|
});
|
611
|
-
|
612
550
|
if (acceptHeader) {
|
613
551
|
// Uses the acceptHeader from Response panel
|
614
552
|
fetchOptions.headers.append('Accept', acceptHeader);
|
615
553
|
} else if (this.accept) {
|
616
554
|
fetchOptions.headers.append('Accept', this.accept);
|
617
|
-
}
|
618
|
-
|
555
|
+
}
|
619
556
|
|
557
|
+
// Add Header Params
|
620
558
|
headerParamEls.map(el => {
|
621
559
|
if (el.value) {
|
622
560
|
fetchOptions.headers.append(el.dataset.pname, el.value);
|
623
561
|
}
|
624
|
-
});
|
625
|
-
// url-encoded Form Params (dynamic) - Parse JSON and generate Params
|
562
|
+
});
|
626
563
|
|
627
|
-
|
564
|
+
// Request Body Params
|
628
565
|
|
566
|
+
// url-encoded Form Params (dynamic) - Parse JSON and generate Params
|
567
|
+
const formUrlDynamicTextAreaEl = requestPanelEl.querySelector("[data-ptype='dynamic-form']");
|
568
|
+
// url-encoded Form Params (regular)
|
629
569
|
const rawFormInputEls = [...requestPanelEl.querySelectorAll("[data-ptype='form-input']")];
|
630
570
|
const patternPropertyKeyEls = [...requestPanelEl.querySelectorAll("[data-ptype='pattern-property-key']")];
|
631
571
|
const patternPropertyInputEls = rawFormInputEls.filter(el => (0, _schemaUtils.isPatternProperty)(el.dataset.pname));
|
632
572
|
const formInputEls = rawFormInputEls.filter(el => !(0, _schemaUtils.isPatternProperty)(el.dataset.pname));
|
633
573
|
let curlData = '';
|
634
574
|
let curlForm = '';
|
635
|
-
|
636
575
|
if (requestBodyContainerEl) {
|
637
576
|
const requestBodyType = requestBodyContainerEl.dataset.selectedRequestBodyType;
|
638
|
-
|
639
577
|
if (requestBodyType.includes('form-urlencoded')) {
|
640
578
|
if (formUrlDynamicTextAreaEl) {
|
641
579
|
const val = formUrlDynamicTextAreaEl.value;
|
642
580
|
const formUrlDynParams = new URLSearchParams();
|
643
581
|
let proceed = true;
|
644
582
|
let tmpObj;
|
645
|
-
|
646
583
|
if (val) {
|
647
584
|
try {
|
648
585
|
tmpObj = JSON.parse(val);
|
@@ -653,12 +590,10 @@ class ApiRequest extends _lit.LitElement {
|
|
653
590
|
} else {
|
654
591
|
proceed = false;
|
655
592
|
}
|
656
|
-
|
657
593
|
if (proceed) {
|
658
594
|
for (const prop in tmpObj) {
|
659
595
|
formUrlDynParams.append(prop, JSON.stringify(tmpObj[prop]));
|
660
596
|
}
|
661
|
-
|
662
597
|
fetchOptions.body = formUrlDynParams;
|
663
598
|
curlData = ` \\\n -d ${formUrlDynParams.toString()}`;
|
664
599
|
}
|
@@ -666,13 +601,10 @@ class ApiRequest extends _lit.LitElement {
|
|
666
601
|
const formUrlParams = new URLSearchParams();
|
667
602
|
patternPropertyInputEls.concat(formInputEls).forEach((el, counter) => {
|
668
603
|
var _patternPropertyKeyEl;
|
669
|
-
|
670
604
|
const keyName = ((_patternPropertyKeyEl = patternPropertyKeyEls[counter]) === null || _patternPropertyKeyEl === void 0 ? void 0 : _patternPropertyKeyEl.value) || el.dataset.pname;
|
671
|
-
|
672
605
|
if (el.type === 'file') {
|
673
606
|
return;
|
674
607
|
}
|
675
|
-
|
676
608
|
if (el.dataset.array === 'false') {
|
677
609
|
if (el.value) {
|
678
610
|
formUrlParams.append(keyName, el.value);
|
@@ -689,9 +621,7 @@ class ApiRequest extends _lit.LitElement {
|
|
689
621
|
const formDataParams = new FormData();
|
690
622
|
patternPropertyInputEls.concat(formInputEls).forEach((el, counter) => {
|
691
623
|
var _patternPropertyKeyEl2;
|
692
|
-
|
693
624
|
const keyName = ((_patternPropertyKeyEl2 = patternPropertyKeyEls[counter]) === null || _patternPropertyKeyEl2 === void 0 ? void 0 : _patternPropertyKeyEl2.value) || el.dataset.pname;
|
694
|
-
|
695
625
|
if (el.dataset.array === 'false') {
|
696
626
|
if (el.type === 'file' && el.files[0]) {
|
697
627
|
formDataParams.append(keyName, el.files[0], el.files[0].name);
|
@@ -710,45 +640,35 @@ class ApiRequest extends _lit.LitElement {
|
|
710
640
|
fetchOptions.body = formDataParams;
|
711
641
|
} else if (mediaFileRegex.test(requestBodyType) || textFileRegex.test(requestBodyType)) {
|
712
642
|
const bodyParamFileEl = requestPanelEl.querySelector('.request-body-param-file');
|
713
|
-
|
714
643
|
if (bodyParamFileEl && bodyParamFileEl.files[0]) {
|
715
644
|
fetchOptions.body = bodyParamFileEl.files[0];
|
716
645
|
curlData = ` \\\n --data-binary @${bodyParamFileEl.files[0].name}`;
|
717
646
|
}
|
718
647
|
} else if (requestBodyType.includes('json') || requestBodyType.includes('xml') || requestBodyType.includes('text')) {
|
719
648
|
const exampleTextAreaEl = requestPanelEl.querySelector('.request-body-param-user-input');
|
720
|
-
|
721
649
|
if (exampleTextAreaEl && exampleTextAreaEl.value) {
|
722
650
|
fetchOptions.body = exampleTextAreaEl.value;
|
723
|
-
|
724
651
|
if (requestBodyType.includes('json')) {
|
725
652
|
fetchOptions.body = JSON.stringify(_json.default.parse(exampleTextAreaEl.value));
|
726
|
-
|
727
653
|
try {
|
728
654
|
curlData = ` \\\n -d '${fetchOptions.body}'`;
|
729
|
-
} catch (err) {
|
730
|
-
/* Ignore unparseable JSON */
|
731
|
-
}
|
655
|
+
} catch (err) {/* Ignore unparseable JSON */}
|
732
656
|
}
|
733
|
-
|
734
657
|
if (!curlData) {
|
735
658
|
// Save single quotes wrapped => 'text' => `"'"text"'"`
|
736
659
|
curlData = ` \\\n -d '${fetchOptions.body.replace(/'/g, '\'"\'"\'')}'`;
|
737
660
|
}
|
738
661
|
}
|
739
|
-
}
|
740
|
-
|
741
|
-
|
662
|
+
}
|
663
|
+
// Common for all request-body
|
742
664
|
if (!requestBodyType.includes('form-data')) {
|
743
665
|
// For multipart/form-data don't set the content-type to allow creation of browser generated part boundaries
|
744
666
|
fetchOptions.headers.append('Content-Type', requestBodyType);
|
745
667
|
}
|
746
668
|
}
|
747
|
-
|
748
669
|
if (this.fetchCredentials) {
|
749
670
|
fetchOptions.credentials = this.fetchCredentials;
|
750
671
|
}
|
751
|
-
|
752
672
|
return {
|
753
673
|
fetchOptions,
|
754
674
|
fetchUrl,
|
@@ -760,7 +680,6 @@ class ApiRequest extends _lit.LitElement {
|
|
760
680
|
}
|
761
681
|
};
|
762
682
|
}
|
763
|
-
|
764
683
|
computeCurlSyntax(headerOverride) {
|
765
684
|
const {
|
766
685
|
fetchOptions,
|
@@ -772,9 +691,9 @@ class ApiRequest extends _lit.LitElement {
|
|
772
691
|
const curlHeaders = [...headers.entries()].reduce((acc, [key, value]) => `${acc} \\\n -H "${key}: ${value}"`, '');
|
773
692
|
this.curlSyntax = `${curl}${curlHeaders}${curlParts.data}${curlParts.form}`;
|
774
693
|
this.requestUpdate();
|
775
|
-
}
|
776
|
-
|
694
|
+
}
|
777
695
|
|
696
|
+
// onExecuteButtonClicked
|
778
697
|
async onTryClick() {
|
779
698
|
const tryBtnEl = this.querySelectorAll('.btn-execute')[0];
|
780
699
|
const {
|
@@ -785,13 +704,12 @@ class ApiRequest extends _lit.LitElement {
|
|
785
704
|
} = this.recomputeFetchOptions();
|
786
705
|
this.responseIsBlob = false;
|
787
706
|
this.respContentDisposition = '';
|
788
|
-
|
789
707
|
if (this.responseBlobUrl) {
|
790
708
|
URL.revokeObjectURL(this.responseBlobUrl);
|
791
709
|
this.responseBlobUrl = '';
|
792
|
-
}
|
793
|
-
|
710
|
+
}
|
794
711
|
|
712
|
+
// Options is legacy usage, documentation has been updated to reference properties of the fetch option directly, but older usages may still be using options
|
795
713
|
const fetchRequest = {
|
796
714
|
explorerLocation: this.elementId,
|
797
715
|
url: fetchUrl.toString(),
|
@@ -818,7 +736,6 @@ class ApiRequest extends _lit.LitElement {
|
|
818
736
|
const fetchRequestObject = new Request(fetchRequest.url, newFetchOptions);
|
819
737
|
this.computeCurlSyntax(newFetchOptions.headers);
|
820
738
|
let fetchResponse;
|
821
|
-
|
822
739
|
try {
|
823
740
|
let respBlob;
|
824
741
|
let respJson;
|
@@ -849,7 +766,6 @@ class ApiRequest extends _lit.LitElement {
|
|
849
766
|
const contentType = fetchResponse.headers.get('content-type');
|
850
767
|
this.responseContentType = contentType;
|
851
768
|
const respEmpty = (await fetchResponse.clone().text()).length === 0;
|
852
|
-
|
853
769
|
if (respEmpty) {
|
854
770
|
this.responseText = '';
|
855
771
|
} else if (contentType) {
|
@@ -857,13 +773,11 @@ class ApiRequest extends _lit.LitElement {
|
|
857
773
|
if (/charset=[^"']+/.test(contentType)) {
|
858
774
|
const encoding = contentType.split('charset=')[1];
|
859
775
|
const buffer = await fetchResponse.arrayBuffer();
|
860
|
-
|
861
776
|
try {
|
862
777
|
respText = new TextDecoder(encoding).decode(buffer);
|
863
778
|
} catch (_) {
|
864
779
|
respText = new TextDecoder('utf-8').decode(buffer);
|
865
780
|
}
|
866
|
-
|
867
781
|
try {
|
868
782
|
this.responseText = JSON.stringify(JSON.parse(respText), null, 8);
|
869
783
|
} catch (_) {
|
@@ -884,7 +798,6 @@ class ApiRequest extends _lit.LitElement {
|
|
884
798
|
this.responseBlobType = 'view';
|
885
799
|
} else {
|
886
800
|
respText = await fetchResponse.text();
|
887
|
-
|
888
801
|
if (contentType.includes('xml')) {
|
889
802
|
this.responseText = (0, _xmlButPrettier.default)(respText, {
|
890
803
|
textNodesOnSameLine: true,
|
@@ -894,10 +807,8 @@ class ApiRequest extends _lit.LitElement {
|
|
894
807
|
this.responseText = respText;
|
895
808
|
}
|
896
809
|
}
|
897
|
-
|
898
810
|
if (this.responseIsBlob) {
|
899
811
|
var _filename$;
|
900
|
-
|
901
812
|
const contentDisposition = fetchResponse.headers.get('content-disposition');
|
902
813
|
const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
|
903
814
|
const filename = filenameRegex.exec(contentDisposition);
|
@@ -909,7 +820,6 @@ class ApiRequest extends _lit.LitElement {
|
|
909
820
|
respText = await fetchResponse.text();
|
910
821
|
this.responseText = respText;
|
911
822
|
}
|
912
|
-
|
913
823
|
const responseEvent = {
|
914
824
|
bubbles: true,
|
915
825
|
composed: true,
|
@@ -941,46 +851,45 @@ class ApiRequest extends _lit.LitElement {
|
|
941
851
|
document.dispatchEvent(new CustomEvent('after-try', responseEvent));
|
942
852
|
document.dispatchEvent(new CustomEvent('response', responseEvent));
|
943
853
|
}
|
944
|
-
|
945
854
|
this.requestUpdate();
|
946
855
|
}
|
947
|
-
|
948
856
|
onAddRemoveFileInput(e, pname) {
|
949
857
|
if (e.target.tagName.toLowerCase() !== 'button') {
|
950
858
|
return;
|
951
859
|
}
|
952
|
-
|
953
860
|
if (e.target.classList.contains('file-input-remove-btn')) {
|
954
861
|
// Remove File Input Set
|
955
862
|
const el = e.target.closest('.input-set');
|
956
863
|
el.remove();
|
957
864
|
return;
|
958
865
|
}
|
866
|
+
const el = e.target.closest('.file-input-container');
|
959
867
|
|
960
|
-
|
961
|
-
// Container
|
868
|
+
// Add File Input Set
|
962
869
|
|
870
|
+
// Container
|
963
871
|
const newInputContainerEl = document.createElement('div');
|
964
|
-
newInputContainerEl.setAttribute('class', 'input-set row');
|
872
|
+
newInputContainerEl.setAttribute('class', 'input-set row');
|
965
873
|
|
874
|
+
// File Input
|
966
875
|
const newInputEl = document.createElement('input');
|
967
876
|
newInputEl.type = 'file';
|
968
877
|
newInputEl.setAttribute('class', 'file-input');
|
969
878
|
newInputEl.setAttribute('data-pname', pname);
|
970
879
|
newInputEl.setAttribute('data-ptype', 'form-input');
|
971
880
|
newInputEl.setAttribute('data-array', 'false');
|
972
|
-
newInputEl.setAttribute('data-file-array', 'true');
|
881
|
+
newInputEl.setAttribute('data-file-array', 'true');
|
973
882
|
|
883
|
+
// Remover Button
|
974
884
|
const newRemoveBtnEl = document.createElement('button');
|
975
885
|
newRemoveBtnEl.setAttribute('class', 'file-input-remove-btn');
|
976
886
|
newRemoveBtnEl.innerHTML = '✕';
|
977
887
|
newInputContainerEl.appendChild(newInputEl);
|
978
888
|
newInputContainerEl.appendChild(newRemoveBtnEl);
|
979
|
-
el.insertBefore(newInputContainerEl, e.target);
|
980
|
-
|
889
|
+
el.insertBefore(newInputContainerEl, e.target);
|
890
|
+
// el.appendChild(newInputContainerEl);
|
981
891
|
this.computeCurlSyntax();
|
982
892
|
}
|
983
|
-
|
984
893
|
downloadResponseBlob() {
|
985
894
|
if (this.responseBlobUrl) {
|
986
895
|
const a = document.createElement('a');
|
@@ -992,7 +901,6 @@ class ApiRequest extends _lit.LitElement {
|
|
992
901
|
a.remove();
|
993
902
|
}
|
994
903
|
}
|
995
|
-
|
996
904
|
viewResponseBlob() {
|
997
905
|
if (this.responseBlobUrl) {
|
998
906
|
const a = document.createElement('a');
|
@@ -1004,7 +912,6 @@ class ApiRequest extends _lit.LitElement {
|
|
1004
912
|
a.remove();
|
1005
913
|
}
|
1006
914
|
}
|
1007
|
-
|
1008
915
|
clearResponseData() {
|
1009
916
|
this.responseUrl = '';
|
1010
917
|
this.responseHeaders = '';
|
@@ -1015,35 +922,29 @@ class ApiRequest extends _lit.LitElement {
|
|
1015
922
|
this.responseIsBlob = false;
|
1016
923
|
this.responseBlobType = '';
|
1017
924
|
this.respContentDisposition = '';
|
1018
|
-
|
1019
925
|
if (this.responseBlobUrl) {
|
1020
926
|
URL.revokeObjectURL(this.responseBlobUrl);
|
1021
927
|
this.responseBlobUrl = '';
|
1022
928
|
}
|
1023
929
|
}
|
1024
|
-
|
1025
930
|
requestParamFunction(event) {
|
1026
931
|
if (event.key === 'Enter') {
|
1027
932
|
this.onTryClick();
|
1028
933
|
event.preventDefault();
|
1029
934
|
}
|
1030
935
|
}
|
1031
|
-
|
1032
936
|
disconnectedCallback() {
|
1033
937
|
// Cleanup ObjectURL forthe blob data if this component created one
|
1034
938
|
if (this.responseBlobUrl) {
|
1035
939
|
URL.revokeObjectURL(this.responseBlobUrl);
|
1036
940
|
this.responseBlobUrl = '';
|
1037
941
|
}
|
1038
|
-
|
1039
942
|
super.disconnectedCallback();
|
1040
943
|
}
|
944
|
+
}
|
1041
945
|
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
946
|
+
// Register the element with the browser
|
1045
947
|
exports.default = ApiRequest;
|
1046
|
-
|
1047
948
|
if (!customElements.get('openapi-explorer')) {
|
1048
949
|
customElements.define('api-request', ApiRequest);
|
1049
950
|
}
|