openapi-explorer 0.9.310 → 0.9.314

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 (121) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/dist/{openapi-explorer.min.js → browser/openapi-explorer.min.js} +3 -3
  3. package/dist/{openapi-explorer.min.js.map → browser/openapi-explorer.min.js.map} +0 -0
  4. package/dist/es/components/api-request.js +936 -0
  5. package/dist/es/components/api-response.js +184 -0
  6. package/dist/es/components/json-tree.js +67 -0
  7. package/{src → dist/es}/components/mime-types.js +11 -17
  8. package/dist/es/components/schema-table.js +156 -0
  9. package/dist/es/components/schema-tree.js +191 -0
  10. package/dist/es/components/tag-input.js +67 -0
  11. package/{src → dist/es}/openapi-explorer-oauth-handler.js +2 -2
  12. package/{src → dist/es}/openapi-explorer.js +364 -371
  13. package/dist/es/styles/advanced-search-styles.js +2 -0
  14. package/dist/es/styles/api-request-styles.js +2 -0
  15. package/dist/es/styles/border-styles.js +2 -0
  16. package/dist/es/styles/endpoint-styles.js +2 -0
  17. package/dist/es/styles/flex-styles.js +2 -0
  18. package/dist/es/styles/font-styles.js +2 -0
  19. package/dist/es/styles/info-styles.js +2 -0
  20. package/dist/es/styles/input-styles.js +4 -0
  21. package/dist/es/styles/nav-styles.js +2 -0
  22. package/dist/es/styles/prism-styles.js +2 -0
  23. package/dist/es/styles/schema-styles.js +2 -0
  24. package/dist/es/styles/tab-styles.js +2 -0
  25. package/dist/es/styles/table-styles.js +2 -0
  26. package/dist/es/templates/advance-search-template.js +37 -0
  27. package/dist/es/templates/callback-template.js +7 -0
  28. package/dist/es/templates/code-samples-template.js +26 -0
  29. package/dist/es/templates/components-template.js +17 -0
  30. package/dist/es/templates/endpoint-template.js +94 -0
  31. package/dist/es/templates/expanded-endpoint-template.js +32 -0
  32. package/{src → dist/es}/templates/focused-endpoint-template.js +15 -15
  33. package/dist/es/templates/navbar-template.js +46 -0
  34. package/dist/es/templates/overview-template.js +9 -0
  35. package/dist/es/templates/responsiveViewMainBodyTemplate.js +30 -0
  36. package/dist/es/templates/security-scheme-template.js +330 -0
  37. package/dist/es/templates/server-template.js +42 -0
  38. package/{src → dist/es}/utils/color-utils.js +53 -16
  39. package/{src → dist/es}/utils/common-utils.js +18 -18
  40. package/{src → dist/es}/utils/schema-utils.js +248 -124
  41. package/{src → dist/es}/utils/spec-parser.js +112 -71
  42. package/dist/es/utils/theme.js +75 -0
  43. package/{src → dist/es}/utils/xml/xml.js +41 -38
  44. package/dist/lib/components/api-request.js +957 -0
  45. package/dist/lib/components/api-response.js +206 -0
  46. package/dist/lib/components/json-tree.js +82 -0
  47. package/dist/lib/components/mime-types.js +70 -0
  48. package/dist/lib/components/schema-table.js +170 -0
  49. package/dist/lib/components/schema-tree.js +206 -0
  50. package/dist/lib/components/tag-input.js +76 -0
  51. package/dist/lib/openapi-explorer-oauth-handler.js +19 -0
  52. package/dist/lib/openapi-explorer.js +817 -0
  53. package/dist/lib/styles/advanced-search-styles.js +10 -0
  54. package/dist/lib/styles/api-request-styles.js +10 -0
  55. package/dist/lib/styles/border-styles.js +10 -0
  56. package/dist/lib/styles/endpoint-styles.js +10 -0
  57. package/dist/lib/styles/flex-styles.js +10 -0
  58. package/dist/lib/styles/font-styles.js +10 -0
  59. package/dist/lib/styles/info-styles.js +10 -0
  60. package/dist/lib/styles/input-styles.js +11 -0
  61. package/dist/lib/styles/nav-styles.js +10 -0
  62. package/dist/lib/styles/prism-styles.js +10 -0
  63. package/dist/lib/styles/schema-styles.js +10 -0
  64. package/dist/lib/styles/tab-styles.js +10 -0
  65. package/dist/lib/styles/table-styles.js +10 -0
  66. package/dist/lib/templates/advance-search-template.js +42 -0
  67. package/dist/lib/templates/callback-template.js +12 -0
  68. package/dist/lib/templates/code-samples-template.js +36 -0
  69. package/dist/lib/templates/components-template.js +27 -0
  70. package/dist/lib/templates/endpoint-template.js +111 -0
  71. package/dist/lib/templates/expanded-endpoint-template.js +48 -0
  72. package/dist/lib/templates/focused-endpoint-template.js +95 -0
  73. package/dist/lib/templates/navbar-template.js +54 -0
  74. package/dist/lib/templates/overview-template.js +16 -0
  75. package/dist/lib/templates/responsiveViewMainBodyTemplate.js +47 -0
  76. package/dist/lib/templates/security-scheme-template.js +342 -0
  77. package/dist/lib/templates/server-template.js +49 -0
  78. package/dist/lib/utils/color-utils.js +112 -0
  79. package/dist/lib/utils/common-utils.js +156 -0
  80. package/dist/lib/utils/schema-utils.js +743 -0
  81. package/dist/lib/utils/spec-parser.js +361 -0
  82. package/dist/lib/utils/theme.js +84 -0
  83. package/dist/lib/utils/xml/xml.js +239 -0
  84. package/package.json +19 -6
  85. package/dist/openapi-explorer.min.js.LICENSE.txt +0 -71
  86. package/dist/openapi-explorer.min.js.LICENSE.txt.gz +0 -0
  87. package/dist/openapi-explorer.min.js.gz +0 -0
  88. package/dist/openapi-explorer.min.js.map.gz +0 -0
  89. package/dist/report.html +0 -38
  90. package/src/components/api-request.js +0 -1244
  91. package/src/components/api-response.js +0 -340
  92. package/src/components/json-tree.js +0 -129
  93. package/src/components/schema-table.js +0 -250
  94. package/src/components/schema-tree.js +0 -280
  95. package/src/components/tag-input.js +0 -109
  96. package/src/styles/advanced-search-styles.js +0 -84
  97. package/src/styles/api-request-styles.js +0 -111
  98. package/src/styles/border-styles.js +0 -24
  99. package/src/styles/css/main.css +0 -24
  100. package/src/styles/endpoint-styles.js +0 -222
  101. package/src/styles/flex-styles.js +0 -15
  102. package/src/styles/font-styles.js +0 -266
  103. package/src/styles/info-styles.js +0 -20
  104. package/src/styles/input-styles.js +0 -236
  105. package/src/styles/nav-styles.js +0 -141
  106. package/src/styles/prism-styles.js +0 -107
  107. package/src/styles/schema-styles.js +0 -121
  108. package/src/styles/tab-styles.js +0 -44
  109. package/src/styles/table-styles.js +0 -48
  110. package/src/templates/advance-search-template.js +0 -81
  111. package/src/templates/callback-template.js +0 -63
  112. package/src/templates/code-samples-template.js +0 -35
  113. package/src/templates/components-template.js +0 -43
  114. package/src/templates/endpoint-template.js +0 -175
  115. package/src/templates/expanded-endpoint-template.js +0 -104
  116. package/src/templates/navbar-template.js +0 -175
  117. package/src/templates/overview-template.js +0 -58
  118. package/src/templates/responsiveViewMainBodyTemplate.js +0 -72
  119. package/src/templates/security-scheme-template.js +0 -487
  120. package/src/templates/server-template.js +0 -106
  121. package/src/utils/theme.js +0 -163
