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