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
@@ -1,250 +0,0 @@
1
- import { LitElement, html, css } from 'lit-element';
2
- import { marked } from 'marked';
3
- import { unsafeHTML } from 'lit-html/directives/unsafe-html';
4
- import FontStyles from '../styles/font-styles';
5
- import SchemaStyles from '../styles/schema-styles';
6
-
7
- export default class SchemaTable extends LitElement {
8
- static get properties() {
9
- return {
10
- schemaExpandLevel: { type: Number, attribute: 'schema-expand-level' },
11
- schemaDescriptionExpanded: { type: String, attribute: 'schema-description-expanded' },
12
- schemaHideReadOnly: { type: String, attribute: 'schema-hide-read-only' },
13
- schemaHideWriteOnly: { type: String, attribute: 'schema-hide-write-only' },
14
- data: { type: Object },
15
- };
16
- }
17
-
18
- connectedCallback() {
19
- super.connectedCallback();
20
- if (!this.schemaExpandLevel || this.schemaExpandLevel < 1) { this.schemaExpandLevel = 99999; }
21
- if (!this.schemaDescriptionExpanded || !'true false'.includes(this.schemaDescriptionExpanded)) { this.schemaDescriptionExpanded = 'true'; }
22
- if (!this.schemaHideReadOnly || !'true false'.includes(this.schemaHideReadOnly)) { this.schemaHideReadOnly = 'true'; }
23
- if (!this.schemaHideWriteOnly || !'true false'.includes(this.schemaHideWriteOnly)) { this.schemaHideWriteOnly = 'true'; }
24
- }
25
-
26
- static get styles() {
27
- return [
28
- FontStyles,
29
- SchemaStyles,
30
- css`
31
- .table {
32
- font-size: var(--font-size-small);
33
- text-align: left;
34
- line-height: calc(var(--font-size-small) + 6px);
35
- }
36
- .table .tr {
37
- width: calc(100% - 5px);
38
- padding: 0 0 0 5px;
39
- border-bottom: 1px dotted var(--light-border-color);
40
- }
41
- .table .td {
42
- padding: 4px 0;
43
- }
44
- .table .key {
45
- width: 240px;
46
- }
47
- .key.deprecated .key-label {
48
- text-decoration: line-through;
49
- }
50
-
51
- .table .key-type {
52
- white-space: normal;
53
- width: 150px;
54
- }
55
- .collapsed-descr .tr {
56
- max-height: calc(var(--font-size-small) + var(--font-size-small) + 4px);
57
- }
58
-
59
- .obj-toggle {
60
- padding: 0 2px;
61
- border-radius:2px;
62
- border: 1px solid transparent;
63
- display: inline-block;
64
- margin-left: -16px;
65
- color:var(--primary-color);
66
- cursor: pointer;
67
- font-size: calc(var(--font-size-small) + 4px);
68
- font-family: var(--font-mono);
69
- background-clip: border-box;
70
- }
71
- .obj-toggle:hover {
72
- border-color: var(--primary-color);
73
- }
74
- .tr.expanded + .object-body {
75
- display:block;
76
- }
77
- .tr.collapsed + .object-body {
78
- display:none;
79
- }`,
80
- ];
81
- }
82
-
83
- /* eslint-disable indent */
84
- render() {
85
- return html`
86
- <div class="table ${this.schemaDescriptionExpanded === 'true' ? 'expanded-descr' : 'collapsed-descr'}">
87
- <div class='toolbar'>
88
- <div style="flex:1"></div>
89
- <div class='toolbar-item' @click='${() => { this.schemaDescriptionExpanded = (this.schemaDescriptionExpanded === 'true' ? 'false' : 'true'); }}'>
90
- ${this.schemaDescriptionExpanded === 'true' ? 'Collapse descriptions' : 'Expand descriptions'}
91
- </div>
92
- </div>
93
- ${this.data && this.data['::description']
94
- ? html`<span class='m-markdown'> ${unsafeHTML(marked(this.data['::description'] || ''))}</span>`
95
- : ''
96
- }
97
- <div style = 'border:1px solid var(--light-border-color)'>
98
- <div style='display:flex; background-color: var(--bg2); padding:8px 4px; border-bottom:1px solid var(--light-border-color);'>
99
- <div class='key' style='font-family:var(--font-regular); font-weight:bold; color:var(--fg);'> Field </div>
100
- <div class='key-type' style='font-family:var(--font-regular); font-weight:bold; color:var(--fg);'> Type </div>
101
- <div class='key-descr' style='font-family:var(--font-regular); font-weight:bold; color:var(--fg);'> Description </div>
102
- </div>
103
- ${this.data ? html`${this.generateTree(this.data['::type'] === 'array' ? this.data['::props'] : this.data, this.data['::type'])}` : ''}
104
- </div>
105
- </div>
106
- `;
107
- }
108
-
109
- generateTree(data, dataType = 'object', key = '', description = '', schemaLevel = 0, indentLevel = 0) {
110
- const newSchemaLevel = data['::type'] && data['::type'].startsWith('xxx-of') ? schemaLevel : (schemaLevel + 1);
111
- const newIndentLevel = dataType === 'xxx-of-option' || data['::type'] === 'xxx-of-option' || key.startsWith('::OPTION') ? indentLevel : (indentLevel + 1);
112
- const leftPadding = 16 * newIndentLevel; // 2 space indentation at each level
113
-
114
- if (!data) {
115
- return html`<div class="null" style="display:inline;">null</div>`;
116
- }
117
- if (Object.keys(data).length === 0) {
118
- return html`<span class="td key object" style='padding-left:${leftPadding}px'>${key}</span>`;
119
- }
120
- let keyLabel = '';
121
- let keyDescr = '';
122
- let isOneOfLabel = false;
123
- if (key.startsWith('::ONE~OF') || key.startsWith('::ANY~OF')) {
124
- keyLabel = key.replace('::', '').replace('~', ' ');
125
- isOneOfLabel = true;
126
- } else if (key.startsWith('::OPTION')) {
127
- const parts = key.split('~');
128
- keyLabel = parts[1];
129
- keyDescr = parts[2];
130
- } else {
131
- keyLabel = key;
132
- }
133
-
134
- let detailObjType = '';
135
- if (data['::type'] === 'object') {
136
- if (dataType === 'array') {
137
- detailObjType = 'array'; // Array of Object
138
- } else {
139
- detailObjType = 'object';
140
- }
141
- } else if (data['::type'] === 'array') {
142
- if (dataType === 'array') {
143
- detailObjType = 'array of array'; // Array of array
144
- } else {
145
- detailObjType = 'array';
146
- }
147
- }
148
-
149
- if (typeof data === 'object') {
150
- return html`
151
- ${newSchemaLevel >= 0 && key
152
- ? html`
153
- <div class='tr ${newSchemaLevel <= this.schemaExpandLevel ? 'expanded' : 'collapsed'} ${data['::type']}' data-obj='${keyLabel}'>
154
- <div class="td key ${data['::deprecated'] ? 'deprecated' : ''}" style='padding-left:${leftPadding}px'>
155
- ${(keyLabel || keyDescr)
156
- ? html`
157
- <span
158
- class='obj-toggle ${newSchemaLevel < this.schemaExpandLevel ? 'expanded' : 'collapsed'}'
159
- data-obj='${keyLabel}'
160
- @click= ${(e) => this.toggleObjectExpand(e, keyLabel)}
161
- >
162
- ${schemaLevel < this.schemaExpandLevel ? '-' : '+'}
163
- </span>`
164
- : ''
165
- }
166
- ${data['::type'] === 'xxx-of-option' || data['::type'] === 'xxx-of-array' || key.startsWith('::OPTION')
167
- ? html`<span class="xxx-of-key" style="margin-left:-6px">${keyLabel}</span><span class="${isOneOfLabel ? 'xxx-of-key' : 'xxx-of-descr'}">${keyDescr}</span>`
168
- : keyLabel.endsWith('*')
169
- ? html`<span class="key-label" style="display:inline-block; margin-left:-6px;"> ${keyLabel.substring(0, keyLabel.length - 1)}</span><span style='color:var(--red);'>*</span>`
170
- : html`<span class="key-label" style="display:inline-block; margin-left:-6px;">${keyLabel === '::props' ? '' : keyLabel}</span>`
171
- }
172
- ${data['::type'] === 'xxx-of' && dataType === 'array' ? html`<span style="color:var(--primary-color)">ARRAY</span>` : ''}
173
- </div>
174
- <div class='td key-type'>${(data['::type'] || '').includes('xxx-of') ? '' : detailObjType}</div>
175
- <div class='td key-descr m-markdown-small' style='line-height:1.7'>${unsafeHTML(marked(description || ''))}</div>
176
- </div>`
177
- : html`
178
- ${data['::type'] === 'array' && dataType === 'array'
179
- ? html`<div class='tr'> <div class='td'> ${dataType} </div> </div>`
180
- : ''
181
- }
182
- `
183
- }
184
- <div class='object-body'>
185
- ${Array.isArray(data) && data[0]
186
- ? html`${this.generateTree(data[0], 'xxx-of-option', '::ARRAY~OF', '', newSchemaLevel, newIndentLevel)}`
187
- : html`${Object.keys(data).map((dataKey) =>
188
- ['::title', '::description', '::type', '::props', '::deprecated'].includes(dataKey) && data[dataKey]['::type'] !== 'array' && data[dataKey]['::type'] !== 'object' ? ''
189
- : html`${this.generateTree(data[dataKey]['::type'] === 'array' ? data[dataKey]['::props'] : data[dataKey],
190
- data[dataKey]['::type'], dataKey, data[dataKey]['::description'], newSchemaLevel, newIndentLevel)}`
191
- )}`
192
- }
193
- <div>
194
- `;
195
- }
196
-
197
- // For Primitive Data types
198
- const { type, readOrWriteOnly, constraint, defaultValue, allowedValues, pattern, schemaDescription, schemaTitle, deprecated } = JSON.parse(data);
199
- if (readOrWriteOnly === '🆁' && this.schemaHideReadOnly === 'true') {
200
- return undefined;
201
- }
202
- if (readOrWriteOnly === '🆆' && this.schemaHideWriteOnly === 'true') {
203
- return undefined;
204
- }
205
- const dataTypeCss = type.replace(/┃.*/g, '').replace(/[^a-zA-Z0-9+]/g, '').substring(0, 4).toLowerCase();
206
- return html`
207
- <div class = "tr primitive">
208
- <div class="td key ${deprecated ? 'deprecated' : ''}" style='padding-left:${leftPadding}px' >
209
- ${keyLabel && keyLabel.endsWith('*')
210
- ? html`<span class="key-label">${keyLabel.substring(0, keyLabel.length - 1)}</span><span style='color:var(--red);'>*</span>`
211
- : key.startsWith('::OPTION')
212
- ? html`<span class='xxx-of-key'>${keyLabel}</span><span class="xxx-of-descr">${keyDescr}</span>`
213
- : html`${keyLabel ? html`<span class="key-label"> ${keyLabel}</span>` : html`<span class="xxx-of-descr">${schemaTitle}</span>`}`
214
- }
215
- </div>
216
- <div class='td key-type ${dataTypeCss}'>
217
- ${dataType === 'array' ? `${type}[]` : type}
218
- <span style="font-family: var(--font-mono);" title="${readOrWriteOnly === '🆁' && 'Read only attribute' || readOrWriteOnly === '🆆' && 'Write only attribute' || ''}">
219
- ${readOrWriteOnly}
220
- </span>
221
- </div>
222
- <div class='td key-descr'>
223
- ${dataType === 'array' ? html`<span class="m-markdown-small">${unsafeHTML(marked(description))}</span>` : ''}
224
- ${schemaTitle || schemaDescription ? html`<span class="m-markdown-small">${unsafeHTML(marked(`${schemaTitle ? `**${schemaTitle}:** ` : ''}${schemaDescription || ''}`))}</span>` : ''}
225
- ${constraint ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px;'> <span class='bold-text'>Constraints: </span> ${constraint}</div>` : ''}
226
- ${defaultValue ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px;'> <span class='bold-text'>Default: </span>${defaultValue}</div>` : ''}
227
- ${allowedValues ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px;'> <span class='bold-text'>Allowed: </span>${allowedValues}</div>` : ''}
228
- ${pattern ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px;'> <span class='bold-text'>Pattern: </span>${pattern}</div>` : ''}
229
- </div>
230
- </div>
231
- `;
232
- }
233
- /* eslint-enable indent */
234
-
235
- toggleObjectExpand(e) {
236
- const rowEl = e.target.closest('.tr');
237
- if (rowEl.classList.contains('expanded')) {
238
- rowEl.classList.add('collapsed');
239
- rowEl.classList.remove('expanded');
240
- e.target.innerText = '+';
241
- } else {
242
- rowEl.classList.remove('collapsed');
243
- rowEl.classList.add('expanded');
244
- e.target.innerText = '-';
245
- }
246
- }
247
- }
248
- if (!customElements.get('openapi-explorer')) {
249
- customElements.define('schema-table', SchemaTable);
250
- }
@@ -1,280 +0,0 @@
1
- import { LitElement, html, css } from 'lit-element';
2
- import { marked } from 'marked';
3
- import { unsafeHTML } from 'lit-html/directives/unsafe-html';
4
- import FontStyles from '../styles/font-styles';
5
- import SchemaStyles from '../styles/schema-styles';
6
- import BorderStyles from '../styles/border-styles';
7
-
8
- export default class SchemaTree extends LitElement {
9
- static get properties() {
10
- return {
11
- data: { type: Object },
12
- schemaExpandLevel: { type: Number, attribute: 'schema-expand-level' },
13
- schemaDescriptionExpanded: { type: String, attribute: 'schema-description-expanded' },
14
- schemaHideReadOnly: { type: String, attribute: 'schema-hide-read-only' },
15
- schemaHideWriteOnly: { type: String, attribute: 'schema-hide-write-only' },
16
- };
17
- }
18
-
19
- connectedCallback() {
20
- super.connectedCallback();
21
- if (!this.schemaExpandLevel || this.schemaExpandLevel < 1) { this.schemaExpandLevel = 99999; }
22
- if (!this.schemaDescriptionExpanded || !'true false'.includes(this.schemaDescriptionExpanded)) { this.schemaDescriptionExpanded = 'true'; }
23
- if (!this.schemaHideReadOnly || !'true false'.includes(this.schemaHideReadOnly)) { this.schemaHideReadOnly = 'true'; }
24
- if (!this.schemaHideWriteOnly || !'true false'.includes(this.schemaHideWriteOnly)) { this.schemaHideWriteOnly = 'true'; }
25
- }
26
-
27
- static get styles() {
28
- return [
29
- FontStyles,
30
- SchemaStyles,
31
- BorderStyles,
32
- css`
33
- .tree {
34
- min-height: 30px;
35
- background: rgb(51, 51, 51);
36
- padding: 10px;
37
- color: white;
38
- font-size:var(--font-size-small);
39
- text-align: left;
40
- line-height:calc(var(--font-size-small) + 6px);
41
- }
42
- .collapsed-descr .tr {
43
- max-height:calc(var(--font-size-small) + 8px);
44
- }
45
- .collapsed-descr .m-markdown-small p {
46
- line-height:calc(var(--font-size-small) + 6px);
47
- }
48
-
49
- .tree .key {
50
- max-width: 300px;
51
- }
52
- .key.deprecated .key-label {
53
- text-decoration: line-through;
54
- }
55
-
56
- .open-bracket{
57
- display:inline-block;
58
- padding: 0 20px 0 0;
59
- cursor: pointer;
60
- border: 1px solid transparent;
61
- border-radius:3px;
62
- }
63
- .open-bracket:hover {
64
- color:var(--primary-color);
65
- background-color:var(--hover-color);
66
- border: 1px solid var(--border-color);
67
- }
68
- .close-bracket{
69
- display:inline-block;
70
- font-family: var(--font-mono);
71
- }
72
- .tr.collapsed + .inside-bracket,
73
- .tr.collapsed + .inside-bracket + .close-bracket{
74
- display:none;
75
- }
76
- .inside-bracket.object,
77
- .inside-bracket.array {
78
- border-left: 1px dotted var(--border-color);
79
- }
80
- .inside-bracket.xxx-of {
81
- padding:5px 0px;
82
- border-style: dotted;
83
- border-width: 0 0 1px 0;
84
- border-color:var(--primary-color);
85
- }`,
86
- ];
87
- }
88
-
89
- /* eslint-disable indent */
90
- render() {
91
- return html`
92
- <div class="tree ${this.schemaDescriptionExpanded === 'true' ? 'expanded-descr' : 'collapsed-descr'}">
93
- <div class="toolbar">
94
- ${this.data && this.data['::description'] ? html`<span class='m-markdown' style="margin-block-start: 0"> ${unsafeHTML(marked(this.data['::description'] || ''))}</span>` : html`<div>&nbsp;</div>`}
95
- <div class="toolbar-item" @click='${() => { this.schemaDescriptionExpanded = (this.schemaDescriptionExpanded === 'true' ? 'false' : 'true'); }}'>
96
- ${this.schemaDescriptionExpanded === 'true' ? 'Collapse descriptions' : 'Expand descriptions'}
97
- </div>
98
- </div>
99
- ${this.data
100
- ? html`${this.generateTree(this.data['::type'] === 'array' ? this.data['::props'] : this.data, this.data['::type'])}`
101
- : html`<span class='mono-font' style='color:var(--red)'> Schema not found </span>`
102
- }
103
- </div>
104
- `;
105
- }
106
-
107
- generateTree(data, dataType = 'object', key = '', description = '', schemaLevel = 0, indentLevel = 0) {
108
- if (!data) {
109
- return html`<div class="null" style="display:inline;">null</div>`;
110
- }
111
- if (Object.keys(data).length === 0) {
112
- return html`<span class="key object">${key}:{ }</span>`;
113
- }
114
- let keyLabel = '';
115
- let keyDescr = '';
116
- if (key.startsWith('::ONE~OF') || key.startsWith('::ANY~OF')) {
117
- keyLabel = key.replace('::', '').replace('~', ' ');
118
- } else if (key.startsWith('::OPTION')) {
119
- const parts = key.split('~');
120
- keyLabel = parts[1];
121
- keyDescr = parts[2];
122
- } else {
123
- keyLabel = key;
124
- }
125
-
126
- const leftPadding = 16;
127
- // Min-width used for model keys: `td key `
128
- const minFieldColWidth = 250 - (indentLevel * leftPadding);
129
- let openBracket = '';
130
- let closeBracket = '';
131
- const newSchemaLevel = data['::type'] && data['::type'].startsWith('xxx-of') ? schemaLevel : (schemaLevel + 1);
132
- // const newIndentLevel = dataType === 'xxx-of-option' || data['::type'] === 'xxx-of-option' ? indentLevel : (indentLevel + 1);
133
- const newIndentLevel = dataType === 'xxx-of-option' || data['::type'] === 'xxx-of-option' || key.startsWith('::OPTION') ? indentLevel : (indentLevel + 1);
134
- if (data['::type'] === 'object') {
135
- if (dataType === 'array') {
136
- if (schemaLevel < this.schemaExpandLevel) {
137
- openBracket = html`<span class="open-bracket array-of-object" @click="${this.toggleObjectExpand}">[{</span>`;
138
- } else {
139
- openBracket = html`<span class="open-bracket array-of-object" @click="${this.toggleObjectExpand}">[{...}]</span>`;
140
- }
141
- closeBracket = '}]';
142
- } else {
143
- if (schemaLevel < this.schemaExpandLevel) {
144
- openBracket = html`<span class="open-bracket object" @click="${this.toggleObjectExpand}">{</span>`;
145
- } else {
146
- openBracket = html`<span class="open-bracket object" @click="${this.toggleObjectExpand}">{...}</span>`;
147
- }
148
- closeBracket = '}';
149
- }
150
- } else if (data['::type'] === 'array') {
151
- if (dataType === 'array') {
152
- if (schemaLevel < this.schemaExpandLevel) {
153
- openBracket = html`<span class="open-bracket array-of-array" @click="${this.toggleObjectExpand}">[[</span>`;
154
- } else {
155
- openBracket = html`<span class="open-bracket array-of-array" @click="${this.toggleObjectExpand}">[[...]]</span>`;
156
- }
157
- closeBracket = ']]';
158
- } else {
159
- if (schemaLevel < this.schemaExpandLevel) {
160
- openBracket = html`<span class="open-bracket array" @click="${this.toggleObjectExpand}">[</span>`;
161
- } else {
162
- openBracket = html`<span class="open-bracket array" @click="${this.toggleObjectExpand}">[...]</span>`;
163
- }
164
- closeBracket = ']';
165
- }
166
- }
167
-
168
- if (typeof data === 'object') {
169
- const flags = data['::flags'] || {};
170
- if (flags['🆁'] && this.schemaHideReadOnly === 'true') {
171
- return undefined;
172
- }
173
- if (flags['🆆'] && this.schemaHideWriteOnly === 'true') {
174
- return undefined;
175
- }
176
- const displayLine = [flags['🆁'] || flags['🆆'], description].filter(v => v).join(' ');
177
- return html`
178
- <div class="tr ${schemaLevel < this.schemaExpandLevel || data['::type'] && data['::type'].startsWith('xxx-of') ? 'expanded' : 'collapsed'} ${data['::type'] || 'no-type-info'}">
179
- <div class="td key ${data['::deprecated'] ? 'deprecated' : ''}" style='min-width:${minFieldColWidth}px'>
180
- ${data['::type'] === 'xxx-of-option' || data['::type'] === 'xxx-of-array' || key.startsWith('::OPTION')
181
- ? html`<span class='key-label xxx-of-key'>${keyLabel}</span><span class="xxx-of-descr">${keyDescr}</span>`
182
- : keyLabel.endsWith('*')
183
- ? html`<span class="key-label">${keyLabel.substring(0, keyLabel.length - 1)}</span><span style='color:var(--red);'>*</span>:`
184
- : keyLabel === '::props' || keyLabel === '::ARRAY~OF'
185
- ? ''
186
- : schemaLevel > 0
187
- ? html`<span class="key-label">${keyLabel}:</span>`
188
- : ''
189
- }
190
- ${data['::type'] === 'xxx-of' && dataType === 'array' ? html`<span style="color:var(--primary-color)">ARRAY</span>` : ''}
191
- ${openBracket}
192
- </div>
193
- <div class="td key-descr">
194
- <span class="m-markdown-small" style="font-family: var(--font-mono); vertical-align: middle;" title="${flags['🆁'] && 'Read only attribute' || flags['🆆'] && 'Write only attribute' || ''}">
195
- ${unsafeHTML(marked(displayLine))}
196
- </span>
197
- </div>
198
- </div>
199
- <div class='inside-bracket ${data['::type'] || 'no-type-info'}' style='padding-left:${data['::type'] === 'xxx-of-option' || data['::type'] === 'xxx-of-array' ? 0 : leftPadding}px;'>
200
- ${Array.isArray(data) && data[0] ? html`${this.generateTree(data[0], 'xxx-of-option', '::ARRAY~OF', '', newSchemaLevel, newIndentLevel)}`
201
- : html`
202
- ${Object.keys(data).map((dataKey) =>
203
- dataKey.startsWith('::') && data[dataKey]['::type'] !== 'array' && data[dataKey]['::type'] !== 'object' ? ''
204
- : html`${this.generateTree(data[dataKey]['::type'] === 'array' ? data[dataKey]['::props'] : data[dataKey],
205
- data[dataKey]['::type'], dataKey, data[dataKey]['::description'], newSchemaLevel, newIndentLevel)}`
206
- )}`
207
- }
208
- </div>
209
- ${data['::type'] && data['::type'].includes('xxx-of')
210
- ? ''
211
- : html`<div class='close-bracket'> ${closeBracket} </div>`
212
- }
213
- `;
214
- }
215
-
216
- // For Primitive Data types
217
- const { type, readOrWriteOnly, constraint, defaultValue, allowedValues, pattern, schemaDescription, schemaTitle, deprecated } = JSON.parse(data);
218
- if (readOrWriteOnly === '🆁' && this.schemaHideReadOnly === 'true') {
219
- return undefined;
220
- }
221
- if (readOrWriteOnly === '🆆' && this.schemaHideWriteOnly === 'true') {
222
- return undefined;
223
- }
224
- const dataTypeCss = type.replace(/┃.*/g, '').replace(/[^a-zA-Z0-9+]/g, '').substring(0, 4).toLowerCase();
225
- return html`
226
- <div class="tr primitive">
227
- <div class="td key ${deprecated ? 'deprecated' : ''}" style='min-width:${minFieldColWidth}px' >
228
- ${keyLabel.endsWith('*')
229
- ? html`<span class="key-label">${keyLabel.substring(0, keyLabel.length - 1)}</span><span style='color:var(--red);'>*</span>:`
230
- : key.startsWith('::OPTION')
231
- ? html`<span class='key-label xxx-of-key'>${keyLabel}</span><span class="xxx-of-descr">${keyDescr}</span>`
232
- : schemaLevel > 0
233
- ? html`<span class="key-label">${keyLabel}:</span>`
234
- : ''
235
- }
236
- <span class="${dataTypeCss}">
237
- ${dataType === 'array' ? `${type}[]` : `${type}`}
238
- </span>
239
- </div>
240
- <div class="td key-descr">
241
- <span class="m-markdown-small" style="font-family: var(--font-mono); vertical-align: middle;" title="${readOrWriteOnly === '🆁' && 'Read only attribute' || readOrWriteOnly === '🆆' && 'Write only attribute' || ''}">
242
- ${unsafeHTML(marked(`${readOrWriteOnly && `${readOrWriteOnly} ` || ''}${dataType === 'array' && description || `${schemaTitle ? `**${schemaTitle}:**` : ''} ${schemaDescription}` || ''}`))}
243
- </span>
244
- ${constraint ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px'><span class='bold-text'>Constraints: </span>${constraint}</div>` : ''}
245
- ${defaultValue ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px'><span class='bold-text'>Default: </span>${defaultValue}</div>` : ''}
246
- ${allowedValues ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px'><span class='bold-text'>Allowed: </span>${allowedValues}</div>` : ''}
247
- ${pattern ? html`<div style='display:inline-block; line-break: anywhere; margin-right:8px'><span class='bold-text'>Pattern: </span>${pattern}</div>` : ''}
248
- </div>
249
- </div>
250
- `;
251
- }
252
- /* eslint-enable indent */
253
-
254
- toggleObjectExpand(e) {
255
- const rowEl = e.target.closest('.tr');
256
- if (rowEl.classList.contains('expanded')) {
257
- rowEl.classList.replace('expanded', 'collapsed');
258
- e.target.innerHTML = e.target.classList.contains('array-of-object')
259
- ? '[{...}]'
260
- : e.target.classList.contains('array-of-array')
261
- ? '[[...]]'
262
- : e.target.classList.contains('array')
263
- ? '[...]'
264
- : '{...}';
265
- } else {
266
- rowEl.classList.replace('collapsed', 'expanded');
267
- e.target.innerHTML = e.target.classList.contains('array-of-object')
268
- ? '[{'
269
- : e.target.classList.contains('array-of-array')
270
- ? '[['
271
- : e.target.classList.contains('object')
272
- ? '{'
273
- : '[';
274
- }
275
- }
276
- }
277
-
278
- if (!customElements.get('openapi-explorer')) {
279
- customElements.define('schema-tree', SchemaTree);
280
- }
@@ -1,109 +0,0 @@
1
- import { LitElement, html, css } from 'lit-element';
2
-
3
- export default class TagInput extends LitElement {
4
- render() {
5
- const tagItemTemplate = html`${
6
- (this.value || []).filter(v => v.trim()).map((v) => html`<span class='tag'>${v}</span>`)
7
- }`;
8
- return html`
9
- <div class='tags' tabindex="0">
10
- ${tagItemTemplate}
11
- <input type="text" class='editor' @paste="${(e) => this.afterPaste(e)}" @keydown="${this.afterKeyDown}" placeholder="${this.placeholder || ''}">
12
- </div>
13
- `;
14
- }
15
-
16
- static get properties() {
17
- return {
18
- placeholder: { type: String },
19
- value: { type: Array, attribute: 'value' },
20
- };
21
- }
22
-
23
- connectedCallback() {
24
- super.connectedCallback();
25
- if (!Array.isArray(this.value)) {
26
- this.value = this.value !== '' ? [this.value] : [];
27
- }
28
- }
29
-
30
- attributeChangedCallback(name, oldVal, newVal) {
31
- if (name === 'value') {
32
- if (newVal && oldVal !== newVal) {
33
- this.value = newVal.split(',').filter(v => v.trim());
34
- }
35
- }
36
- super.attributeChangedCallback(name, oldVal, newVal);
37
- }
38
-
39
- afterPaste(e) {
40
- const clipboardData = e.clipboardData || window.clipboardData;
41
- const pastedData = clipboardData.getData('Text');
42
- const pastedArray = pastedData && pastedData.split(',').filter(v => v.trim()) || [];
43
- this.value = this.value.concat(pastedArray);
44
- e.preventDefault();
45
- }
46
-
47
- afterKeyDown(e) {
48
- if (e.keyCode === 13) {
49
- e.stopPropagation();
50
- e.preventDefault();
51
- this.value = this.value.concat(e.target.value || []);
52
- e.target.value = '';
53
- } else if (e.keyCode === 8) {
54
- if (e.target.value.length === 0) {
55
- this.value = this.value.slice(0, -1);
56
- }
57
- }
58
- }
59
-
60
- static get styles() {
61
- return [css`
62
- .tags{
63
- display:flex;
64
- flex-wrap: wrap;
65
- outline: none;
66
- padding:0;
67
- border-radius:var(--border-radius);
68
- border:1px solid var(--border-color);
69
- cursor:text;
70
- overflow:hidden;
71
- background:var(--input-bg);
72
- }
73
- .tag, .editor {
74
- padding:3px;
75
- margin:2px;
76
- }
77
- .tag{
78
- border:1px solid var(--border-color);
79
- background-color:var(--bg3);
80
- color:var(--fg3);
81
- border-radius:var(--border-radius);
82
- word-break: break-all;
83
- font-size: var(--font-size-small);
84
- }
85
- .tag:hover ~ #cursor {
86
- display: block;
87
- }
88
- .editor{
89
- flex:1;
90
- border:1px solid transparent;
91
- color:var(--fg);
92
- min-width:60px;
93
- outline: none;
94
- line-height: inherit;
95
- font-family:inherit;
96
- background:transparent;
97
- font-size: calc(var(--font-size-small) + 1px);
98
- }
99
- .editor::placeholder {
100
- color: var(--placeholder-color);
101
- opacity:1;
102
- }
103
- `];
104
- }
105
- }
106
- // Register the element with the browser
107
- if (!customElements.get('openapi-explorer')) {
108
- customElements.define('tag-input', TagInput);
109
- }