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.
Files changed (80) hide show
  1. package/dist/browser/openapi-explorer.min.js +2 -2
  2. package/dist/es/components/api-request.js +58 -140
  3. package/dist/es/components/api-response.js +9 -34
  4. package/dist/es/components/json-tree.js +4 -18
  5. package/dist/es/components/request-form-table.js +13 -36
  6. package/dist/es/components/schema-table.js +28 -42
  7. package/dist/es/components/schema-tree.js +31 -61
  8. package/dist/es/components/syntax-highlighter.js +7 -26
  9. package/dist/es/components/tag-input.js +2 -14
  10. package/dist/es/openapi-explorer-oauth-handler.js +0 -2
  11. package/dist/es/openapi-explorer.js +62 -174
  12. package/dist/es/react.js +4 -4
  13. package/dist/es/styles/input-styles.js +1 -1
  14. package/dist/es/styles/schema-styles.js +1 -1
  15. package/dist/es/templates/advance-search-template.js +1 -5
  16. package/dist/es/templates/callback-template.js +2 -2
  17. package/dist/es/templates/code-samples-template.js +1 -3
  18. package/dist/es/templates/components-template.js +41 -4
  19. package/dist/es/templates/endpoint-template.js +6 -17
  20. package/dist/es/templates/expanded-endpoint-template.js +4 -7
  21. package/dist/es/templates/focused-endpoint-template.js +0 -10
  22. package/dist/es/templates/mainBodyTemplate.js +3 -2
  23. package/dist/es/templates/navbar-template.js +9 -12
  24. package/dist/es/templates/overview-template.js +1 -1
  25. package/dist/es/templates/security-scheme-template.js +12 -73
  26. package/dist/es/templates/server-template.js +1 -8
  27. package/dist/es/utils/color-utils.js +2 -21
  28. package/dist/es/utils/common-utils.js +3 -20
  29. package/dist/es/utils/schema-utils.js +35 -132
  30. package/dist/es/utils/spec-parser.js +35 -120
  31. package/dist/es/utils/theme.js +3 -6
  32. package/dist/es/utils/xml/xml.js +1 -40
  33. package/dist/lib/components/api-request.js +58 -157
  34. package/dist/lib/components/api-response.js +9 -54
  35. package/dist/lib/components/json-tree.js +4 -27
  36. package/dist/lib/components/request-form-table.js +14 -42
  37. package/dist/lib/components/schema-table.js +28 -52
  38. package/dist/lib/components/schema-tree.js +31 -72
  39. package/dist/lib/components/syntax-highlighter.js +6 -49
  40. package/dist/lib/components/tag-input.js +2 -18
  41. package/dist/lib/languages/en.js +2 -3
  42. package/dist/lib/languages/fr.js +2 -3
  43. package/dist/lib/languages/index.js +0 -6
  44. package/dist/lib/openapi-explorer-oauth-handler.js +0 -6
  45. package/dist/lib/openapi-explorer.js +61 -197
  46. package/dist/lib/react.js +4 -5
  47. package/dist/lib/styles/advanced-search-styles.js +1 -5
  48. package/dist/lib/styles/api-request-styles.js +1 -5
  49. package/dist/lib/styles/border-styles.js +1 -5
  50. package/dist/lib/styles/endpoint-styles.js +1 -5
  51. package/dist/lib/styles/flex-styles.js +1 -5
  52. package/dist/lib/styles/font-styles.js +1 -5
  53. package/dist/lib/styles/info-styles.js +1 -5
  54. package/dist/lib/styles/input-styles.js +1 -5
  55. package/dist/lib/styles/key-frame-styles.js +1 -5
  56. package/dist/lib/styles/nav-styles.js +1 -5
  57. package/dist/lib/styles/prism-styles.js +1 -5
  58. package/dist/lib/styles/schema-styles.js +1 -5
  59. package/dist/lib/styles/tab-styles.js +1 -5
  60. package/dist/lib/styles/table-styles.js +1 -5
  61. package/dist/lib/styles/tag-input-styles.js +1 -5
  62. package/dist/lib/templates/advance-search-template.js +0 -6
  63. package/dist/lib/templates/callback-template.js +1 -3
  64. package/dist/lib/templates/code-samples-template.js +0 -4
  65. package/dist/lib/templates/components-template.js +43 -9
  66. package/dist/lib/templates/endpoint-template.js +6 -29
  67. package/dist/lib/templates/expanded-endpoint-template.js +3 -17
  68. package/dist/lib/templates/focused-endpoint-template.js +0 -19
  69. package/dist/lib/templates/mainBodyTemplate.js +2 -13
  70. package/dist/lib/templates/navbar-template.js +9 -20
  71. package/dist/lib/templates/overview-template.js +0 -5
  72. package/dist/lib/templates/security-scheme-template.js +12 -79
  73. package/dist/lib/templates/server-template.js +1 -12
  74. package/dist/lib/utils/color-utils.js +4 -25
  75. package/dist/lib/utils/common-utils.js +3 -33
  76. package/dist/lib/utils/schema-utils.js +33 -141
  77. package/dist/lib/utils/spec-parser.js +35 -128
  78. package/dist/lib/utils/theme.js +3 -16
  79. package/dist/lib/utils/xml/xml.js +1 -42
  80. package/package.json +2 -2
@@ -1,5 +1,6 @@
1
- import { LitElement, css } from 'lit'; // Styles
1
+ import { LitElement, css } from 'lit';
2
2
 
3
+ // Styles
3
4
  import FontStyles from './styles/font-styles.js';
4
5
  import InputStyles from './styles/input-styles.js';
5
6
  import SchemaStyles from './styles/schema-styles.js';
@@ -31,7 +32,6 @@ export default class OpenApiExplorer extends LitElement {
31
32
  threshold: 0
32
33
  };
33
34
  this.isIntersectionObserverActive = true;