@@ -0,0 +1,817 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+
6
+ var _litElement = require("lit-element");
7
+
8
+ var _marked = require("marked");
9
+
10
+ var _prismjs = _interopRequireDefault(require("prismjs"));
11
+
12
+ require("prismjs/components/prism-css");
13
+
14
+ require("prismjs/components/prism-yaml");
15
+
16
+ require("prismjs/components/prism-go");
17
+
18
+ require("prismjs/components/prism-java");
19
+
20
+ require("prismjs/components/prism-json");
21
+
22
+ require("prismjs/components/prism-bash");
23
+
24
+ require("prismjs/components/prism-python");
25
+
26
+ require("prismjs/components/prism-http");
27
+
28
+ require("prismjs/components/prism-csharp");
29
+
30
+ var _fontStyles = _interopRequireDefault(require("./styles/font-styles"));
31
+
32
+ var _inputStyles = _interopRequireDefault(require("./styles/input-styles"));
33
+
34
+ var _flexStyles = _interopRequireDefault(require("./styles/flex-styles"));
35
+
36
+ var _tableStyles = _interopRequireDefault(require("./styles/table-styles"));
37
+
38
+ var _endpointStyles = _interopRequireDefault(require("./styles/endpoint-styles"));
39
+
40
+ var _prismStyles = _interopRequireDefault(require("./styles/prism-styles"));
41
+
42
+ var _tabStyles = _interopRequireDefault(require("./styles/tab-styles"));
43
+
44
+ var _navStyles = _interopRequireDefault(require("./styles/nav-styles"));
45
+
46
+ var _infoStyles = _interopRequireDefault(require("./styles/info-styles"));
47
+
48
+ var _advancedSearchStyles = _interopRequireDefault(require("./styles/advanced-search-styles"));
49
+
50
+ var _commonUtils = require("./utils/common-utils");
51
+
52
+ var _specParser = _interopRequireDefault(require("./utils/spec-parser"));
53
+
54
+ var _responsiveViewMainBodyTemplate = _interopRequireDefault(require("./templates/responsiveViewMainBodyTemplate"));
55
+
56
+ var _apiRequestStyles = _interopRequireDefault(require("./styles/api-request-styles"));
57
+
58
+ var _securitySchemeTemplate = require("./templates/security-scheme-template");
59
+
60
+ require("./openapi-explorer-oauth-handler");
61
+
62
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
63
+
64
+ // It's possible none of these imports are actually necessary and should just be removed
65
+ // Styles
66
+ class OpenApiExplorer extends _litElement.LitElement {
67
+ constructor() {
68
+ super();
69
+ this.isV1 = false;
70
+ this.loading = true;
71
+ const intersectionObserverOptions = {
72
+ root: this.getRootNode().host,
73
+ rootMargin: '-50px 0px -50px 0px',
74
+ // when the element is visible 100px from bottom
75
+ threshold: 0
76
+ };
77
+ this.isIntersectionObserverActive = true;
78
+
79
+ if (typeof IntersectionObserver !== 'undefined') {
80
+ this.intersectionObserver = new IntersectionObserver(entries => {
81
+ this.onIntersect(entries);
82
+ }, intersectionObserverOptions);
83
+ } else {
84
+ this.intersectionObserver = {
85
+ disconnect() {},
86
+
87
+ observe() {}
88
+
89
+ };
90
+ }
91
+ }
92
+
93
+ static get properties() {
94
+ return {
95
+ // Heading
96
+ headingText: {
97
+ type: String,
98
+ attribute: 'heading-text'
99
+ },
100
+ explorerLocation: {
101
+ type: String,
102
+ attribute: 'explorer-location'
103
+ },
104
+ // Spec
105
+ specUrl: {
106
+ type: String,
107
+ attribute: 'spec-url'
108
+ },
109
+ // UI Layouts
110
+ layout: {
111
+ type: String
112
+ },
113
+ defaultSchemaTab: {
114
+ type: String,
115
+ attribute: 'default-schema-tab'
116
+ },
117
+ responseAreaHeight: {
118
+ type: String,
119
+ attribute: 'response-area-height'
120
+ },
121
+ fillRequestWithDefault: {
122
+ type: String,
123
+ attribute: 'fill-defaults'
124
+ },
125
+ // Schema Styles
126
+ schemaStyle: {
127
+ type: String,
128
+ attribute: 'schema-style'
129
+ },
130
+ schemaExpandLevel: {
131
+ type: Number,
132
+ attribute: 'schema-expand-level'
133
+ },
134
+ schemaDescriptionExpanded: {
135
+ type: String,
136
+ attribute: 'schema-description-expanded'
137
+ },
138
+ // API Server
139
+ serverUrl: {
140
+ type: String,
141
+ attribute: 'server-url'
142
+ },
143
+ // Hide/Show Sections & Enable Disable actions
144
+ showInfo: {
145
+ type: String,
146
+ attribute: 'show-info'
147
+ },
148
+ allowAuthentication: {
149
+ type: String,
150
+ attribute: 'show-authentication'
151
+ },
152
+ allowTry: {
153
+ type: String,
154
+ attribute: 'enable-console'
155
+ },
156
+ allowSearch: {
157
+ type: String,
158
+ attribute: 'allow-search'
159
+ },
160
+ allowAdvancedSearch: {
161
+ type: String,
162
+ attribute: 'allow-advanced-search'
163
+ },
164
+ allowServerSelection: {
165
+ type: String,
166
+ attribute: 'show-server-selection'
167
+ },
168
+ showComponents: {
169
+ type: String,
170
+ attribute: 'show-components'
171
+ },
172
+ // Main Colors and Font
173
+ primaryColor: {
174
+ type: String,
175
+ attribute: 'primary-color'
176
+ },
177
+ secondaryColor: {
178
+ type: String,
179
+ attribute: 'secondary-color'
180
+ },
181
+ bgColor: {
182
+ type: String,
183
+ attribute: 'bg-color'
184
+ },
185
+ textColor: {
186
+ type: String,
187
+ attribute: 'text-color'
188
+ },
189
+ headerColor: {
190
+ type: String,
191
+ attribute: 'header-color'
192
+ },
193
+ fontSize: {
194
+ type: String,
195
+ attribute: 'font-size'
196
+ },
197
+ // Nav Bar Colors
198
+ navBgColor: {
199
+ type: String,
200
+ attribute: 'nav-bg-color'
201
+ },
202
+ navTextColor: {
203
+ type: String,
204
+ attribute: 'nav-text-color'
205
+ },
206
+ navHoverBgColor: {
207
+ type: String,
208
+ attribute: 'nav-hover-bg-color'
209
+ },
210
+ navHoverTextColor: {
211
+ type: String,
212
+ attribute: 'nav-hover-text-color'
213
+ },
214
+ navItemSpacing: {
215
+ type: String,
216
+ attribute: 'nav-item-spacing'
217
+ },
218
+ usePathInNavBar: {
219
+ type: String,
220
+ attribute: 'use-path-in-nav-bar'
221
+ },
222
+ // Fetch Options
223
+ fetchCredentials: {
224
+ type: String,
225
+ attribute: 'fetch-credentials'
226
+ },
227
+ // Filters
228
+ matchPaths: {
229
+ type: String,
230
+ attribute: 'match-paths'
231
+ },
232
+ // Internal Properties
233
+ loading: {
234
+ type: Boolean
235
+ },
236
+ // indicates spec is being loaded
237
+ operationsCollapsed: {
238
+ type: Boolean
239
+ },
240
+ showAdvancedSearchDialog: {
241
+ type: Boolean
242
+ },
243
+ advancedSearchMatches: {
244
+ type: Object
245
+ }
246
+ };
247
+ }
248
+
249
+ static get styles() {
250
+ return [_fontStyles.default, _inputStyles.default, _flexStyles.default, _tableStyles.default, _endpointStyles.default, _prismStyles.default, _tabStyles.default, _navStyles.default, _infoStyles.default, _advancedSearchStyles.default, _apiRequestStyles.default, (0, _litElement.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}.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{padding:24px 8px 0 4px}.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{position:relative;padding:6px 0}.divider{border-top:2px solid var(--border-color);margin:24px 0;width:100%}.tooltip{border:1px solid var(--border-color);border-left-width:4px;margin-left:2px}.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:hover a:hover{color:var(--primary-color)}.tooltip:hover .tooltip-text{visibility:visible;opacity:1}@keyframes spin{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}@media only screen and (max-width:767.98px){.section-padding{margin:1rem}.sub-title.tag{margin-left: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:2rem 3rem}.endpoint-body{position:relative;padding:36px 0 48px 0}}@media only screen and (min-width:1024px){.nav-bar{width:${(0, _litElement.unsafeCSS)(this.fontSize === 'default' ? '300px' : this.fontSize === 'large' ? '315px' : '330px')};display:flex}.section-gap--read-mode{padding:24px 24px 12px}.main-content-inner{padding:24px}}`];
251
+ } // Startup
252
+
253
+
254
+ connectedCallback() {
255
+ super.connectedCallback();
256
+ this.handleResize = this.handleResize.bind(this);
257
+ window.addEventListener('resize', this.handleResize);
258
+ this.loading = true;
259
+ const parent = this.parentElement;
260
+
261
+ if (parent) {
262
+ if (parent.offsetWidth === 0 && parent.style.width === '') {
263
+ parent.style.width = '100vw';
264
+ }
265
+
266
+ if (parent.offsetHeight === 0 && parent.style.height === '') {
267
+ parent.style.height = '100vh';
268
+ }
269
+
270
+ if (parent.tagName === 'BODY') {
271
+ if (!parent.style.marginTop) {
272
+ parent.style.marginTop = '0';
273
+ }
274
+
275
+ if (!parent.style.marginRight) {
276
+ parent.style.marginRight = '0';
277
+ }
278
+
279
+ if (!parent.style.marginBottom) {
280
+ parent.style.marginBottom = '0';
281
+ }
282
+
283
+ if (!parent.style.marginLeft) {
284
+ parent.style.marginLeft = '0';
285
+ }
286
+ }
287
+ }
288
+
289
+ this.renderStyle = 'focused';
290
+ this.explorerLocation = this.explorerLocation || (0, _commonUtils.getCurrentElement)();
291
+
292
+ if (!this.schemaStyle || !'tree, table,'.includes(`${this.schemaStyle},`)) {
293
+ this.schemaStyle = 'tree';
294
+ }
295
+
296
+ if (!this.defaultSchemaTab || !'body, model,'.includes(`${this.defaultSchemaTab},`)) {
297
+ this.defaultSchemaTab = 'model';
298
+ }
299
+
300
+ if (!this.schemaExpandLevel || this.schemaExpandLevel < 1) {
301
+ this.schemaExpandLevel = 99999;
302
+ }
303
+
304
+ if (!this.schemaDescriptionExpanded || !'true, false,'.includes(`${this.schemaDescriptionExpanded},`)) {
305
+ this.schemaDescriptionExpanded = 'true';
306
+ }
307
+
308
+ this.schemaHideReadOnly = ['post', 'put', 'patch'].join(',');
309
+ this.schemaHideWriteOnly = true;
310
+
311
+ if (!this.fillRequestWithDefault || !'true, false,'.includes(`${this.fillRequestWithDefault},`)) {
312
+ this.fillRequestWithDefault = 'true';
313
+ }
314
+
315
+ if (!this.responseAreaHeight) {
316
+ this.responseAreaHeight = '300px';
317
+ }
318
+
319
+ if (!this.allowSearch || !'true, false,'.includes(`${this.allowSearch},`)) {
320
+ this.allowSearch = 'true';
321
+ }
322
+
323
+ if (!this.allowAdvancedSearch || !'true, false,'.includes(`${this.allowAdvancedSearch},`)) {
324
+ this.allowAdvancedSearch = 'true';
325
+ }
326
+
327
+ if (!this.allowTry || !'true, false,'.includes(`${this.allowTry},`)) {
328
+ this.allowTry = 'true';
329
+ }
330
+
331
+ if (!this.navItemSpacing || !'compact, relaxed, default,'.includes(`${this.navItemSpacing},`)) {
332
+ this.navItemSpacing = 'default';
333
+ }
334
+
335
+ if (!this.usePathInNavBar || !'true, false,'.includes(`${this.usePathInNavBar},`)) {
336
+ this.usePathInNavBar = 'false';
337
+ }
338
+
339
+ if (!this.fontSize || !'default, large, largest,'.includes(`${this.fontSize},`)) {
340
+ this.fontSize = 'default';
341
+ }
342
+
343
+ if (!this.showInfo || !'true, false,'.includes(`${this.showInfo},`)) {
344
+ this.showInfo = 'true';
345
+ }
346
+
347
+ if (!this.allowServerSelection || !'true, false,'.includes(`${this.allowServerSelection},`)) {
348
+ this.allowServerSelection = 'true';
349
+ }
350
+
351
+ if (!this.allowAuthentication || !'true, false,'.includes(`${this.allowAuthentication},`)) {
352
+ this.allowAuthentication = 'true';
353
+ }
354
+
355
+ if (!this.showComponents || !'true false'.includes(this.showComponents)) {
356
+ this.showComponents = 'true';
357
+ }
358
+
359
+ if (!this.fetchCredentials || !'omit, same-origin, include,'.includes(`${this.fetchCredentials},`)) {
360
+ this.fetchCredentials = '';
361
+ }
362
+
363
+ if (!this.showAdvancedSearchDialog) {
364
+ this.showAdvancedSearchDialog = false;
365
+ }
366
+
367
+ _marked.marked.setOptions({
368
+ highlight(code, lang) {
369
+ if (_prismjs.default.languages[lang]) {
370
+ return _prismjs.default.highlight(code, _prismjs.default.languages[lang], lang);
371
+ }
372
+
373
+ return code;
374
+ }
375
+
376
+ });
377
+
378
+ window.addEventListener('hashchange', () => {
379
+ this.scrollTo((0, _commonUtils.getCurrentElement)());
380
+ }, true);
381
+ this.handleResize();
382
+ } // Cleanup
383
+
384
+
385
+ disconnectedCallback() {
386
+ this.intersectionObserver.disconnect();
387
+ window.removeEventListener('resize', this.handleResize);
388
+ super.disconnectedCallback();
389
+ }
390
+
391
+ render() {
392
+ return _responsiveViewMainBodyTemplate.default.call(this);
393
+ }
394
+
395
+ observeExpandedContent() {
396
+ // Main Container
397
+ const observeOverviewEls = this.shadowRoot.querySelectorAll('.observe-me');
398
+ observeOverviewEls.forEach(targetEl => {
399
+ this.intersectionObserver.observe(targetEl);
400
+ });
401
+ }
402
+
403
+ handleResize() {
404
+ const mediaQueryResult = window.matchMedia('(min-width: 768px)');
405
+ const newDisplay = mediaQueryResult.matches ? 'focused' : 'view';
406
+
407
+ if (this.renderStyle !== newDisplay) {
408
+ this.renderStyle = newDisplay;
409
+ this.requestUpdate();
410
+ }
411
+ }
412
+
413
+ attributeChangedCallback(name, oldVal, newVal) {
414
+ if (name === 'spec-url') {
415
+ if (oldVal !== newVal) {
416
+ // put it at the end of event-loop to load all the attributes
417
+ window.setTimeout(async () => {
418
+ await this.loadSpec(newVal); // If the initial location is set, then attempt to scroll there
419
+
420
+ if (this.explorerLocation) {
421
+ this.scrollTo(this.explorerLocation);
422
+ }
423
+ }, 0);
424
+ }
425
+ }
426
+
427
+ if (name === 'render-style') {
428
+ if (newVal === 'read') {
429
+ window.setTimeout(() => {
430
+ this.observeExpandedContent();
431
+ }, 100);
432
+ } else {
433
+ this.intersectionObserver.disconnect();
434
+ }
435
+ }
436
+
437
+ if (name === 'explorer-location') {
438
+ window.setTimeout(() => {
439
+ this.scrollTo(newVal);
440
+ }, 0);
441
+ }
442
+
443
+ super.attributeChangedCallback(name, oldVal, newVal);
444
+ }
445
+
446
+ onSearchChange(e) {
447
+ this.operationsCollapsed = false;
448
+ this.matchPaths = e.target.value;
449
+ this.resolvedSpec.tags.forEach(tag => tag.paths.filter(v => {
450
+ if (this.matchPaths) {
451
+ // v.expanded = false;
452
+ if ((0, _commonUtils.pathIsInSearch)(this.matchPaths, v)) {
453
+ tag.expanded = true;
454
+ }
455
+ }
456
+ }));
457
+ this.resolvedSpec.components.forEach(component => {
458
+ component.subComponents.forEach(subComponent => {
459
+ subComponent.expanded = false;
460
+
461
+ if (!this.matchPaths || (0, _commonUtils.componentIsInSearch)(this.matchPaths, subComponent)) {
462
+ subComponent.expanded = true;
463
+ }
464
+ });
465
+ });
466
+ this.requestUpdate();
467
+ }
468
+
469
+ onClearSearch() {
470
+ const searchEl = this.shadowRoot.getElementById('nav-bar-search');
471
+ searchEl.value = '';
472
+ this.matchPaths = '';
473
+ this.resolvedSpec.components.forEach(component => {
474
+ component.subComponents.forEach(v => {
475
+ v.expanded = true;
476
+ });
477
+ });
478
+ }
479
+
480
+ async onShowSearchModalClicked() {
481
+ this.showAdvancedSearchDialog = true; // wait for the dialog to render
482
+
483
+ await (0, _commonUtils.sleep)(10);
484
+ const inputEl = this.shadowRoot.getElementById('advanced-search-dialog-input');
485
+
486
+ if (inputEl) {
487
+ inputEl.focus();
488
+ }
489
+ } // Public Method
490
+
491
+
492
+ async loadSpec(specUrlOrObject) {
493
+ if (!specUrlOrObject) {
494
+ return;
495
+ }
496
+
497
+ this.matchPaths = '';
498
+
499
+ try {
500
+ this.resolvedSpec = null;
501
+ this.loading = true;
502
+ this.loadFailed = false;
503
+ const spec = await (0, _specParser.default)(specUrlOrObject, this.serverUrl);
504
+ this.loading = false;
505
+
506
+ if (spec === undefined || spec === null) {
507
+ console.error('Unable to resolve the API spec. '); // eslint-disable-line no-console
508
+
509
+ return;
510
+ }
511
+
512
+ if (!this.serverUrl) {
513
+ this.serverUrl = spec.servers[0].computedUrl || spec.servers[0].url;
514
+ }
515
+
516
+ this.selectedServer = spec.servers.find(s => s.url === this.serverUrl || !this.serverUrl) || spec.servers[0];
517
+ this.afterSpecParsedAndValidated(spec);
518
+ } catch (err) {
519
+ this.loading = false;
520
+ this.loadFailed = true;
521
+ this.resolvedSpec = null;
522
+ console.error('OpenAPI Explorer: Unable to resolve the API spec..', err); // eslint-disable-line no-console
523
+ }
524
+ } // Public Method
525
+
526
+
527
+ async setAuthenticationConfiguration(apiKeyId, {
528
+ token,
529
+ clientId,
530
+ clientSecret,
531
+ redirectUri
532
+ }) {
533
+ const securityObj = this.resolvedSpec && this.resolvedSpec.securitySchemes.find(v => v.apiKeyId === apiKeyId);
534
+
535
+ if (!securityObj) {
536
+ throw Error('SecuritySchemeNotFound');
537
+ }
538
+
539
+ let authorizationToken = token && token.replace(/^(Bearer|Basic)\s+/i, '').trim();
540
+
541
+ if (authorizationToken && securityObj.type && securityObj.type === 'http' && securityObj.scheme && securityObj.scheme.toLowerCase() === 'basic') {
542
+ authorizationToken = `Basic ${btoa(authorizationToken)}`;
543
+ } else if (authorizationToken && securityObj.scheme && securityObj.scheme.toLowerCase() === 'bearer') {
544
+ authorizationToken = `Bearer ${authorizationToken}`;
545
+ } else {
546
+ authorizationToken = null;
547
+ }
548
+
549
+ securityObj.clientId = clientId && clientId.trim();
550
+ securityObj.clientSecret = clientSecret && clientSecret.trim();
551
+ securityObj.redirectUri = new URL(redirectUri && redirectUri.trim() || '', window.location.href).toString();
552
+ securityObj.finalKeyValue = authorizationToken;
553
+ await _securitySchemeTemplate.checkForAuthToken.call(this);
554
+ this.requestUpdate();
555
+ }
556
+
557
+ afterSpecParsedAndValidated(spec) {
558
+ this.resolvedSpec = spec;
559
+ this.dispatchEvent(new CustomEvent('spec-loaded', {
560
+ bubbles: true,
561
+ detail: spec
562
+ }));
563
+ this.requestUpdate(); // Initiate IntersectionObserver and put it at the end of event loop, to allow loading all the child elements (must for larger specs)
564
+
565
+ this.intersectionObserver.disconnect();
566
+
567
+ if (this.renderStyle === 'focused') {
568
+ const defaultElementId = this.showInfo ? 'overview' : this.resolvedSpec.tags && this.resolvedSpec.tags[0] && this.resolvedSpec.tags[0].paths[0];
569
+ this.scrollTo(this.explorerLocation || defaultElementId);
570
+ }
571
+
572
+ if (this.renderStyle === 'view' && this.explorerLocation) {
573
+ this.expandAndGotoOperation(this.explorerLocation);
574
+ }
575
+ }
576
+
577
+ expandAndGotoOperation(elementId) {
578
+ // Expand full operation and tag
579
+ let isExpandingNeeded = false;
580
+ const tag = this.resolvedSpec.tags.find(t => t.paths && t.paths.find(p => p.elementId === elementId));
581
+ const path = tag && tag.paths && tag.paths.find(p => p.elementId === elementId);
582
+
583
+ if (path && (!path.expanded || !tag.expanded)) {
584
+ isExpandingNeeded = true;
585
+ path.expanded = true;
586
+ tag.expanded = true;
587
+ this.requestUpdate();
588
+ } // requestUpdate() and delay required, else we cant find element because it won't exist immediately
589
+
590
+
591
+ const tmpElementId = elementId.indexOf('#') === -1 ? elementId : elementId.substring(1);
592
+ window.setTimeout(() => {
593
+ const gotoEl = this.shadowRoot.getElementById(tmpElementId);
594
+
595
+ if (gotoEl) {
596
+ gotoEl.scrollIntoView({
597
+ behavior: 'auto',
598
+ block: 'start'
599
+ });
600
+ (0, _commonUtils.replaceState)(tmpElementId);
601
+ }
602
+ }, isExpandingNeeded ? 150 : 0);
603
+ }
604
+
605
+ isValidTopId(id) {
606
+ return id.startsWith('overview') || id === 'servers' || id === 'auth';
607
+ }
608
+
609
+ isValidPathId(id) {
610
+ if (id === 'overview' && this.showInfo) {
611
+ return true;
612
+ }
613
+
614
+ if (id === 'servers' && this.allowServerSelection) {
615
+ return true;
616
+ }
617
+
618
+ if (id === 'auth' && this.allowAuthentication) {
619
+ return true;
620
+ }
621
+
622
+ if (id.startsWith('tag--')) {
623
+ return this.resolvedSpec.tags && this.resolvedSpec.tags.find(tag => tag.elementId === id);
624
+ }
625
+
626
+ return this.resolvedSpec.tags && this.resolvedSpec.tags.find(tag => tag.paths.find(path => path.elementId === id));
627
+ }
628
+
629
+ onIntersect(entries) {
630
+ if (this.isIntersectionObserverActive === false) {
631
+ return;
632
+ }
633
+
634
+ entries.forEach(entry => {
635
+ if (entry.isIntersecting && entry.intersectionRatio > 0) {
636
+ 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');
637
+ const newNavEl = this.shadowRoot.getElementById(`link-${entry.target.id}`); // Add active class in the new element
638
+
639
+ if (newNavEl) {
640
+ (0, _commonUtils.replaceState)(entry.target.id);
641
+ newNavEl.scrollIntoView({
642
+ behavior: 'auto',
643
+ block: 'center'
644
+ });
645
+ newNavEl.classList.add('active');
646
+ } // Remove active class from previous element
647
+
648
+
649
+ if (oldNavEl) {
650
+ oldNavEl.classList.remove('active');
651
+ }
652
+ }
653
+ });
654
+ } // Called by anchor tags created using markdown
655
+
656
+
657
+ handleHref(e) {
658
+ if (e.target.tagName.toLowerCase() === 'a') {
659
+ const anchor = e.target.getAttribute('href');
660
+
661
+ if (anchor && anchor.startsWith('#')) {
662
+ const gotoEl = this.shadowRoot.getElementById(anchor.replace('#', ''));
663
+
664
+ if (gotoEl) {
665
+ gotoEl.scrollIntoView({
666
+ behavior: 'auto',
667
+ block: 'start'
668
+ });
669
+ }
670
+ }
671
+ }
672
+ }
673
+ /**
674
+ * Called by
675
+ * - onClick of Navigation Bar
676
+ * - onClick of Advanced Search items
677
+ *
678
+ * Functionality:
679
+ * 1. First deactivate IntersectionObserver
680
+ * 2. Scroll to the element
681
+ * 3. Activate IntersectionObserver (after little delay)
682
+ *
683
+ */
684
+
685
+
686
+ scrollToEventTarget(event, scrollNavItemToView = true) {
687
+ const navEl = event.currentTarget;
688
+
689
+ if (!navEl.dataset.contentId) {
690
+ return;
691
+ }
692
+
693
+ let repeatedElementIndex;
694
+
695
+ if (navEl.dataset.contentId === 'section') {
696
+ const navSectionSlot = this.shadowRoot.querySelector('slot.custom-nav-section');
697
+ const assignedNodes = navSectionSlot && navSectionSlot.assignedNodes();
698
+ repeatedElementIndex = assignedNodes && [].findIndex.call(assignedNodes, slot => slot === event.target);
699
+ }
700
+
701
+ this.isIntersectionObserverActive = false;
702
+ this.scrollTo(navEl.dataset.contentId, scrollNavItemToView, repeatedElementIndex);
703
+ setTimeout(() => {
704
+ this.isIntersectionObserverActive = true;
705
+ }, 300);
706
+ } // Public Method (scrolls to a given path and highlights the left-nav selection)
707
+
708
+
709
+ async scrollTo(elementId, scrollNavItemToView = true, repeatedElementIndex) {
710
+ if (!this.resolvedSpec) {
711
+ return;
712
+ }
713
+
714
+ if (this.renderStyle === 'view') {
715
+ this.expandAndGotoOperation(elementId);
716
+ return;
717
+ } // explorerLocation will get validated in the focused-endpoint-template
718
+
719
+
720
+ this.explorerLocation = elementId;
721
+ await (0, _commonUtils.sleep)(0);
722
+ const contentEl = this.shadowRoot.getElementById(elementId);
723
+
724
+ if (!contentEl) {
725
+ return;
726
+ } // For focused APIs, always scroll to the top of the component
727
+
728
+
729
+ if (!elementId.match('cmp--')) {
730
+ this.shadowRoot.getElementById('operations-root').scrollIntoView({
731
+ behavior: 'auto',
732
+ block: 'start'
733
+ });
734
+ } else {
735
+ contentEl.scrollIntoView({
736
+ behavior: 'auto',
737
+ block: 'start'
738
+ });
739
+ } // 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
740
+
741
+
742
+ const requestEl = this.shadowRoot.querySelector('api-request');
743
+
744
+ if (requestEl) {
745
+ requestEl.resetRequestBodySelection();
746
+ }
747
+
748
+ const responseEl = this.shadowRoot.querySelector('api-response');
749
+
750
+ if (responseEl) {
751
+ responseEl.resetSelection();
752
+ } // Update Location Hash
753
+
754
+
755
+ (0, _commonUtils.replaceState)(elementId); // Update NavBar View and Styles
756
+
757
+ let newNavEl = this.shadowRoot.getElementById(`link-${elementId}`);
758
+
759
+ if (elementId === 'section') {
760
+ const navSectionSlot = this.shadowRoot.querySelector('slot.custom-nav-section');
761
+ const assignedNodes = navSectionSlot && navSectionSlot.assignedNodes();
762
+ newNavEl = assignedNodes && assignedNodes[repeatedElementIndex || 0];
763
+ }
764
+
765
+ if (!newNavEl) {
766
+ return;
767
+ }
768
+
769
+ if (scrollNavItemToView) {
770
+ newNavEl.scrollIntoView({
771
+ behavior: 'auto',
772
+ block: 'center'
773
+ });
774
+ }
775
+
776
+ await (0, _commonUtils.sleep)(0);
777
+ 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');
778
+
779
+ if (oldNavEl) {
780
+ oldNavEl.classList.remove('active');
781
+ }
782
+
783
+ const navSectionSlot = this.shadowRoot.querySelector('slot.custom-nav-section');
784
+ const assignedNodes = navSectionSlot && navSectionSlot.assignedNodes();
785
+ (assignedNodes || []).filter((n, nodeIndex) => nodeIndex !== repeatedElementIndex).forEach(node => {
786
+ node.classList.remove('active');
787
+ });
788
+ newNavEl.classList.add('active'); // must add the class after scrolling
789
+
790
+ this.requestUpdate();
791
+ } // Event handler for Advanced Search text-inputs and checkboxes
792
+
793
+
794
+ onAdvancedSearch(ev, delay) {
795
+ const eventTargetEl = ev.target;
796
+ clearTimeout(this.timeoutId);
797
+ this.timeoutId = setTimeout(() => {
798
+ let searchInputEl;
799
+
800
+ if (eventTargetEl.type === 'text') {
801
+ searchInputEl = eventTargetEl;
802
+ } else {
803
+ searchInputEl = eventTargetEl.closest('.advanced-search-options').querySelector('input[type=text]');
804
+ }
805
+
806
+ const searchOptions = [...eventTargetEl.closest('.advanced-search-options').querySelectorAll('input:checked')].map(v => v.id);
807
+ this.advancedSearchMatches = (0, _commonUtils.advancedSearch)(searchInputEl.value, this.resolvedSpec.tags, searchOptions);
808
+ }, delay);
809
+ }
810
+
811
+ }
812
+
813
+ exports.default = OpenApiExplorer;
814
+
815
+ if (!customElements.get('openapi-explorer')) {
816
+ customElements.define('openapi-explorer', OpenApiExplorer);
817
+ }