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,11 +1,10 @@
1
1
  import OpenApiResolver from 'openapi-resolver/dist/openapi-resolver.browser';
2
2
  import { marked } from 'marked';
3
3
  import { invalidCharsRegEx } from './common-utils';
4
-
5
4
  export default async function ProcessSpec(specUrlOrObject, serverUrl = '') {
6
5
  const inputSpecIsAUrl = typeof specUrlOrObject === 'string' && specUrlOrObject.match(/^http/) || typeof specUrlOrObject === 'object' && typeof specUrlOrObject.href === 'string';
7
-
8
6
  let jsonParsedSpec;
7
+
9
8
  try {
10
9
  jsonParsedSpec = await OpenApiResolver(specUrlOrObject);
11
10
  } catch (error) {
@@ -16,24 +15,26 @@ export default async function ProcessSpec(specUrlOrObject, serverUrl = '') {
16
15
 
17
16
  if (!jsonParsedSpec) {
18
17
  throw Error('SpecificationNotFound');
19
- }
18
+ } // Tags with Paths and WebHooks
20
19
 
21
- // Tags with Paths and WebHooks
22
- const tags = groupByTags(jsonParsedSpec);
23
20
 
24
- // Components
25
- const components = getComponents(jsonParsedSpec);
21
+ const tags = groupByTags(jsonParsedSpec); // Components
26
22
 
27
- // Info Description Headers
28
- const infoDescriptionHeaders = (jsonParsedSpec.info && jsonParsedSpec.info.description) ? getHeadersFromMarkdown(jsonParsedSpec.info.description) : [];
23
+ const components = getComponents(jsonParsedSpec); // Info Description Headers
24
+
25
+ const infoDescriptionHeaders = jsonParsedSpec.info && jsonParsedSpec.info.description ? getHeadersFromMarkdown(jsonParsedSpec.info.description) : []; // Security Scheme
29
26
 
30
- // Security Scheme
31
27
  const securitySchemes = [];
28
+
32
29
  if (jsonParsedSpec.components && jsonParsedSpec.components.securitySchemes) {
33
- Object.entries(jsonParsedSpec.components.securitySchemes).forEach((kv) => {
34
- const securityObj = { apiKeyId: kv[0], ...kv[1] };
30
+ Object.entries(jsonParsedSpec.components.securitySchemes).forEach(kv => {
31
+ const securityObj = {
32
+ apiKeyId: kv[0],
33
+ ...kv[1]
34
+ };
35
35
  securityObj.value = '';
36
36
  securityObj.finalKeyValue = '';
37
+
37
38
  if (kv[1].type === 'apiKey' || kv[1].type === 'http') {
38
39
  securityObj.name = kv[1].name || 'Authorization';
39
40
  securityObj.user = '';
@@ -43,12 +44,13 @@ export default async function ProcessSpec(specUrlOrObject, serverUrl = '') {
43
44
  securityObj.clientId = '';
44
45
  securityObj.clientSecret = '';
45
46
  }
47
+
46
48
  securitySchemes.push(securityObj);
47
49
  });
48
- }
50
+ } // Updated Security Type Display Text based on Type
49
51
 
50
- // Updated Security Type Display Text based on Type
51
- securitySchemes.forEach((v) => {
52
+
53
+ securitySchemes.forEach(v => {
52
54
  if (v.type === 'http') {
53
55
  v.typeDisplay = v.scheme === 'basic' ? 'HTTP Basic' : 'HTTP Bearer';
54
56
  } else if (v.type === 'apiKey') {
@@ -58,41 +60,61 @@ export default async function ProcessSpec(specUrlOrObject, serverUrl = '') {
58
60
  } else {
59
61
  v.typeDisplay = v.type;
60
62
  }
61
- });
63
+ }); // Servers
62
64
 
63
- // Servers
64
65
  let servers = [];
66
+
65
67
  if (Array.isArray(jsonParsedSpec.servers) && jsonParsedSpec.servers.length) {
66
- jsonParsedSpec.servers.forEach((v) => {
68
+ jsonParsedSpec.servers.forEach(v => {
67
69
  let computedUrl = v.url.trim();
70
+
68
71
  if (!(computedUrl.startsWith('http') || computedUrl.startsWith('//') || computedUrl.startsWith('{'))) {
69
72
  if (window.location.origin.startsWith('http')) {
70
73
  v.url = window.location.origin + v.url;
71
74
  computedUrl = v.url;
72
75
  }
73
- }
74
- // Apply server-variables to generate final computed-url
76
+ } // Apply server-variables to generate final computed-url
77
+
78
+
75
79
  if (v.variables) {
76
- Object.entries(v.variables).forEach((kv) => {
80
+ Object.entries(v.variables).forEach(kv => {
77
81
  const regex = new RegExp(`{${kv[0]}}`, 'g');
78
82
  computedUrl = computedUrl.replace(regex, kv[1].default || '');
79
83
  kv[1].value = kv[1].default || '';
80
84
  });
81
85
  }
86
+
82
87
  v.computedUrl = computedUrl;
83
88
  });
89
+
84
90
  if (serverUrl && !jsonParsedSpec.servers.some(s => s.url === serverUrl || s.computedUrl === serverUrl)) {
85
- jsonParsedSpec.servers.push({ url: serverUrl, computedUrl: serverUrl });
91
+ jsonParsedSpec.servers.push({
92
+ url: serverUrl,
93
+ computedUrl: serverUrl
94
+ });
86
95
  }
87
96
  } else if (serverUrl) {
88
- jsonParsedSpec.servers = [{ url: serverUrl, computedUrl: serverUrl }];
97
+ jsonParsedSpec.servers = [{
98
+ url: serverUrl,
99
+ computedUrl: serverUrl
100
+ }];
89
101
  } else if (inputSpecIsAUrl) {
90
- jsonParsedSpec.servers = [{ url: new URL(specUrlOrObject).origin, computedUrl: new URL(specUrlOrObject).origin }];
102
+ jsonParsedSpec.servers = [{
103
+ url: new URL(specUrlOrObject).origin,
104
+ computedUrl: new URL(specUrlOrObject).origin
105
+ }];
91
106
  } else if (window.location.origin.startsWith('http')) {
92
- jsonParsedSpec.servers = [{ url: window.location.origin, computedUrl: window.location.origin }];
107
+ jsonParsedSpec.servers = [{
108
+ url: window.location.origin,
109
+ computedUrl: window.location.origin
110
+ }];
93
111
  } else {
94
- jsonParsedSpec.servers = [{ url: 'http://localhost', computedUrl: 'http://localhost' }];
112
+ jsonParsedSpec.servers = [{
113
+ url: 'http://localhost',
114
+ computedUrl: 'http://localhost'
115
+ }];
95
116
  }
117
+
96
118
  servers = jsonParsedSpec.servers;
97
119
  const parsedSpec = {
98
120
  info: jsonParsedSpec.info,
@@ -102,14 +124,14 @@ export default async function ProcessSpec(specUrlOrObject, serverUrl = '') {
102
124
  // pathGroups,
103
125
  externalDocs: jsonParsedSpec.externalDocs,
104
126
  securitySchemes,
105
- servers,
127
+ servers
106
128
  };
107
129
  return parsedSpec;
108
130
  }
109
131
 
110
132
  function getHeadersFromMarkdown(markdownContent) {
111
133
  const tokens = marked.lexer(markdownContent);
112
- const headers = tokens.filter((v) => v.type === 'heading' && v.depth <= 2);
134
+ const headers = tokens.filter(v => v.type === 'heading' && v.depth <= 2);
113
135
  return headers || [];
114
136
  }
115
137
 
@@ -117,15 +139,16 @@ function getComponents(openApiSpec) {
117
139
  if (!openApiSpec.components) {
118
140
  return [];
119
141
  }
142
+
120
143
  const components = [];
144
+
121
145
  for (const component in openApiSpec.components) {
122
146
  const subComponents = Object.keys(openApiSpec.components[component]).map(sComponent => ({
123
147
  expanded: true,
124
148
  id: `${component.toLowerCase()}-${sComponent.toLowerCase()}`.replace(invalidCharsRegEx, '-'),
125
149
  name: sComponent,
126
- component: openApiSpec.components[component][sComponent],
150
+ component: openApiSpec.components[component][sComponent]
127
151
  })).sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
128
-
129
152
  let cmpDescription;
130
153
  let cmpName;
131
154
 
@@ -134,35 +157,44 @@ function getComponents(openApiSpec) {
134
157
  cmpName = 'Schemas';
135
158
  cmpDescription = '';
136
159
  break;
160
+
137
161
  case 'responses':
138
162
  cmpName = 'Responses';
139
163
  cmpDescription = 'Describes responses from an API Operation, including design-time, static links to operations based on the response.';
140
164
  break;
165
+
141
166
  case 'parameters':
142
167
  cmpName = 'Parameters';
143
168
  cmpDescription = 'Describes operation parameters. A unique parameter is defined by a combination of a name and location.';
144
169
  break;
170
+
145
171
  case 'examples':
146
172
  cmpName = 'Examples';
147
173
  cmpDescription = 'List of Examples for operations, can be requests, responses and objects examples.';
148
174
  break;
175
+
149
176
  case 'requestBodies':
150
177
  break;
178
+
151
179
  case 'headers':
152
180
  cmpName = 'Headers';
153
181
  cmpDescription = 'Headers follows the structure of the Parameters but they are explicitly in "header"';
154
182
  break;
183
+
155
184
  case 'securitySchemes':
156
185
  break;
186
+
157
187
  case 'links':
158
188
  cmpName = 'Links';
159
189
  cmpDescription = 'Links represent a possible design-time link for a response. The presence of a link does not guarantee the caller\'s ability to successfully invoke it, rather it provides a known relationship and traversal mechanism between responses and other operations.';
160
190
  break;
191
+
161
192
  case 'callbacks':
162
- cmpName = 'Callbacks';
163
- // eslint-disable-next-line max-len
193
+ cmpName = 'Callbacks'; // eslint-disable-next-line max-len
194
+
164
195
  cmpDescription = 'A map of possible out-of band callbacks related to the parent operation. Each value in the map is a Path Item Object that describes a set of requests that may be initiated by the API provider and the expected responses. The key value used to identify the path item object is an expression, evaluated at runtime, that identifies a URL to use for the callback operation.';
165
196
  break;
197
+
166
198
  default:
167
199
  cmpName = component;
168
200
  cmpDescription = component;
@@ -174,7 +206,7 @@ function getComponents(openApiSpec) {
174
206
  show: true,
175
207
  name: cmpName,
176
208
  description: cmpDescription,
177
- subComponents,
209
+ subComponents
178
210
  });
179
211
  }
180
212
  }
@@ -184,51 +216,55 @@ function getComponents(openApiSpec) {
184
216
 
185
217
  function groupByTags(openApiSpec) {
186
218
  const supportedMethods = ['get', 'put', 'post', 'delete', 'patch', 'head', 'options']; // this is also used for ordering endpoints by methods
187
- const tags = openApiSpec.tags && Array.isArray(openApiSpec.tags)
188
- ? openApiSpec.tags.map((t) => ({
189
- show: true,
190
- elementId: `tag--${t.name.replace(invalidCharsRegEx, '-')}`,
191
- name: t.name,
192
- description: t.description || '',
193
- headers: t.description ? getHeadersFromMarkdown(t.description) : [],
194
- paths: [],
195
- expanded: t['x-tag-expanded'] !== false,
196
- }))
197
- : [];
198
219
 
220
+ const tags = openApiSpec.tags && Array.isArray(openApiSpec.tags) ? openApiSpec.tags.map(t => ({
221
+ show: true,
222
+ elementId: `tag--${t.name.replace(invalidCharsRegEx, '-')}`,
223
+ name: t.name,
224
+ description: t.description || '',
225
+ headers: t.description ? getHeadersFromMarkdown(t.description) : [],
226
+ paths: [],
227
+ expanded: t['x-tag-expanded'] !== false
228
+ })) : [];
199
229
  const pathsAndWebhooks = openApiSpec.paths || {};
230
+
200
231
  if (openApiSpec.webhooks) {
201
232
  for (const [key, value] of Object.entries(openApiSpec.webhooks)) {
202
233
  value._type = 'webhook'; // eslint-disable-line no-underscore-dangle
234
+
203
235
  pathsAndWebhooks[key] = value;
204
236
  }
205
- }
206
- // For each path find the tag and push it into the corresponding tag
237
+ } // For each path find the tag and push it into the corresponding tag
238
+
239
+
207
240
  for (const pathOrHookName in pathsAndWebhooks) {
208
241
  const commonParams = pathsAndWebhooks[pathOrHookName].parameters;
209
242
  const commonPathProp = {
210
243
  servers: pathsAndWebhooks[pathOrHookName].servers || [],
211
- parameters: pathsAndWebhooks[pathOrHookName].parameters || [],
244
+ parameters: pathsAndWebhooks[pathOrHookName].parameters || []
212
245
  };
213
246
  const isWebhook = pathsAndWebhooks[pathOrHookName]._type === 'webhook'; // eslint-disable-line no-underscore-dangle
214
- supportedMethods.forEach((methodName) => {
247
+
248
+ supportedMethods.forEach(methodName => {
215
249
  if (pathsAndWebhooks[pathOrHookName][methodName]) {
216
- const pathOrHookObj = openApiSpec.paths[pathOrHookName][methodName];
217
- // If path.methods are tagged, else generate it from path
250
+ const pathOrHookObj = openApiSpec.paths[pathOrHookName][methodName]; // If path.methods are tagged, else generate it from path
251
+
218
252
  const pathTags = Array.isArray(pathOrHookObj.tags) ? pathOrHookObj.tags : pathOrHookObj.tags && [pathOrHookObj.tags] || [];
253
+
219
254
  if (pathTags.length === 0) {
220
255
  pathTags.push('General ⦂');
221
256
  }
222
257
 
223
- pathTags.forEach((tag) => {
258
+ pathTags.forEach(tag => {
224
259
  let tagObj;
225
260
  let specTagsItem;
226
261
 
227
262
  if (openApiSpec.tags) {
228
- specTagsItem = openApiSpec.tags.find((v) => (v.name.toLowerCase() === tag.toLowerCase()));
263
+ specTagsItem = openApiSpec.tags.find(v => v.name.toLowerCase() === tag.toLowerCase());
229
264
  }
230
265
 
231
- tagObj = tags.find((v) => v.name === tag);
266
+ tagObj = tags.find(v => v.name === tag);
267
+
232
268
  if (!tagObj) {
233
269
  tagObj = {
234
270
  show: true,
@@ -237,24 +273,28 @@ function groupByTags(openApiSpec) {
237
273
  description: specTagsItem && specTagsItem.description || '',
238
274
  headers: specTagsItem && specTagsItem.description ? getHeadersFromMarkdown(specTagsItem.description) : [],
239
275
  paths: [],
240
- expanded: (specTagsItem ? specTagsItem['x-tag-expanded'] !== false : true),
276
+ expanded: specTagsItem ? specTagsItem['x-tag-expanded'] !== false : true
241
277
  };
242
278
  tags.push(tagObj);
243
- }
279
+ } // Generate a short summary which is broken
280
+
244
281
 
245
- // Generate a short summary which is broken
246
282
  let shortSummary = (pathOrHookObj.summary || pathOrHookObj.description || `${methodName.toUpperCase()} ${pathOrHookName}`).trim();
283
+
247
284
  if (shortSummary.length > 100) {
248
285
  shortSummary = shortSummary.split(/[.|!|?]\s|[\r?\n]/)[0]; // take the first line (period or carriage return)
249
- }
250
- // Merge Common Parameters with This methods parameters
286
+ } // Merge Common Parameters with This methods parameters
287
+
288
+
251
289
  let finalParameters = [];
290
+
252
291
  if (commonParams) {
253
292
  if (pathOrHookObj.parameters) {
254
- finalParameters = commonParams.filter((commonParam) => {
255
- if (!pathOrHookObj.parameters.some((param) => (commonParam.name === param.name && commonParam.in === param.in))) {
293
+ finalParameters = commonParams.filter(commonParam => {
294
+ if (!pathOrHookObj.parameters.some(param => commonParam.name === param.name && commonParam.in === param.in)) {
256
295
  return commonParam;
257
296
  }
297
+
258
298
  return undefined;
259
299
  }).concat(pathOrHookObj.parameters);
260
300
  } else {
@@ -262,28 +302,29 @@ function groupByTags(openApiSpec) {
262
302
  }
263
303
  } else {
264
304
  finalParameters = pathOrHookObj.parameters ? pathOrHookObj.parameters.slice(0) : [];
265
- }
305
+ } // Remove bad callbacks
306
+
266
307
 
267
- // Remove bad callbacks
268
308
  if (pathOrHookObj.callbacks) {
269
309
  for (const [callbackName, callbackConfig] of Object.entries(pathOrHookObj.callbacks)) {
270
310
  const originalCallbackEntries = Object.entries(callbackConfig);
271
- const filteredCallbacks = originalCallbackEntries.filter((entry) => typeof entry[1] === 'object') || [];
311
+ const filteredCallbacks = originalCallbackEntries.filter(entry => typeof entry[1] === 'object') || [];
272
312
  pathOrHookObj.callbacks[callbackName] = Object.fromEntries(filteredCallbacks);
313
+
273
314
  if (filteredCallbacks.length !== originalCallbackEntries.length) {
274
315
  console.warn(`OpenAPI Explorer: Invalid Callback found in ${callbackName}`); // eslint-disable-line no-console
275
316
  }
276
317
  }
277
- }
318
+ } // Update Responses
319
+
278
320
 
279
- // Update Responses
280
321
  tagObj.paths.push({
281
322
  show: true,
282
323
  expanded: false,
283
324
  isWebhook,
284
325
  expandedAtLeastOnce: false,
285
- summary: (pathOrHookObj.summary || ''),
286
- description: (pathOrHookObj.description || ''),
326
+ summary: pathOrHookObj.summary || '',
327
+ description: pathOrHookObj.description || '',
287
328
  shortSummary,
288
329
  method: methodName,
289
330
  path: pathOrHookName,
@@ -298,12 +339,12 @@ function groupByTags(openApiSpec) {
298
339
  security: pathOrHookObj.security,
299
340
  // commonSummary: commonPathProp.summary,
300
341
  // commonDescription: commonPathProp.description,
301
- xCodeSamples: pathOrHookObj['x-codeSamples'] || pathOrHookObj['x-code-samples'] || '',
342
+ xCodeSamples: pathOrHookObj['x-codeSamples'] || pathOrHookObj['x-code-samples'] || ''
302
343
  });
303
- });// End of tag path create
344
+ }); // End of tag path create
304
345
  }
305
346
  }); // End of Methods
306
347
  }
307
348
 
308
- return tags.filter((tag) => tag.paths && tag.paths.length > 0);
309
- }
349
+ return tags.filter(tag => tag.paths && tag.paths.length > 0);
350
+ }
@@ -0,0 +1,75 @@
1
+ import { html } from 'lit-element';
2
+ import color from 'color';
3
+ import ColorUtils from './color-utils';
4
+ /* Generates an schema object containing type and constraint info */
5
+ // TODO: possible drive theme from:
6
+
7
+ /*
8
+ if (!this.theme || !'light, dark,'.includes(`${this.theme},`)) {
9
+ this.theme = (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) ? 'light' : 'dark';
10
+ }
11
+ */
12
+
13
+ export default function setTheme(theme = {}) {
14
+ const bg1 = theme.bg1 ? theme.bg1 : '#ffffff';
15
+ const fg1 = theme.fg1 ? theme.fg1 : '#444444';
16
+ const bg2 = theme.bg2 ? theme.bg2 : ColorUtils.color.brightness(bg1, -5); // or '#fafafa'
17
+
18
+ const bg3 = theme.bg3 ? theme.bg3 : ColorUtils.color.brightness(bg1, -15); // or '#f6f6f6'
19
+
20
+ const lightBg = theme.bg3 ? theme.bg3 : ColorUtils.color.brightness(bg1, -45);
21
+ const fg2 = theme.fg2 ? theme.fg2 : ColorUtils.color.brightness(fg1, 17); // or '#555'
22
+
23
+ const fg3 = theme.fg3 ? theme.fg3 : ColorUtils.color.brightness(fg1, 30); // or #666
24
+
25
+ const lightFg = theme.fg3 ? theme.fg3 : ColorUtils.color.brightness(fg1, 70); // or #999
26
+
27
+ const inlineCodeFg = theme.inlineCodeFg ? theme.inlineCodeFg : 'brown';
28
+ const selectionBg = '#444';
29
+ const selectionFg = '#eee';
30
+ const headerColor = theme.headerColor ? theme.headerColor : ColorUtils.color.brightness(bg1, -180);
31
+ const navBgColor = theme.navBgColor ? theme.navBgColor : ColorUtils.color.brightness(bg1, -180);
32
+ const navTextColor = theme.navTextColor ? theme.navTextColor : ColorUtils.color.opacity(ColorUtils.color.invert(navBgColor), '0.65');
33
+ const navHoverBgColor = theme.navHoverBgColor ? theme.navHoverBgColor : ColorUtils.color.brightness(navBgColor, -15);
34
+ const navHoverTextColor = theme.navHoverTextColor ? theme.navHoverTextColor : ColorUtils.color.invert(navBgColor);
35
+ const overlayBg = 'rgba(0, 0, 0, 0.4)';
36
+ const defaultColors = [`--purple: ${getComputedStyle(this).getPropertyValue('--purple').trim() || '#6f42c1'}`, `--red: ${getComputedStyle(this).getPropertyValue('--red').trim() || '#dc3545'}`, `--orange: ${getComputedStyle(this).getPropertyValue('--orange').trim() || '#fd7e14'}`, `--yellow: ${getComputedStyle(this).getPropertyValue('--yellow').trim() || '#ffc107'}`, `--green: ${getComputedStyle(this).getPropertyValue('--green').trim() || '#28a745'}`, `--blue: ${getComputedStyle(this).getPropertyValue('--blue').trim() || '#38b3f9'}`, '--pink: #e83e8c', '--white: #fff', ''];
37
+ const lightColors = [`--light-purple: ${color(getComputedStyle(this).getPropertyValue('--purple').trim() || '#6f42c1').lightness(96).hex()}`, `--light-red: ${color(getComputedStyle(this).getPropertyValue('--red').trim() || '#dc3545').lightness(96).hex()}`, `--light-orange: ${color(getComputedStyle(this).getPropertyValue('--orange').trim() || '#fd7e14').lightness(96).hex()}`, `--light-yellow: ${color(getComputedStyle(this).getPropertyValue('--yellow').trim() || '#ffc107').lightness(96).hex()}`, `--light-green: ${color(getComputedStyle(this).getPropertyValue('--green').trim() || '#28a745').lightness(96).hex()}`, `--light-blue: ${color(getComputedStyle(this).getPropertyValue('--blue').trim() || '#38b3f9').lightness(96).hex()}`, ''];
38
+ const newTheme = {
39
+ bg1,
40
+ bg2,
41
+ bg3,
42
+ lightBg,
43
+ fg1,
44
+ fg2,
45
+ fg3,
46
+ lightFg,
47
+ inlineCodeFg,
48
+ selectionBg,
49
+ selectionFg,
50
+ overlayBg,
51
+ navBgColor,
52
+ navTextColor,
53
+ navHoverBgColor,
54
+ navHoverTextColor,
55
+ headerColor,
56
+ headerColorInvert: ColorUtils.color.invert(headerColor),
57
+ headerColorDarker: ColorUtils.color.brightness(headerColor, -20),
58
+ headerColorBorder: ColorUtils.color.brightness(headerColor, 10),
59
+ borderColor: theme.borderColor || ColorUtils.color.brightness(bg1, -38),
60
+ lightBorderColor: theme.lightBorderColor || ColorUtils.color.brightness(bg1, -23),
61
+ codeBorderColor: theme.codeBorderColor || 'transparent',
62
+ inputBg: theme.inputBg || ColorUtils.color.brightness(bg1, 10),
63
+ // #fff
64
+ placeHolder: theme.placeHolder || ColorUtils.color.brightness(lightFg, 20),
65
+ // #dedede
66
+ hoverColor: theme.hoverColor || ColorUtils.color.brightness(bg1, -5),
67
+ // # f1f1f1
68
+ codeBg: theme.codeBg || ColorUtils.color.opacity(ColorUtils.color.brightness(bg1, -15), 0.7),
69
+ codeFg: theme.codeFg || '#666',
70
+ codePropertyColor: theme.codePropertyColor || '#905',
71
+ codeKeywordColor: theme.codeKeywordColor || '#07a',
72
+ codeOperatorColor: theme.codeOperatorColor || '#9a6e3a'
73
+ };
74
+ return html` <style>*,:after,:before{box-sizing:border-box}:host{--border-radius:2px;--layout:${this.layout || 'column'};--nav-item-padding:${this.navItemSpacing === 'relaxed' ? '10px' : this.navItemSpacing === 'compact' ? '5px 10px' : '7px 10px'};--resp-area-height:${this.responseAreaHeight};--font-size-small:${this.fontSize === 'default' ? '12px' : this.fontSize === 'large' ? '13px' : '14px'};--font-size-mono:${this.fontSize === 'default' ? '13px' : this.fontSize === 'large' ? '14px' : '15px'};--font-size-regular:${this.fontSize === 'default' ? '14px' : this.fontSize === 'large' ? '15px' : '16px'};--dialog-z-index:1000;--bg:${newTheme.bg1};--bg2:${newTheme.bg2};--bg3:${newTheme.bg3};--light-bg:${newTheme.lightBg};--fg:${newTheme.fg1};--fg2:${newTheme.fg2};--fg3:${newTheme.fg3};--light-fg:${newTheme.lightFg};--selection-bg:${newTheme.selectionBg};--selection-fg:${newTheme.selectionFg};--overlay-bg:${newTheme.overlayBg};--border-color:${newTheme.borderColor};--light-border-color:${newTheme.lightBorderColor};--code-border-color:${newTheme.codeBorderColor};--input-bg:${newTheme.inputBg};--placeholder-color:${newTheme.placeHolder};--hover-color:${newTheme.hoverColor};${defaultColors.join(';\n')} ${lightColors.join(';\n')} --header-bg:${newTheme.headerColor};--header-fg:${newTheme.headerColorInvert};--header-color-darker:${newTheme.headerColorDarker};--header-color-border:${newTheme.headerColorBorder};--nav-bg-color:${newTheme.navBgColor};--nav-text-color:${newTheme.navTextColor};--nav-hover-bg-color:${newTheme.navHoverBgColor};--nav-hover-text-color:${newTheme.navHoverTextColor};--code-bg:${newTheme.codeBg};--code-fg:${newTheme.codeFg};--inline-code-fg:${newTheme.inlineCodeFg};--code-property-color:${newTheme.codePropertyColor};--code-keyword-color:${newTheme.codeKeywordColor};--code-operator-color:${newTheme.codeOperatorColor};--primary-color:${theme.primaryColor};--secondary-color:${theme.secondaryColor};--primary-btn-text-color:${ColorUtils.color.selectTextColorFromBackground(theme.primaryColor)}}</style>`;
75
+ }
@@ -1,5 +1,4 @@
1
1
  /* eslint-disable no-underscore-dangle */
2
-
3
2
  const XML_CHARACTER_MAP = {
4
3
  '&': '&amp;',
5
4
  '"': '&quot;',
@@ -9,17 +8,15 @@ const XML_CHARACTER_MAP = {
9
8
  };
10
9
 
11
10
  function escapeForXML(string) {
12
- return string && string.replace
13
- ? string.replace(/([&"<>'])/g, function(str, item) {
14
- return XML_CHARACTER_MAP[item];
15
- })
16
- : string;
11
+ return string && string.replace ? string.replace(/([&"<>'])/g, function (str, item) {
12
+ return XML_CHARACTER_MAP[item];
13
+ }) : string;
17
14
  }
18
15
 
19
16
  const DEFAULT_INDENT = ' ';
20
-
21
17
  export default function xml(input, rawOptions) {
22
18
  let options = rawOptions;
19
+
23
20
  if (typeof options !== 'object') {
24
21
  options = {
25
22
  indent: options
@@ -27,9 +24,7 @@ export default function xml(input, rawOptions) {
27
24
  }
28
25
 
29
26
  let output = '';
30
- const indent = !options.indent ? ''
31
- : options.indent === true ? DEFAULT_INDENT
32
- : options.indent;
27
+ const indent = !options.indent ? '' : options.indent === true ? DEFAULT_INDENT : options.indent;
33
28
  let instant = true;
34
29
 
35
30
  function delay(func) {
@@ -52,25 +47,34 @@ export default function xml(input, rawOptions) {
52
47
 
53
48
  function addXmlDeclaration(declaration) {
54
49
  const encoding = declaration.encoding || 'UTF-8';
55
- const attr = { version: '1.0', encoding: encoding };
50
+ const attr = {
51
+ version: '1.0',
52
+ encoding: encoding
53
+ };
56
54
 
57
55
  if (declaration.standalone) {
58
56
  attr.standalone = declaration.standalone;
59
57
  }
60
58
 
61
- add({ '?xml': { _attr: attr } });
59
+ add({
60
+ '?xml': {
61
+ _attr: attr
62
+ }
63
+ });
62
64
  output = output.replace('/>', '?>');
63
- }
65
+ } // disable delay delayed
64
66
 
65
- // disable delay delayed
66
- delay(function() { instant = false; });
67
+
68
+ delay(function () {
69
+ instant = false;
70
+ });
67
71
 
68
72
  if (options.declaration) {
69
73
  addXmlDeclaration(options.declaration);
70
74
  }
71
75
 
72
76
  if (input && input.forEach) {
73
- input.forEach(function(value, i) {
77
+ input.forEach(function (value, i) {
74
78
  add(value, i + 1 === input.length);
75
79
  });
76
80
  } else {
@@ -81,7 +85,7 @@ export default function xml(input, rawOptions) {
81
85
  }
82
86
 
83
87
  function create_indent(character, count) {
84
- return (new Array(count || 0).join(character || ''));
88
+ return new Array(count || 0).join(character || '');
85
89
  }
86
90
 
87
91
  function resolve(data, indent, indent_count_raw) {
@@ -108,42 +112,40 @@ function resolve(data, indent, indent_count_raw) {
108
112
 
109
113
  const attributes = [];
110
114
  const content = [];
111
-
112
115
  let isStringContent;
113
116
 
114
117
  function get_attributes(obj) {
115
118
  const keys = Object.keys(obj);
116
- keys.forEach(function(key) {
119
+ keys.forEach(function (key) {
117
120
  attributes.push(attribute(key, obj[key]));
118
121
  });
119
122
  }
120
123
 
121
124
  switch (typeof values) {
122
125
  case 'object':
123
- if (values === null) {break;}
126
+ if (values === null) {
127
+ break;
128
+ }
124
129
 
125
130
  if (values._attr) {
126
131
  get_attributes(values._attr);
127
132
  }
128
133
 
129
134
  if (values._cdata) {
130
- content.push(
131
- `${(`<![CDATA[${values._cdata}`).replace(/\]\]>/g, ']]]]><![CDATA[>')}]]>`
132
- );
135
+ content.push(`${`<![CDATA[${values._cdata}`.replace(/\]\]>/g, ']]]]><![CDATA[>')}]]>`);
133
136
  }
134
137
 
135
138
  if (values.forEach) {
136
139
  isStringContent = false;
137
140
  content.push('');
138
- values.forEach(function(value) {
141
+ values.forEach(function (value) {
139
142
  if (typeof value === 'object') {
140
143
  const _name = Object.keys(value)[0];
141
144
 
142
145
  if (_name === '_attr') {
143
146
  get_attributes(value._attr);
144
147
  } else {
145
- content.push(resolve(
146
- value, indent, indent_count + 1));
148
+ content.push(resolve(value, indent, indent_count + 1));
147
149
  }
148
150
  } else {
149
151
  // string
@@ -152,10 +154,12 @@ function resolve(data, indent, indent_count_raw) {
152
154
  content.push(escapeForXML(value));
153
155
  }
154
156
  });
157
+
155
158
  if (!isStringContent) {
156
159
  content.push('');
157
160
  }
158
161
  }
162
+
159
163
  break;
160
164
 
161
165
  default:
@@ -186,15 +190,18 @@ function format(append, elem, end) {
186
190
  while (elem.content.length) {
187
191
  const value = elem.content.shift();
188
192
 
189
- if (value === undefined) {continue;}
190
- if (interrupt(value)) {return;}
193
+ if (value === undefined) {
194
+ continue;
195
+ }
196
+
197
+ if (interrupt(value)) {
198
+ return;
199
+ }
191
200
 
192
201
  format(append, value);
193
202
  }
194
203
 
195
- append(false, (len > 1 ? elem.indents : '')
196
- + (elem.name ? `</${elem.name}>` : '')
197
- + (elem.indent && !end ? '\n' : ''));
204
+ append(false, (len > 1 ? elem.indents : '') + (elem.name ? `</${elem.name}>` : '') + (elem.indent && !end ? '\n' : ''));
198
205
  }
199
206
 
200
207
  function interrupt(value) {
@@ -205,14 +212,11 @@ function format(append, elem, end) {
205
212
  append(true);
206
213
  return true;
207
214
  }
215
+
208
216
  return false;
209
217
  }
210
218
 
211
- append(false, elem.indents
212
- + (elem.name ? `<${elem.name}` : '')
213
- + (elem.attributes.length ? ` ${elem.attributes.join(' ')}` : '')
214
- + (len ? (elem.name ? '>' : '') : (elem.name ? '/>' : ''))
215
- + (elem.indent && len > 1 ? '\n' : ''));
219
+ append(false, elem.indents + (elem.name ? `<${elem.name}` : '') + (elem.attributes.length ? ` ${elem.attributes.join(' ')}` : '') + (len ? elem.name ? '>' : '' : elem.name ? '/>' : '') + (elem.indent && len > 1 ? '\n' : ''));
216
220
 
217
221
  if (!len) {
218
222
  append(false, elem.indent ? '\n' : '');
@@ -226,5 +230,4 @@ function format(append, elem, end) {
226
230
 
227
231
  function attribute(key, value) {
228
232
  return `${key}=` + `"${escapeForXML(value)}"`;
229
- }
230
-
233
+ }