34
-
35
35
  if (typeof IntersectionObserver !== 'undefined') {
36
36
  this.intersectionObserver = new IntersectionObserver(entries => {
37
37
  this.onIntersect(entries);
@@ -39,13 +39,10 @@ export default class OpenApiExplorer extends LitElement {
39
39
  } else {
40
40
  this.intersectionObserver = {
41
41
  disconnect() {},
42
-
43
42
  observe() {}
44
-
45
43
  };
46
44
  }
47
45
  }
48
-
49
46
  static get properties() {
50
47
  return {
51
48
  // Heading
@@ -69,11 +66,9 @@ export default class OpenApiExplorer extends LitElement {
69
66
  collapsed: {
70
67
  type: Boolean,
71
68
  attribute: 'collapse',
72
-
73
69
  converter(value) {
74
70
  return value !== 'false' && value !== false;
75
71
  }
76
-
77
72
  },
78
73
  operationsCollapsed: {
79
74
  type: Boolean
@@ -92,21 +87,17 @@ export default class OpenApiExplorer extends LitElement {
92
87
  hideDefaults: {
93
88
  type: Boolean,
94
89
  attribute: 'hide-defaults',
95
-
96
90
  converter(value) {
97
91
  return value !== 'false' && value !== false;
98
92
  }
99
-
100
93
  },
101
94
  // Schema Styles
102
95
  displaySchemaAsTable: {
103
96
  type: Boolean,
104
97
  attribute: 'table',
105
-
106
98
  converter(value) {
107
99
  return value !== 'false' && value !== false;
108
100
  }
109
-
110
101
  },
111
102
  schemaExpandLevel: {
112
103
  type: Number,
@@ -121,65 +112,51 @@ export default class OpenApiExplorer extends LitElement {
121
112
  hideInfo: {
122
113
  type: Boolean,
123
114
  attribute: 'hide-info',
124
-
125
115
  converter(value) {
126
116
  return value !== 'false' && value !== false;
127
117
  }
128
-
129
118
  },
130
119
  hideAuthentication: {
131
120
  type: Boolean,
132
121
  attribute: 'hide-authentication',
133
-
134
122
  converter(value) {
135
123
  return value !== 'false' && value !== false;
136
124
  }
137
-
138
125
  },
139
126
  hideExecution: {
140
127
  type: Boolean,
141
128
  attribute: 'hide-console',
142
-
143
129
  converter(value) {
144
130
  return value !== 'false' && value !== false;
145
131
  }
146
-
147
132
  },
148
133
  includeNulls: {
149
134
  type: Boolean,
150
135
  attribute: 'display-nulls',
151
-
152
136
  converter(value) {
153
137
  return value !== 'false' && value !== false;
154
138
  }
155
-
156
139
  },
157
140
  hideSearch: {
158
141
  type: Boolean,
159
142
  attribute: 'hide-search',
160
-
161
143
  converter(value) {
162
144
  return value !== 'false' && value !== false;
163
145
  }
164
-
165
146
  },
166
147
  hideServerSelection: {
167
148
  type: Boolean,
168
149
  attribute: 'hide-server-selection',
169
-
170
150
  converter(value) {
171
151
  return value !== 'false' && value !== false;
172
152
  }
173
-
174
153
  },
175
154
  hideComponents: {
176
155
  type: Boolean,
177
156
  attribute: 'hide-components',
178
-
179
157
  converter(value) {
180
158
  return value !== 'false' && value !== false;
181
159
  }
182
-
183
160
  },
184
161
  // Main Colors and Font
185
162
  primaryColor: {
@@ -230,11 +207,9 @@ export default class OpenApiExplorer extends LitElement {
230
207
  usePathInNavBar: {
231
208
  type: Boolean,
232
209
  attribute: 'use-path-in-nav-bar',
233
-
234
210
  converter(value) {
235
211
  return value !== 'false' && value !== false;
236
212
  }
237
-
238
213
  },
239
214
  // Fetch Options
240
215
  fetchCredentials: {
@@ -259,96 +234,78 @@ export default class OpenApiExplorer extends LitElement {
259
234
  }
260
235
  };
261
236
  }
262
-
263
237
  static finalizeStyles() {
264
- return [FontStyles, SchemaStyles, InputStyles, FlexStyles, TableStyles, KeyFrameStyles, EndpointStyles, PrismStyles, TabStyles, NavStyles, InfoStyles, TagInputStyles, advancedSearchStyles, apiRequestStyles, css`:not(:defined){display:none}:host{display:flex;flex-direction:column;width:100%;height:100%;margin:0;padding:0;overflow:hidden;letter-spacing:normal;color:var(--fg);background-color:var(--bg);font-family:var(--font-regular)}.body{display:flex;height:100%;width:100%;overflow:hidden}a{text-decoration:none}.main-content{margin:0;padding:0;display:block;flex:1;height:100%;overflow-y:overlay;overflow-x:hidden;scrollbar-width:thin;scrollbar-color:var(--border-color) transparent}.main-content::-webkit-scrollbar{width:8px;height:8px}.main-content::-webkit-scrollbar-track{background:0 0}.main-content::-webkit-scrollbar-thumb{background-color:var(--border-color)}.section-gap.section-tag{border-bottom:1px solid var(--border-color)}.method-section-gap{margin:0;padding:0 8px 0 4px;border-bottom:1px solid var(--border-color)}.section-gap{padding:24px 0 0}.section-tag-header{position:relative;cursor:n-resize;padding:12px 0}.collapsed .section-tag-header:hover{cursor:s-resize}.section-tag-header:hover{background-image:linear-gradient(to right,rgba(0,0,0,0),var(--border-color),rgba(0,0,0,0))}.collapsed .section-tag-header:hover::after{color:var(--primary-color)}.collapsed .section-tag-body{display:none}.logo{height:36px;width:36px;margin-left:5px}.only-large-screen,.only-large-screen-flex{display:none}.header-title{font-size:calc(var(--font-size-regular) + 8px);padding:0 8px}.tag.title{text-transform:uppercase}.header{background-color:var(--header-bg);color:var(--header-fg);width:100%}input.header-input{background:var(--header-color-darker);color:var(--header-fg);border:1px solid var(--header-color-border);flex:1;padding-right:24px;border-radius:3px}input.header-input::placeholder{opacity:.4}input:disabled{cursor:not-allowed}.loader{margin:16px auto 16px auto;border:4px solid var(--bg3);border-radius:50%;border-top:4px solid var(--primary-color);width:36px;height:36px;animation:spin 2s linear infinite}.expanded-endpoint-body,.expanded-endpoint-component{position:relative;padding:6px 0}.expanded-endpoint-component>h2:hover{cursor:pointer;text-decoration:underline}.divider{border-top:2px solid var(--border-color);margin:24px 0;width:100%}.security-tooltip{border:1px solid var(--border-color);border-left-width:4px;margin-left:2px}.security-tooltip a{color:var(--fg2);text-decoration:none}.tooltip-text{color:var(--fg2);background-color:var(--bg2);visibility:hidden;overflow-wrap:break-word}.tooltip:hover{color:var(--primary-color);border-color:var(--primary-color)}.tooltip-replace:hover{visibility:hidden}.tooltip:hover a:hover{color:var(--primary-color)}.tooltip:hover .tooltip-text{visibility:visible;cursor:text;opacity:1}@media only screen and (max-width:767.98px){.section-padding{margin:1rem}.sub-title.tag{margin-left:1rem}.section-tag-body .description{margin-left:1rem;margin-right:1rem}}@media only screen and (min-width:768px){.nav-bar{width:260px;display:flex}.only-large-screen{display:block}.only-large-screen-flex{display:flex}.section-gap{padding:24px 24px}.section-gap--read-mode{padding:24px 8px}.section-gap--focused-mode{padding:1.5rem}.endpoint-body{position:relative;padding:36px 0 48px 0}}@media only screen and (min-width:1024px){.nav-bar{width:330px;display:flex}.section-gap--read-mode{padding:24px 24px 12px}.main-content-inner{padding:24px}}`];
265
- } // Startup
266
-
238
+ return [FontStyles, SchemaStyles, InputStyles, FlexStyles, TableStyles, KeyFrameStyles, EndpointStyles, PrismStyles, TabStyles, NavStyles, InfoStyles, TagInputStyles, advancedSearchStyles, apiRequestStyles, css`:not(:defined){display:none}:host{display:flex;flex-direction:column;width:100%;height:100%;margin:0;padding:0;overflow:hidden;letter-spacing:normal;color:var(--fg);background-color:var(--bg);font-family:var(--font-regular)}.body{display:flex;height:100%;width:100%;overflow:hidden}a{text-decoration:none}.main-content{margin:0;padding:0;display:block;flex:1;height:100%;overflow-y:overlay;overflow-x:hidden;scrollbar-width:thin;scrollbar-color:var(--border-color) transparent}.main-content::-webkit-scrollbar{width:8px;height:8px}.main-content::-webkit-scrollbar-track{background:0 0}.main-content::-webkit-scrollbar-thumb{background-color:var(--border-color)}.section-gap.section-tag{border-bottom:1px solid var(--border-color)}.method-section-gap{margin:0;padding:0 8px 0 4px;border-bottom:1px solid var(--border-color)}.section-gap{padding:24px 0 0}.section-tag-header{position:relative;cursor:n-resize;padding:12px 0}.collapsed .section-tag-header:hover{cursor:s-resize}.section-tag-header:hover{background-image:linear-gradient(to right,rgba(0,0,0,0),var(--border-color),rgba(0,0,0,0))}.collapsed .section-tag-header:hover::after{color:var(--primary-color)}.collapsed .section-tag-body{display:none}.logo{height:36px;width:36px;margin-left:5px}.only-large-screen,.only-large-screen-flex{display:none}.header-title{font-size:calc(var(--font-size-regular) + 8px);padding:0 8px}.tag.title{text-transform:uppercase}.header{background-color:var(--header-bg);color:var(--header-fg);width:100%}input.header-input{background:var(--header-color-darker);color:var(--header-fg);border:1px solid var(--header-color-border);flex:1;padding-right:24px;border-radius:3px}input.header-input::placeholder{opacity:.4}input:disabled{cursor:not-allowed}.loader{margin:16px auto 16px auto;border:4px solid var(--bg3);border-radius:50%;border-top:4px solid var(--primary-color);width:36px;height:36px;animation:spin 2s linear infinite}.expanded-endpoint-body,.expanded-endpoint-component{position:relative;padding:6px 0}.divider{border-top:2px solid var(--border-color);margin:24px 0;width:100%}.security-tooltip{border:1px solid var(--border-color);border-left-width:4px;margin-left:2px}.security-tooltip a{color:var(--fg2);text-decoration:none}.tooltip-text{color:var(--fg2);background-color:var(--bg2);visibility:hidden;overflow-wrap:break-word}.tooltip:hover{color:var(--primary-color);border-color:var(--primary-color)}.tooltip-replace:hover{visibility:hidden}.tooltip:hover a:hover{color:var(--primary-color)}.tooltip:hover .tooltip-text{visibility:visible;cursor:text;opacity:1}@media only screen and (max-width:767.98px){.section-padding{margin:1rem}.sub-title.tag{margin-left:1rem}.section-tag-body .description{margin-left:1rem;margin-right:1rem}}@media only screen and (min-width:768px){.nav-bar{width:260px;display:flex}.only-large-screen{display:block}.only-large-screen-flex{display:flex}.section-gap{padding:24px 24px}.section-gap--read-mode{padding:24px 8px}.section-gap--focused-mode{padding:1.5rem}.endpoint-body{position:relative;padding:36px 0 48px 0}}@media only screen and (min-width:1024px){.nav-bar{width:330px;display:flex}.section-gap--read-mode{padding:24px 24px 12px}.main-content-inner{padding:24px}}`];
239
+ }
267
240
 
241
+ // Startup
268
242
  connectedCallback() {
269
243
  super.connectedCallback();
270
244
  this.handleResize = this.handleResize.bind(this);
271
245
  window.addEventListener('resize', this.handleResize);
272
246
  this.loading = true;
273
247
  const parent = this.parentElement;
274
-
275
248
  if (parent) {
276
249
  if (parent.offsetWidth === 0 && parent.style.width === '') {
277
250
  parent.style.width = '100vw';
278
251
  }
279
-
280
252
  if (parent.offsetHeight === 0 && parent.style.height === '') {
281
253
  parent.style.height = '100vh';
282
254
  }
283
-
284
255
  if (parent.tagName === 'BODY') {
285
256
  if (!parent.style.marginTop) {
286
257
  parent.style.marginTop = '0';
287
258
  }
288
-
289
259
  if (!parent.style.marginRight) {
290
260
  parent.style.marginRight = '0';
291
261
  }
292
-
293
262
  if (!parent.style.marginBottom) {
294
263
  parent.style.marginBottom = '0';
295
264
  }
296
-
297
265
  if (!parent.style.marginLeft) {
298
266
  parent.style.marginLeft = '0';
299
267
  }
300
268
  }
301
269
  }
302
-
303
270
  this.renderStyle = 'focused';
304
271
  this.operationsCollapsed = this.collapsed;
305
272
  this.componentsCollapsed = this.collapsed;
306
273
  this.explorerLocation = this.explorerLocation || getCurrentElement();
307
-
308
274
  if (!this.defaultSchemaTab || !'body, model, form,'.includes(`${this.defaultSchemaTab},`)) {
309
275
  this.defaultSchemaTab = 'model';
310
276
  }
311
-
312
277
  if (!this.schemaExpandLevel || this.schemaExpandLevel < 1) {
313
278
  this.schemaExpandLevel = 99999;
314
279
  }
315
-
316
280
  this.schemaHideReadOnly = ['post', 'put', 'patch', 'query'].join(',');
317
281
  this.schemaHideWriteOnly = true;
318
-
319
282
  if (!this.responseAreaHeight) {
320
283
  this.responseAreaHeight = '300px';
321
284
  }
322
-
323
285
  if (!this.navItemSpacing || !'compact, relaxed, default,'.includes(`${this.navItemSpacing},`)) {
324
286
  this.navItemSpacing = 'default';
325
287
  }
326
-
327
288
  if (!this.fetchCredentials || !'omit, same-origin, include,'.includes(`${this.fetchCredentials},`)) {
328
289
  this.fetchCredentials = '';
329
290
  }
330
-
331
291
  if (!this.showAdvancedSearchDialog) {
332
292
  this.showAdvancedSearchDialog = false;
333
293
  }
334
-
335
294
  window.addEventListener('hashchange', () => {
336
295
  this.scrollTo(getCurrentElement());
337
296
  }, true);
338
297
  this.handleResize();
339
- } // Cleanup
340
-
298
+ }
341
299
 
300
+ // Cleanup
342
301
  disconnectedCallback() {
343
302
  this.intersectionObserver.disconnect();
344
303
  window.removeEventListener('resize', this.handleResize);
345
304
  super.disconnectedCallback();
346
305
  }
347
-
348
306
  render() {
349
307
  return mainBodyTemplate.call(this);
350
308
  }
351
-
352
309
  observeExpandedContent() {
353
310
  // Main Container
354
311
  const observeOverviewEls = this.shadowRoot.querySelectorAll('.observe-me');
@@ -356,39 +313,33 @@ export default class OpenApiExplorer extends LitElement {
356
313
  this.intersectionObserver.observe(targetEl);
357
314
  });
358
315
  }
359
-
360
316
  handleResize() {
361
317
  const mediaQueryResult = window.matchMedia('(min-width: 768px)');
362
318
  const newDisplay = mediaQueryResult.matches ? 'focused' : 'view';
363
-
364
319
  if (this.renderStyle !== newDisplay) {
365
320
  this.renderStyle = newDisplay;
366
321
  this.requestUpdate();
367
322
  }
368
323
  }
369
-
370
324
  attributeChangedCallback(name, oldVal, newVal) {
371
325
  if (name === 'spec-url') {
372
326
  if (oldVal !== newVal) {
373
327
  window.setTimeout(async () => {
374
- await this.loadSpec(newVal); // If the initial location is set, then attempt to scroll there
375
-
328
+ await this.loadSpec(newVal);
329
+ // If the initial location is set, then attempt to scroll there
376
330
  if (this.explorerLocation) {
377
331
  this.scrollTo(this.explorerLocation);
378
332
  }
379
333
  }, 0);
380
334
  }
381
335
  }
382
-
383
336
  if (name === 'server-url' && newVal) {
384
337
  var _this$resolvedSpec;
385
-
386
338
  this.selectedServer = ((_this$resolvedSpec = this.resolvedSpec) === null || _this$resolvedSpec === void 0 ? void 0 : _this$resolvedSpec.servers.find(s => s.url === newVal || !newVal)) || {
387
339
  url: newVal,
388
340
  computedUrl: newVal
389
341
  };
390
342
  }
391
-
392
343
  if (name === 'render-style') {
393
344
  if (newVal === 'read') {
394
345
  window.setTimeout(() => {
@@ -398,24 +349,19 @@ export default class OpenApiExplorer extends LitElement {
398
349
  this.intersectionObserver.disconnect();
399
350
  }
400
351
  }
401
-
402
352
  if (name === 'explorer-location') {
403
353
  window.setTimeout(() => {
404
354
  this.scrollTo(newVal);
405
355
  }, 0);
406
356
  }
407
-
408
357
  if (name === 'collapsed') {
409
358
  this.operationsCollapsed = newVal;
410
359
  this.componentsCollapsed = newVal;
411
360
  }
412
-
413
361
  super.attributeChangedCallback(name, oldVal, newVal);
414
362
  }
415
-
416
363
  onSearchChange(e) {
417
364
  var _this$matchPaths;
418
-
419
365
  this.matchPaths = e.target.value;
420
366
  const expand = !!((_this$matchPaths = this.matchPaths) !== null && _this$matchPaths !== void 0 && _this$matchPaths.trim());
421
367
  this.operationsCollapsed = !expand;
@@ -428,55 +374,43 @@ export default class OpenApiExplorer extends LitElement {
428
374
  });
429
375
  this.requestUpdate();
430
376
  }
431
-
432
377
  onClearSearch() {
433
378
  const searchEl = this.shadowRoot.getElementById('nav-bar-search');
434
379
  searchEl.value = '';
435
380
  this.matchPaths = '';
436
381
  }
437
-
438
382
  async onShowSearchModalClicked() {
439
- this.showAdvancedSearchDialog = true; // wait for the dialog to render
440
-
383
+ this.showAdvancedSearchDialog = true;
384
+ // wait for the dialog to render
441
385
  await sleep(10);
442
386
  const inputEl = this.shadowRoot.getElementById('advanced-search-dialog-input');
443
-
444
387
  if (inputEl) {
445
388
  inputEl.focus();
446
389
  }
447
- } // Public Method
448
-
390
+ }
449
391
 
392
+ // Public Method
450
393
  async loadSpec(specUrlOrObject) {
451
394
  if (!specUrlOrObject) {
452
395
  return;
453
396
  }
454
-
455
397
  this.matchPaths = '';
456
-
457
398
  try {
458
399
  var _spec$info;
459
-
460
400
  this.resolvedSpec = null;
461
401
  this.loading = true;
462
402
  this.loadFailed = false;
463
403
  const spec = await ProcessSpec(specUrlOrObject, this.serverUrl);
464
404
  this.loading = false;
465
-
466
405
  if (spec === undefined || spec === null) {
467
406
  console.error('Unable to resolve the API spec. '); // eslint-disable-line no-console
468
-
469
407
  return;
470
408
  }
471
-
472
409
  initI18n((_spec$info = spec.info) === null || _spec$info === void 0 ? void 0 : _spec$info['x-locale']);
473
-
474
410
  if (!this.serverUrl) {
475
411
  var _spec$servers$, _spec$servers$2;
476
-
477
412
  this.serverUrl = ((_spec$servers$ = spec.servers[0]) === null || _spec$servers$ === void 0 ? void 0 : _spec$servers$.computedUrl) || ((_spec$servers$2 = spec.servers[0]) === null || _spec$servers$2 === void 0 ? void 0 : _spec$servers$2.url);
478
413
  }
479
-
480
414
  this.selectedServer = spec.servers.find(s => s.url === this.serverUrl || !this.serverUrl) || spec.servers[0];
481
415
  this.afterSpecParsedAndValidated(spec);
482
416
  } catch (err) {
@@ -485,16 +419,15 @@ export default class OpenApiExplorer extends LitElement {
485
419
  this.resolvedSpec = null;
486
420
  console.error('OpenAPI Explorer: Unable to resolve the API spec..', err); // eslint-disable-line no-console
487
421
  }
488
-
489
422
  try {
490
423
  await checkForAuthToken.call(this);
491
424
  } catch (error) {
492
425
  // eslint-disable-next-line no-console
493
426
  console.error('Failed to check for authentication token', error);
494
427
  }
495
- } // Public Method
496
-
428
+ }
497
429
 
430
+ // Public Method
498
431
  async setAuthenticationConfiguration(apiKeyId, {
499
432
  token,
500
433
  clientId,
@@ -502,13 +435,10 @@ export default class OpenApiExplorer extends LitElement {
502
435
  redirectUri
503
436
  }) {
504
437
  const securityObj = this.resolvedSpec && this.resolvedSpec.securitySchemes.find(v => v.apiKeyId === apiKeyId);
505
-
506
438
  if (!securityObj) {
507
439
  throw Error('SecuritySchemeNotFound');
508
440
  }
509
-
510
441
  let authorizationToken = token && token.replace(/^(Bearer|Basic)\s+/i, '').trim();
511
-
512
442
  if (authorizationToken && securityObj.type && securityObj.type === 'http' && securityObj.scheme && securityObj.scheme.toLowerCase() === 'basic') {
513
443
  authorizationToken = `Basic ${btoa(authorizationToken)}`;
514
444
  } else if (authorizationToken && securityObj.scheme && securityObj.scheme.toLowerCase() === 'bearer') {
@@ -516,7 +446,6 @@ export default class OpenApiExplorer extends LitElement {
516
446
  } else {
517
447
  authorizationToken = null;
518
448
  }
519
-
520
449
  securityObj.clientId = clientId && clientId.trim();
521
450
  securityObj.clientSecret = clientSecret && clientSecret.trim();
522
451
  securityObj.redirectUri = new URL(redirectUri && redirectUri.trim() || '', window.location.href).toString();
@@ -524,56 +453,47 @@ export default class OpenApiExplorer extends LitElement {
524
453
  await checkForAuthToken.call(this);
525
454
  this.requestUpdate();
526
455
  }
527
-
528
456
  afterSpecParsedAndValidated(spec) {
529
457
  this.resolvedSpec = spec;
530
-
531
458
  if (this.operationsCollapsed) {
532
459
  this.resolvedSpec.tags.forEach(t => t.expanded = false);
533
460
  }
534
-
535
461
  if (this.componentsCollapsed) {
536
462
  this.resolvedSpec.components.forEach(c => c.expanded = false);
537
463
  }
538
-
539
464
  this.dispatchEvent(new CustomEvent('spec-loaded', {
540
465
  bubbles: true,
541
466
  detail: spec
542
467
  }));
543
- this.requestUpdate(); // Initiate IntersectionObserver and put it at the end of event loop, to allow loading all the child elements (must for larger specs)
468
+ this.requestUpdate();
544
469
 
470
+ // Initiate IntersectionObserver and put it at the end of event loop, to allow loading all the child elements (must for larger specs)
545
471
  this.intersectionObserver.disconnect();
546
-
547
472
  if (this.renderStyle === 'focused') {
548
473
  const defaultElementId = !this.hideInfo ? 'overview' : this.resolvedSpec.tags && this.resolvedSpec.tags[0] && this.resolvedSpec.tags[0].paths[0];
549
474
  this.scrollTo(this.explorerLocation || defaultElementId);
550
475
  }
551
-
552
476
  if (this.renderStyle === 'view' && this.explorerLocation) {
553
477
  this.expandAndGotoOperation(this.explorerLocation);
554
478
  }
555
479
  }
556
-
557
480
  expandAndGotoOperation(elementId) {
558
481
  var _tag$paths;
559
-
560
482
  // Expand full operation and tag
561
483
  let isExpandingNeeded = false;
562
484
  const tag = this.resolvedSpec.tags.find(t => t.paths && t.paths.find(p => p.elementId === elementId));
563
485
  const path = tag === null || tag === void 0 ? void 0 : (_tag$paths = tag.paths) === null || _tag$paths === void 0 ? void 0 : _tag$paths.find(p => p.elementId === elementId);
564
-
565
486
  if (path && (!path.expanded || !tag.expanded)) {
566
487
  isExpandingNeeded = true;
567
488
  path.expanded = true;
568
489
  tag.expanded = true;
569
490
  this.requestUpdate();
570
- } // requestUpdate() and delay required, else we cant find element because it won't exist immediately
571
-
491
+ }
572
492
 
493
+ // requestUpdate() and delay required, else we cant find element because it won't exist immediately
573
494
  const tmpElementId = elementId.indexOf('#') === -1 ? elementId : elementId.substring(1);
574
495
  window.setTimeout(() => {
575
496
  const gotoEl = this.shadowRoot.getElementById(tmpElementId);
576
-
577
497
  if (gotoEl) {
578
498
  gotoEl.scrollIntoView({
579
499
  behavior: 'auto',
@@ -583,41 +503,34 @@ export default class OpenApiExplorer extends LitElement {
583
503
  }
584
504
  }, isExpandingNeeded ? 150 : 0);
585
505
  }
586
-
587
506
  isValidTopId(id) {
588
507
  return id.startsWith('overview') || id === 'servers' || id === 'auth';
589
508
  }
590
-
591
509
  isValidPathId(id) {
592
510
  if (id === 'overview' && !this.hideInfo) {
593
511
  return true;
594
512
  }
595
-
596
513
  if (id === 'servers' && !this.hideServerSelection) {
597
514
  return true;
598
515
  }
599
-
600
516
  if (id === 'auth' && !this.hideAuthentication) {
601
517
  return true;
602
518
  }
603
-
604
519
  if (id.startsWith('tag--')) {
605
520
  return this.resolvedSpec.tags && this.resolvedSpec.tags.find(tag => tag.elementId === id);
606
521
  }
607
-
608
522
  return this.resolvedSpec.tags && this.resolvedSpec.tags.find(tag => tag.paths.find(path => path.elementId === id));
609
523
  }
610
-
611
524
  onIntersect(entries) {
612
525
  if (this.isIntersectionObserverActive === false) {
613
526
  return;
614
527
  }
615
-
616
528
  entries.forEach(entry => {
617
529
  if (entry.isIntersecting && entry.intersectionRatio > 0) {
618
530
  const oldNavEl = this.shadowRoot.querySelector('.nav-bar-tag.active, .nav-bar-path.active, .nav-bar-info.active, .nav-bar-h1.active, .nav-bar-h2.active');
619
- const newNavEl = this.shadowRoot.getElementById(`link-${entry.target.id}`); // Add active class in the new element
531
+ const newNavEl = this.shadowRoot.getElementById(`link-${entry.target.id}`);
620
532
 
533
+ // Add active class in the new element
621
534
  if (newNavEl) {
622
535
  replaceState(entry.target.id);
623
536
  newNavEl.scrollIntoView({
@@ -625,24 +538,21 @@ export default class OpenApiExplorer extends LitElement {
625
538
  block: 'center'
626
539
  });
627
540
  newNavEl.classList.add('active');
628
- } // Remove active class from previous element
629
-
630
-
541
+ }
542
+ // Remove active class from previous element
631
543
  if (oldNavEl) {
632
544
  oldNavEl.classList.remove('active');
633
545
  }
634
546
  }
635
547
  });
636
- } // Called by anchor tags created using markdown
637
-
548
+ }
638
549
 
550
+ // Called by anchor tags created using markdown
639
551
  handleHref(e) {
640
552
  if (e.target.tagName.toLowerCase() === 'a') {
641
553
  const anchor = e.target.getAttribute('href');
642
-
643
554
  if (anchor && anchor.startsWith('#')) {
644
555
  const gotoEl = this.shadowRoot.getElementById(anchor.replace('#', ''));
645
-
646
556
  if (gotoEl) {
647
557
  gotoEl.scrollIntoView({
648
558
  behavior: 'auto',
@@ -652,6 +562,7 @@ export default class OpenApiExplorer extends LitElement {
652
562
  }
653
563
  }
654
564
  }
565
+
655
566
  /**
656
567
  * Called by
657
568
  * - onClick of Navigation Bar
@@ -663,106 +574,96 @@ export default class OpenApiExplorer extends LitElement {
663
574
  * 3. Activate IntersectionObserver (after little delay)
664
575
  *
665
576
  */
666
-
667
-
668
577
  scrollToEventTarget(event, scrollNavItemToView = true) {
669
578
  const navEl = event.currentTarget;
670
-
671
579
  if (!navEl.dataset.contentId) {
672
580
  return;
673
581
  }
674
-
675
582
  this.isIntersectionObserverActive = false;
676
583
  this.scrollTo(navEl.dataset.contentId, scrollNavItemToView);
677
584
  setTimeout(() => {
678
585
  this.isIntersectionObserverActive = true;
679
586
  }, 300);
680
587
  }
681
-
682
588
  scrollToCustomNavSectionTarget(event, scrollNavItemToView = true) {
683
589
  const navEl = event.currentTarget;
684
-
685
590
  if (!navEl.dataset.contentId) {
686
591
  return;
687
592
  }
688
-
689
593
  const navSectionSlot = this.shadowRoot.querySelector('slot.custom-nav-section');
690
- const assignedNodes = navSectionSlot === null || navSectionSlot === void 0 ? void 0 : navSectionSlot.assignedNodes(); // clicked child node could be multiple levels deep in a custom nav
594
+ const assignedNodes = navSectionSlot === null || navSectionSlot === void 0 ? void 0 : navSectionSlot.assignedNodes();
691
595
 
596
+ // clicked child node could be multiple levels deep in a custom nav
692
597
  const hasChildNode = node => {
693
598
  return node === event.target || node.children && [...node.children].some(c => hasChildNode(c));
694
599
  };
695
-
696
600
  let repeatedElementIndex = assignedNodes && [].findIndex.call(assignedNodes, slot => hasChildNode(slot));
697
-
698
601
  if (repeatedElementIndex === -1 && navEl.dataset.contentId.match(/^section--\d+/)) {
699
602
  repeatedElementIndex = Number(navEl.dataset.contentId.split('--')[1]) - 1;
700
603
  }
701
-
702
604
  this.isIntersectionObserverActive = false;
703
605
  this.scrollTo(navEl.dataset.contentId, scrollNavItemToView, repeatedElementIndex);
704
606
  setTimeout(() => {
705
607
  this.isIntersectionObserverActive = true;
706
608
  }, 300);
707
- } // Public Method (scrolls to a given path and highlights the left-nav selection)
708
-
609
+ }
610
+ async scrollToSchemaComponentByName(schemaComponentNameEvent) {
611
+ var _this$resolvedSpec2, _this$resolvedSpec2$c, _this$resolvedSpec2$c2, _this$resolvedSpec2$c3;
612
+ const schemaComponentName = schemaComponentNameEvent.detail;
613
+ const schemaComponent = (_this$resolvedSpec2 = this.resolvedSpec) === null || _this$resolvedSpec2 === void 0 ? void 0 : (_this$resolvedSpec2$c = _this$resolvedSpec2.components) === null || _this$resolvedSpec2$c === void 0 ? void 0 : (_this$resolvedSpec2$c2 = _this$resolvedSpec2$c.find(c => c.componentKeyId === 'schemas')) === null || _this$resolvedSpec2$c2 === void 0 ? void 0 : (_this$resolvedSpec2$c3 = _this$resolvedSpec2$c2.subComponents) === null || _this$resolvedSpec2$c3 === void 0 ? void 0 : _this$resolvedSpec2$c3.find(s => s.name === schemaComponentName);
614
+ if (schemaComponent) {
615
+ await this.scrollTo(`cmp--${schemaComponent.id}`, true);
616
+ }
617
+ }
709
618
 
619
+ // Public Method (scrolls to a given path and highlights the left-nav selection)
710
620
  async scrollTo(elementId, scrollNavItemToView = true, repeatedElementIndex) {
711
621
  try {
712
622
  await this.scrollToOrThrowException(elementId, scrollNavItemToView, repeatedElementIndex);
713
623
  } catch (error) {
714
624
  // There's an issue for lit elements for some browsers which are causing this issue we'll log here and still throw
715
625
  console.error('Failed to scroll to target', elementId, scrollNavItemToView, repeatedElementIndex, error); // eslint-disable-line no-console
716
-
717
626
  throw error;
718
627
  }
719
628
  }
720
-
721
629
  async scrollToOrThrowException(elementId, scrollNavItemToView = true, forcedRepeatedElementIndex) {
722
630
  if (!this.resolvedSpec) {
723
631
  return;
724
632
  }
725
-
726
633
  this.emitOperationChangedEvent(elementId);
727
-
728
634
  if (this.renderStyle === 'view') {
729
635
  this.expandAndGotoOperation(elementId);
730
636
  return;
731
- } // explorerLocation will get validated in the focused-endpoint-template
732
-
637
+ }
733
638
 
639
+ // explorerLocation will get validated in the focused-endpoint-template
734
640
  this.explorerLocation = elementId;
735
641
  const tag = this.resolvedSpec.tags.find(t => t.paths.some(p => p.elementId === elementId));
736
-
737
642
  if (tag) {
738
643
  tag.expanded = true;
739
- } // Convert to Async and to the background, so that we can be sure that the operation has been expanded and put into view before trying to directly scroll to it (or it won't be found in the next line and even if it is, it might not be able to be scrolled into view)
740
-
741
-
742
- await sleep(0); // In the case of section scrolling, these are hard swaps, so just load "section". In the case of `tags` the headers have the element html Id in the last `--id`, so split that off and check for it
644
+ }
645
+ // Convert to Async and to the background, so that we can be sure that the operation has been expanded and put into view before trying to directly scroll to it (or it won't be found in the next line and even if it is, it might not be able to be scrolled into view)
646
+ await sleep(0);
743
647
 
648
+ // In the case of section scrolling, these are hard swaps, so just load "section". In the case of `tags` the headers have the element html Id in the last `--id`, so split that off and check for it
744
649
  const contentEl = this.shadowRoot.getElementById(elementId !== null && elementId !== void 0 && elementId.startsWith('section') ? 'section' : elementId) || this.shadowRoot.getElementById(elementId.split('--').slice(-1)[0]);
745
-
746
650
  if (!contentEl) {
747
651
  return;
748
- } // For focused APIs, always scroll to the top of the component
749
-
652
+ }
750
653
 
654
+ // For focused APIs, always scroll to the top of the component
751
655
  let newNavEl;
752
656
  let waitForComponentToExpand = false;
753
657
  const elementIndex = forcedRepeatedElementIndex || forcedRepeatedElementIndex === 0 ? forcedRepeatedElementIndex : Number(elementId.split('--')[1]) - 1;
754
-
755
658
  if (elementId.match(/^section/)) {
756
659
  const customSections = this.shadowRoot.querySelector('slot.custom-section');
757
660
  const assignedNodesToCustomSections = customSections === null || customSections === void 0 ? void 0 : customSections.assignedNodes();
758
-
759
661
  if (assignedNodesToCustomSections) {
760
662
  try {
761
663
  assignedNodesToCustomSections.map(customSection => {
762
664
  customSection.classList.remove('active');
763
665
  });
764
666
  const newActiveCustomSection = assignedNodesToCustomSections[elementIndex];
765
-
766
667
  if (newActiveCustomSection && !newActiveCustomSection.classList.contains('active')) {
767
668
  newActiveCustomSection.classList.add('active');
768
669
  }
@@ -771,69 +672,66 @@ export default class OpenApiExplorer extends LitElement {
771
672
  console.error('Failed to switch between custom sections, usually happens because the DOM is not ready and has not loaded these sections yet.', error);
772
673
  }
773
674
  }
774
-
775
675
  const navSectionSlot = this.shadowRoot.querySelector('slot.custom-nav-section');
776
676
  const assignedNodes = navSectionSlot === null || navSectionSlot === void 0 ? void 0 : navSectionSlot.assignedNodes();
777
- newNavEl = assignedNodes === null || assignedNodes === void 0 ? void 0 : assignedNodes[elementIndex]; // Update Location Hash
677
+ newNavEl = assignedNodes === null || assignedNodes === void 0 ? void 0 : assignedNodes[elementIndex];
778
678
 
679
+ // Update Location Hash
779
680
  replaceState(`section--${elementIndex + 1}`);
780
681
  } else if (elementId.match('cmp--')) {
781
682
  const component = this.resolvedSpec.components.find(c => c.subComponents.find(sub => elementId.includes(sub.id)));
782
-
783
683
  if (component && !component.expanded) {
784
684
  waitForComponentToExpand = true;
785
685
  component.expanded = true;
786
686
  }
787
-
788
687
  contentEl.scrollIntoView({
789
688
  behavior: 'auto',
790
689
  block: 'start'
791
- }); // Update Location Hash
690
+ });
792
691
 
692
+ // Update Location Hash
793
693
  replaceState(elementId);
794
694
  newNavEl = this.shadowRoot.getElementById(`link-${elementId}`);
795
695
  } else if (!elementId.match('cmp--') && !elementId.match('tag--')) {
796
696
  this.shadowRoot.getElementById('operations-root').scrollIntoView({
797
697
  behavior: 'auto',
798
698
  block: 'start'
799
- }); // Update Location Hash
699
+ });
800
700
 
701
+ // Update Location Hash
801
702
  replaceState(elementId);
802
703
  newNavEl = this.shadowRoot.getElementById(`link-${elementId}`);
803
704
  } else {
804
705
  contentEl.scrollIntoView({
805
706
  behavior: 'auto',
806
707
  block: 'start'
807
- }); // Update Location Hash
708
+ });
808
709
 
710
+ // Update Location Hash
809
711
  replaceState(elementId);
810
712
  newNavEl = this.shadowRoot.getElementById(`link-${elementId}`);
811
- } // for focused style it is important to reset request-body-selection and response selection which maintains the state for in case of multiple req-body or multiple response mime-type
812
-
713
+ }
813
714
 
715
+ // for focused style it is important to reset request-body-selection and response selection which maintains the state for in case of multiple req-body or multiple response mime-type
814
716
  const requestEl = this.shadowRoot.querySelector('api-request');
815
-
816
717
  if (requestEl) {
817
718
  requestEl.resetRequestBodySelection();
818
719
  }
819
-
820
720
  const responseEl = this.shadowRoot.querySelector('api-response');
821
-
822
721
  if (responseEl) {
823
722
  responseEl.resetSelection();
824
- } // Update NavBar View and Styles
825
-
723
+ }
826
724
 
725
+ // Update NavBar View and Styles
827
726
  if (!newNavEl) {
828
727
  return;
829
728
  }
830
-
831
729
  if (scrollNavItemToView) {
832
730
  newNavEl.scrollIntoView({
833
731
  behavior: 'auto',
834
732
  block: 'center'
835
- }); // Also force it into view again if for some reason it isn't there
836
-
733
+ });
734
+ // Also force it into view again if for some reason it isn't there
837
735
  if (waitForComponentToExpand) {
838
736
  setTimeout(() => newNavEl.scrollIntoView({
839
737
  behavior: 'auto',
@@ -841,42 +739,35 @@ export default class OpenApiExplorer extends LitElement {
841
739
  }), 600);
842
740
  }
843
741
  }
844
-
845
742
  await sleep(0);
846
743
  const oldNavEl = this.shadowRoot.querySelector('.nav-bar-tag.active, .nav-bar-path.active, .nav-bar-info.active, .nav-bar-h1.active, .nav-bar-h2.active');
847
-
848
744
  if (oldNavEl) {
849
745
  oldNavEl.classList.remove('active');
850
746
  }
851
-
852
747
  const navSectionSlot = this.shadowRoot.querySelector('slot.custom-nav-section');
853
748
  const assignedNodes = navSectionSlot === null || navSectionSlot === void 0 ? void 0 : navSectionSlot.assignedNodes();
854
749
  (assignedNodes || []).filter((n, nodeIndex) => isNaN(elementIndex) || nodeIndex !== elementIndex).forEach(node => {
855
750
  node.classList.remove('active');
856
751
  });
857
752
  newNavEl.classList.add('active'); // must add the class after scrolling
858
-
859
753
  this.requestUpdate();
860
- } // Event handler for Advanced Search text-inputs and checkboxes
861
-
754
+ }
862
755
 
756
+ // Event handler for Advanced Search text-inputs and checkboxes
863
757
  onAdvancedSearch(ev) {
864
758
  const eventTargetEl = ev.target;
865
759
  clearTimeout(this.timeoutId);
866
760
  this.timeoutId = setTimeout(() => {
867
761
  let searchInputEl;
868
-
869
762
  if (eventTargetEl.type === 'text') {
870
763
  searchInputEl = eventTargetEl;
871
764
  } else {
872
765
  searchInputEl = eventTargetEl.closest('.advanced-search-options').querySelector('input[type=text]');
873
766
  }
874
-
875
767
  const searchOptions = [...eventTargetEl.closest('.advanced-search-options').querySelectorAll('input:checked')].map(v => v.id);
876
768
  this.advancedSearchMatches = advancedSearch(searchInputEl.value, this.resolvedSpec.tags, searchOptions);
877
769
  }, 0);
878
770
  }
879
-
880
771
  emitOperationChangedEvent(elementId) {
881
772
  const operation = this.resolvedSpec.tags.map(t => t.paths).flat(1).find(p => p.elementId === elementId);
882
773
  const event = {
@@ -890,11 +781,8 @@ export default class OpenApiExplorer extends LitElement {
890
781
  };
891
782
  this.dispatchEvent(new CustomEvent('event', event));
892
783
  }
893
-
894
784
  }
895
-
896
785
  if (!customElements.get('openapi-explorer')) {
897
786
  customElements.define('openapi-explorer', OpenApiExplorer);
898
787
  }
899
-
900
788
  import './openapi-explorer-oauth-handler.js';