@stoplight/elements 8.3.3 → 8.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var elementsCore = require('@stoplight/elements-core');
6
4
  var mosaic = require('@stoplight/mosaic');
7
5
  var types = require('@stoplight/types');
@@ -21,645 +19,652 @@ var get = require('lodash/get.js');
21
19
  var isObject = require('lodash/isObject.js');
22
20
  var last = require('lodash/last.js');
23
21
 
24
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
25
-
26
- function _interopNamespace(e) {
27
- if (e && e.__esModule) return e;
28
- var n = Object.create(null);
29
- if (e) {
30
- Object.keys(e).forEach(function (k) {
31
- if (k !== 'default') {
32
- var d = Object.getOwnPropertyDescriptor(e, k);
33
- Object.defineProperty(n, k, d.get ? d : {
34
- enumerable: true,
35
- get: function () { return e[k]; }
22
+ function _interopNamespaceDefault(e) {
23
+ var n = Object.create(null);
24
+ if (e) {
25
+ Object.keys(e).forEach(function (k) {
26
+ if (k !== 'default') {
27
+ var d = Object.getOwnPropertyDescriptor(e, k);
28
+ Object.defineProperty(n, k, d.get ? d : {
29
+ enumerable: true,
30
+ get: function () { return e[k]; }
31
+ });
32
+ }
36
33
  });
37
- }
38
- });
39
- }
40
- n["default"] = e;
41
- return Object.freeze(n);
34
+ }
35
+ n.default = e;
36
+ return Object.freeze(n);
42
37
  }
43
38
 
44
- var cn__default = /*#__PURE__*/_interopDefaultLegacy(cn);
45
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
46
- var defaults__default = /*#__PURE__*/_interopDefaultLegacy(defaults);
47
- var flow__default = /*#__PURE__*/_interopDefaultLegacy(flow);
48
- var saver__default = /*#__PURE__*/_interopDefaultLegacy(saver);
49
- var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
50
- var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
51
- var last__default = /*#__PURE__*/_interopDefaultLegacy(last);
39
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
52
40
 
53
- function computeTagGroups(serviceNode, nodeType) {
54
- const groupsByTagId = {};
55
- const ungrouped = [];
56
- const lowerCaseServiceTags = serviceNode.tags.map(tn => tn.toLowerCase());
57
- const groupableNodes = serviceNode.children.filter(n => n.type === nodeType);
58
- for (const node of groupableNodes) {
59
- const tagName = node.tags[0];
60
- if (tagName) {
61
- const tagId = tagName.toLowerCase();
62
- if (groupsByTagId[tagId]) {
63
- groupsByTagId[tagId].items.push(node);
64
- }
65
- else {
66
- const serviceTagIndex = lowerCaseServiceTags.findIndex(tn => tn === tagId);
67
- const serviceTagName = serviceNode.tags[serviceTagIndex];
68
- groupsByTagId[tagId] = {
69
- title: serviceTagName || tagName,
70
- items: [node],
71
- };
72
- }
73
- }
74
- else {
75
- ungrouped.push(node);
76
- }
77
- }
78
- const orderedTagGroups = Object.entries(groupsByTagId)
79
- .sort(([g1], [g2]) => {
80
- const g1LC = g1.toLowerCase();
81
- const g2LC = g2.toLowerCase();
82
- const g1Idx = lowerCaseServiceTags.findIndex(tn => tn === g1LC);
83
- const g2Idx = lowerCaseServiceTags.findIndex(tn => tn === g2LC);
84
- if (g1Idx < 0 && g2Idx < 0)
85
- return 0;
86
- if (g1Idx < 0)
87
- return 1;
88
- if (g2Idx < 0)
89
- return -1;
90
- return g1Idx - g2Idx;
91
- })
92
- .map(([, tagGroup]) => tagGroup);
93
- return { groups: orderedTagGroups, ungrouped };
94
- }
95
- const defaultComputerAPITreeConfig = {
96
- hideSchemas: false,
97
- hideInternal: false,
98
- };
99
- const computeAPITree = (serviceNode, config = {}) => {
100
- const mergedConfig = defaults__default["default"](config, defaultComputerAPITreeConfig);
101
- const tree = [];
102
- tree.push({
103
- id: '/',
104
- slug: '/',
105
- title: 'Overview',
106
- type: 'overview',
107
- meta: '',
108
- });
109
- const hasOperationNodes = serviceNode.children.some(node => node.type === types.NodeType.HttpOperation);
110
- if (hasOperationNodes) {
111
- tree.push({
112
- title: 'Endpoints',
113
- });
114
- const { groups, ungrouped } = computeTagGroups(serviceNode, types.NodeType.HttpOperation);
115
- addTagGroupsToTree(groups, ungrouped, tree, types.NodeType.HttpOperation, mergedConfig.hideInternal);
116
- }
117
- const hasWebhookNodes = serviceNode.children.some(node => node.type === types.NodeType.HttpWebhook);
118
- if (hasWebhookNodes) {
119
- tree.push({
120
- title: 'Webhooks',
121
- });
122
- const { groups, ungrouped } = computeTagGroups(serviceNode, types.NodeType.HttpWebhook);
123
- addTagGroupsToTree(groups, ungrouped, tree, types.NodeType.HttpWebhook, mergedConfig.hideInternal);
124
- }
125
- let schemaNodes = serviceNode.children.filter(node => node.type === types.NodeType.Model);
126
- if (mergedConfig.hideInternal) {
127
- schemaNodes = schemaNodes.filter(n => !isInternal(n));
128
- }
129
- if (!mergedConfig.hideSchemas && schemaNodes.length) {
130
- tree.push({
131
- title: 'Schemas',
132
- });
133
- const { groups, ungrouped } = computeTagGroups(serviceNode, types.NodeType.Model);
134
- addTagGroupsToTree(groups, ungrouped, tree, types.NodeType.Model, mergedConfig.hideInternal);
135
- }
136
- return tree;
137
- };
138
- const findFirstNodeSlug = (tree) => {
139
- for (const item of tree) {
140
- if ('slug' in item) {
141
- return item.slug;
142
- }
143
- if ('items' in item) {
144
- const slug = findFirstNodeSlug(item.items);
145
- if (slug) {
146
- return slug;
147
- }
148
- }
149
- }
150
- return;
151
- };
152
- const isInternal = (node) => {
153
- const data = node.data;
154
- if (elementsCore.isHttpOperation(data) || elementsCore.isHttpWebhookOperation(data)) {
155
- return !!data.internal;
156
- }
157
- if (elementsCore.isHttpService(data)) {
158
- return false;
159
- }
160
- return !!data['x-internal'];
161
- };
162
- const addTagGroupsToTree = (groups, ungrouped, tree, itemsType, hideInternal) => {
163
- ungrouped.forEach(node => {
164
- if (hideInternal && isInternal(node)) {
165
- return;
166
- }
167
- tree.push({
168
- id: node.uri,
169
- slug: node.uri,
170
- title: node.name,
171
- type: node.type,
172
- meta: elementsCore.isHttpOperation(node.data) || elementsCore.isHttpWebhookOperation(node.data) ? node.data.method : '',
173
- });
174
- });
175
- groups.forEach(group => {
176
- const items = group.items.flatMap(node => {
177
- if (hideInternal && isInternal(node)) {
178
- return [];
179
- }
180
- return {
181
- id: node.uri,
182
- slug: node.uri,
183
- title: node.name,
184
- type: node.type,
185
- meta: elementsCore.isHttpOperation(node.data) || elementsCore.isHttpWebhookOperation(node.data) ? node.data.method : '',
186
- };
187
- });
188
- if (items.length > 0) {
189
- tree.push({
190
- title: group.title,
191
- items,
192
- itemsType,
193
- });
194
- }
195
- });
41
+ function computeTagGroups(serviceNode, nodeType) {
42
+ const groupsByTagId = {};
43
+ const ungrouped = [];
44
+ const lowerCaseServiceTags = serviceNode.tags.map(tn => tn.toLowerCase());
45
+ const groupableNodes = serviceNode.children.filter(n => n.type === nodeType);
46
+ for (const node of groupableNodes) {
47
+ const tagName = node.tags[0];
48
+ if (tagName) {
49
+ const tagId = tagName.toLowerCase();
50
+ if (groupsByTagId[tagId]) {
51
+ groupsByTagId[tagId].items.push(node);
52
+ }
53
+ else {
54
+ const serviceTagIndex = lowerCaseServiceTags.findIndex(tn => tn === tagId);
55
+ const serviceTagName = serviceNode.tags[serviceTagIndex];
56
+ groupsByTagId[tagId] = {
57
+ title: serviceTagName || tagName,
58
+ items: [node],
59
+ };
60
+ }
61
+ }
62
+ else {
63
+ ungrouped.push(node);
64
+ }
65
+ }
66
+ const orderedTagGroups = Object.entries(groupsByTagId)
67
+ .sort(([g1], [g2]) => {
68
+ const g1LC = g1.toLowerCase();
69
+ const g2LC = g2.toLowerCase();
70
+ const g1Idx = lowerCaseServiceTags.findIndex(tn => tn === g1LC);
71
+ const g2Idx = lowerCaseServiceTags.findIndex(tn => tn === g2LC);
72
+ if (g1Idx < 0 && g2Idx < 0)
73
+ return 0;
74
+ if (g1Idx < 0)
75
+ return 1;
76
+ if (g2Idx < 0)
77
+ return -1;
78
+ return g1Idx - g2Idx;
79
+ })
80
+ .map(([, tagGroup]) => tagGroup);
81
+ return { groups: orderedTagGroups, ungrouped };
82
+ }
83
+ const defaultComputerAPITreeConfig = {
84
+ hideSchemas: false,
85
+ hideInternal: false,
86
+ };
87
+ const computeAPITree = (serviceNode, config = {}) => {
88
+ const mergedConfig = defaults(config, defaultComputerAPITreeConfig);
89
+ const tree = [];
90
+ tree.push({
91
+ id: '/',
92
+ slug: '/',
93
+ title: 'Overview',
94
+ type: 'overview',
95
+ meta: '',
96
+ });
97
+ const hasOperationNodes = serviceNode.children.some(node => node.type === types.NodeType.HttpOperation);
98
+ if (hasOperationNodes) {
99
+ tree.push({
100
+ title: 'Endpoints',
101
+ });
102
+ const { groups, ungrouped } = computeTagGroups(serviceNode, types.NodeType.HttpOperation);
103
+ addTagGroupsToTree(groups, ungrouped, tree, types.NodeType.HttpOperation, mergedConfig.hideInternal);
104
+ }
105
+ const hasWebhookNodes = serviceNode.children.some(node => node.type === types.NodeType.HttpWebhook);
106
+ if (hasWebhookNodes) {
107
+ tree.push({
108
+ title: 'Webhooks',
109
+ });
110
+ const { groups, ungrouped } = computeTagGroups(serviceNode, types.NodeType.HttpWebhook);
111
+ addTagGroupsToTree(groups, ungrouped, tree, types.NodeType.HttpWebhook, mergedConfig.hideInternal);
112
+ }
113
+ let schemaNodes = serviceNode.children.filter(node => node.type === types.NodeType.Model);
114
+ if (mergedConfig.hideInternal) {
115
+ schemaNodes = schemaNodes.filter(n => !isInternal(n));
116
+ }
117
+ if (!mergedConfig.hideSchemas && schemaNodes.length) {
118
+ tree.push({
119
+ title: 'Schemas',
120
+ });
121
+ const { groups, ungrouped } = computeTagGroups(serviceNode, types.NodeType.Model);
122
+ addTagGroupsToTree(groups, ungrouped, tree, types.NodeType.Model, mergedConfig.hideInternal);
123
+ }
124
+ return tree;
125
+ };
126
+ const findFirstNodeSlug = (tree) => {
127
+ for (const item of tree) {
128
+ if ('slug' in item) {
129
+ return item.slug;
130
+ }
131
+ if ('items' in item) {
132
+ const slug = findFirstNodeSlug(item.items);
133
+ if (slug) {
134
+ return slug;
135
+ }
136
+ }
137
+ }
138
+ return;
139
+ };
140
+ const isInternal = (node) => {
141
+ const data = node.data;
142
+ if (elementsCore.isHttpOperation(data) || elementsCore.isHttpWebhookOperation(data)) {
143
+ return !!data.internal;
144
+ }
145
+ if (elementsCore.isHttpService(data)) {
146
+ return false;
147
+ }
148
+ return !!data['x-internal'];
149
+ };
150
+ const addTagGroupsToTree = (groups, ungrouped, tree, itemsType, hideInternal) => {
151
+ ungrouped.forEach(node => {
152
+ if (hideInternal && isInternal(node)) {
153
+ return;
154
+ }
155
+ tree.push({
156
+ id: node.uri,
157
+ slug: node.uri,
158
+ title: node.name,
159
+ type: node.type,
160
+ meta: elementsCore.isHttpOperation(node.data) || elementsCore.isHttpWebhookOperation(node.data) ? node.data.method : '',
161
+ });
162
+ });
163
+ groups.forEach(group => {
164
+ const items = group.items.flatMap(node => {
165
+ if (hideInternal && isInternal(node)) {
166
+ return [];
167
+ }
168
+ return {
169
+ id: node.uri,
170
+ slug: node.uri,
171
+ title: node.name,
172
+ type: node.type,
173
+ meta: elementsCore.isHttpOperation(node.data) || elementsCore.isHttpWebhookOperation(node.data) ? node.data.method : '',
174
+ };
175
+ });
176
+ if (items.length > 0) {
177
+ tree.push({
178
+ title: group.title,
179
+ items,
180
+ itemsType,
181
+ });
182
+ }
183
+ });
196
184
  };
197
185
 
198
- const itemMatchesHash = (hash, item) => {
199
- if (item.type === types.NodeType.HttpOperation) {
200
- return hash.substr(1) === `${item.data.path}-${item.data.method}`;
201
- }
202
- else {
203
- return hash.substr(1) === `${item.data.name}-${item.data.method}`;
204
- }
205
- };
206
- const TryItContext = React__namespace.createContext({
207
- hideTryIt: false,
208
- tryItCredentialsPolicy: 'omit',
209
- });
210
- TryItContext.displayName = 'TryItContext';
211
- const LocationContext = React__namespace.createContext({
212
- location: {
213
- hash: '',
214
- key: '',
215
- pathname: '',
216
- search: '',
217
- state: '',
218
- },
219
- });
220
- LocationContext.displayName = 'LocationContext';
221
- const APIWithStackedLayout = ({ serviceNode, hideTryIt, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, renderExtensionAddon, showPoweredByLink = true, location, }) => {
222
- const { groups: operationGroups } = computeTagGroups(serviceNode, types.NodeType.HttpOperation);
223
- const { groups: webhookGroups } = computeTagGroups(serviceNode, types.NodeType.HttpWebhook);
224
- return (React__namespace.createElement(LocationContext.Provider, { value: { location } },
225
- React__namespace.createElement(TryItContext.Provider, { value: { hideTryIt, tryItCredentialsPolicy, corsProxy: tryItCorsProxy } },
226
- React__namespace.createElement(mosaic.Flex, { w: "full", flexDirection: "col", m: "auto", className: "sl-max-w-4xl" },
227
- React__namespace.createElement(mosaic.Box, { w: "full", borderB: true },
228
- React__namespace.createElement(elementsCore.Docs, { className: "sl-mx-auto", nodeData: serviceNode.data, nodeTitle: serviceNode.name, nodeType: types.NodeType.HttpService, location: location, layoutOptions: { showPoweredByLink, hideExport }, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, renderExtensionAddon: renderExtensionAddon })),
229
- operationGroups.length > 0 && webhookGroups.length > 0 ? React__namespace.createElement(mosaic.Heading, { size: 2 }, "Endpoints") : null,
230
- operationGroups.map(group => (React__namespace.createElement(Group, { key: group.title, group: group }))),
231
- webhookGroups.length > 0 ? React__namespace.createElement(mosaic.Heading, { size: 2 }, "Webhooks") : null,
232
- webhookGroups.map(group => (React__namespace.createElement(Group, { key: group.title, group: group })))))));
233
- };
234
- APIWithStackedLayout.displayName = 'APIWithStackedLayout';
235
- const Group = React__namespace.memo(({ group }) => {
236
- const [isExpanded, setIsExpanded] = React__namespace.useState(false);
237
- const scrollRef = React__namespace.useRef(null);
238
- const { location: { hash }, } = React__namespace.useContext(LocationContext);
239
- const urlHashMatches = hash.substr(1) === group.title;
240
- const onClick = React__namespace.useCallback(() => setIsExpanded(!isExpanded), [isExpanded]);
241
- const shouldExpand = React__namespace.useMemo(() => {
242
- return urlHashMatches || group.items.some(item => itemMatchesHash(hash, item));
243
- }, [group, hash, urlHashMatches]);
244
- React__namespace.useEffect(() => {
245
- var _a;
246
- if (shouldExpand) {
247
- setIsExpanded(true);
248
- if (urlHashMatches && ((_a = scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current) === null || _a === void 0 ? void 0 : _a.offsetTop)) {
249
- window.scrollTo(0, scrollRef.current.offsetTop);
250
- }
251
- }
252
- }, [shouldExpand, urlHashMatches, group, hash]);
253
- return (React__namespace.createElement(mosaic.Box, null,
254
- React__namespace.createElement(mosaic.Flex, { ref: scrollRef, onClick: onClick, mx: "auto", justifyContent: "between", alignItems: "center", borderB: true, px: 2, py: 4, cursor: "pointer", color: { default: 'current', hover: 'muted' } },
255
- React__namespace.createElement(mosaic.Box, { fontSize: "lg", fontWeight: "medium" }, group.title),
256
- React__namespace.createElement(mosaic.Icon, { className: "sl-mr-2", icon: isExpanded ? 'chevron-down' : 'chevron-right', size: "sm" })),
257
- React__namespace.createElement(Collapse, { isOpen: isExpanded }, group.items.map(item => {
258
- return React__namespace.createElement(Item, { key: item.uri, item: item });
259
- }))));
260
- });
261
- Group.displayName = 'Group';
262
- const Item = React__namespace.memo(({ item }) => {
263
- const { location } = React__namespace.useContext(LocationContext);
264
- const { hash } = location;
265
- const [isExpanded, setIsExpanded] = React__namespace.useState(false);
266
- const scrollRef = React__namespace.useRef(null);
267
- const color = elementsCore.HttpMethodColors[item.data.method] || 'gray';
268
- const isDeprecated = !!item.data.deprecated;
269
- const { hideTryIt, tryItCredentialsPolicy, corsProxy } = React__namespace.useContext(TryItContext);
270
- const onClick = React__namespace.useCallback(() => setIsExpanded(!isExpanded), [isExpanded]);
271
- React__namespace.useEffect(() => {
272
- var _a;
273
- if (itemMatchesHash(hash, item)) {
274
- setIsExpanded(true);
275
- if ((_a = scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current) === null || _a === void 0 ? void 0 : _a.offsetTop) {
276
- window.scrollTo(0, scrollRef.current.offsetTop);
277
- }
278
- }
279
- }, [hash, item]);
280
- return (React__namespace.createElement(mosaic.Box, { ref: scrollRef, w: "full", my: 2, border: true, borderColor: { default: isExpanded ? 'light' : 'transparent', hover: 'light' }, bg: { default: isExpanded ? 'code' : 'transparent', hover: 'code' } },
281
- React__namespace.createElement(mosaic.Flex, { mx: "auto", alignItems: "center", cursor: "pointer", fontSize: "lg", p: 2, onClick: onClick, color: "current" },
282
- React__namespace.createElement(mosaic.Box, { w: 24, textTransform: "uppercase", textAlign: "center", fontWeight: "semibold", border: true, rounded: true, px: 2, bg: "canvas", className: cn__default["default"](`sl-mr-5 sl-text-base`, `sl-text-${color}`, `sl-border-${color}`) }, item.data.method || 'UNKNOWN'),
283
- React__namespace.createElement(mosaic.Box, { flex: 1, fontWeight: "medium", wordBreak: "all" }, item.type === types.NodeType.HttpOperation ? item.data.path : item.name),
284
- isDeprecated && React__namespace.createElement(elementsCore.DeprecatedBadge, null)),
285
- React__namespace.createElement(Collapse, { isOpen: isExpanded },
286
- React__namespace.createElement(mosaic.Box, { flex: 1, p: 2, fontWeight: "medium", mx: "auto", fontSize: "xl" }, item.name),
287
- hideTryIt ? (React__namespace.createElement(mosaic.Box, { as: elementsCore.ParsedDocs, layoutOptions: { noHeading: true, hideTryItPanel: true }, node: item, p: 4 })) : (React__namespace.createElement(mosaic.Tabs, { appearance: "line" },
288
- React__namespace.createElement(mosaic.TabList, null,
289
- React__namespace.createElement(mosaic.Tab, null, "Docs"),
290
- React__namespace.createElement(mosaic.Tab, null, "TryIt")),
291
- React__namespace.createElement(mosaic.TabPanels, null,
292
- React__namespace.createElement(mosaic.TabPanel, null,
293
- React__namespace.createElement(elementsCore.ParsedDocs, { className: "sl-px-4", node: item, location: location, layoutOptions: { noHeading: true, hideTryItPanel: true } })),
294
- React__namespace.createElement(mosaic.TabPanel, null,
295
- React__namespace.createElement(elementsCore.TryItWithRequestSamples, { httpOperation: item.data, tryItCredentialsPolicy: tryItCredentialsPolicy, corsProxy: corsProxy }))))))));
296
- });
297
- Item.displayName = 'Item';
298
- const Collapse = ({ isOpen, children }) => {
299
- if (!isOpen)
300
- return null;
301
- return React__namespace.createElement(mosaic.Box, null, children);
302
- };
186
+ const itemMatchesHash = (hash, item) => {
187
+ if (item.type === types.NodeType.HttpOperation) {
188
+ return hash.substr(1) === `${item.data.path}-${item.data.method}`;
189
+ }
190
+ else {
191
+ return hash.substr(1) === `${item.data.name}-${item.data.method}`;
192
+ }
193
+ };
194
+ const TryItContext = React__namespace.createContext({
195
+ hideTryIt: false,
196
+ hideTryItPanel: false,
197
+ hideSamples: false,
198
+ tryItCredentialsPolicy: 'omit',
199
+ });
200
+ TryItContext.displayName = 'TryItContext';
201
+ const LocationContext = React__namespace.createContext({
202
+ location: {
203
+ hash: '',
204
+ key: '',
205
+ pathname: '',
206
+ search: '',
207
+ state: '',
208
+ },
209
+ });
210
+ LocationContext.displayName = 'LocationContext';
211
+ const APIWithStackedLayout = ({ serviceNode, hideTryItPanel, hideTryIt, hideSamples, hideExport, hideSecurityInfo, hideServerInfo, exportProps, tryItCredentialsPolicy, tryItCorsProxy, renderExtensionAddon, showPoweredByLink = true, location, }) => {
212
+ const { groups: operationGroups } = computeTagGroups(serviceNode, types.NodeType.HttpOperation);
213
+ const { groups: webhookGroups } = computeTagGroups(serviceNode, types.NodeType.HttpWebhook);
214
+ return (React__namespace.createElement(LocationContext.Provider, { value: { location } },
215
+ React__namespace.createElement(TryItContext.Provider, { value: { hideTryItPanel, hideTryIt, hideSamples, tryItCredentialsPolicy, corsProxy: tryItCorsProxy } },
216
+ React__namespace.createElement(mosaic.Flex, { w: "full", flexDirection: "col", m: "auto", className: "sl-max-w-4xl" },
217
+ React__namespace.createElement(mosaic.Box, { w: "full", borderB: true },
218
+ React__namespace.createElement(elementsCore.Docs, { className: "sl-mx-auto", nodeData: serviceNode.data, nodeTitle: serviceNode.name, nodeType: types.NodeType.HttpService, location: location, layoutOptions: { showPoweredByLink, hideExport, hideSecurityInfo, hideServerInfo }, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, renderExtensionAddon: renderExtensionAddon })),
219
+ operationGroups.length > 0 && webhookGroups.length > 0 ? React__namespace.createElement(mosaic.Heading, { size: 2 }, "Endpoints") : null,
220
+ operationGroups.map(group => (React__namespace.createElement(Group, { key: group.title, group: group }))),
221
+ webhookGroups.length > 0 ? React__namespace.createElement(mosaic.Heading, { size: 2 }, "Webhooks") : null,
222
+ webhookGroups.map(group => (React__namespace.createElement(Group, { key: group.title, group: group })))))));
223
+ };
224
+ APIWithStackedLayout.displayName = 'APIWithStackedLayout';
225
+ const Group = React__namespace.memo(({ group }) => {
226
+ const [isExpanded, setIsExpanded] = React__namespace.useState(false);
227
+ const scrollRef = React__namespace.useRef(null);
228
+ const { location: { hash }, } = React__namespace.useContext(LocationContext);
229
+ const urlHashMatches = hash.substr(1) === group.title;
230
+ const onClick = React__namespace.useCallback(() => setIsExpanded(!isExpanded), [isExpanded]);
231
+ const shouldExpand = React__namespace.useMemo(() => {
232
+ return urlHashMatches || group.items.some(item => itemMatchesHash(hash, item));
233
+ }, [group, hash, urlHashMatches]);
234
+ React__namespace.useEffect(() => {
235
+ var _a;
236
+ if (shouldExpand) {
237
+ setIsExpanded(true);
238
+ if (urlHashMatches && ((_a = scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current) === null || _a === void 0 ? void 0 : _a.offsetTop)) {
239
+ window.scrollTo(0, scrollRef.current.offsetTop);
240
+ }
241
+ }
242
+ }, [shouldExpand, urlHashMatches, group, hash]);
243
+ return (React__namespace.createElement(mosaic.Box, null,
244
+ React__namespace.createElement(mosaic.Flex, { ref: scrollRef, onClick: onClick, mx: "auto", justifyContent: "between", alignItems: "center", borderB: true, px: 2, py: 4, cursor: "pointer", color: { default: 'current', hover: 'muted' } },
245
+ React__namespace.createElement(mosaic.Box, { fontSize: "lg", fontWeight: "medium" }, group.title),
246
+ React__namespace.createElement(mosaic.Icon, { className: "sl-mr-2", icon: isExpanded ? 'chevron-down' : 'chevron-right', size: "sm" })),
247
+ React__namespace.createElement(Collapse, { isOpen: isExpanded }, group.items.map(item => {
248
+ return React__namespace.createElement(Item, { key: item.uri, item: item });
249
+ }))));
250
+ });
251
+ Group.displayName = 'Group';
252
+ const Item = React__namespace.memo(({ item }) => {
253
+ const { location } = React__namespace.useContext(LocationContext);
254
+ const { hash } = location;
255
+ const [isExpanded, setIsExpanded] = React__namespace.useState(false);
256
+ const scrollRef = React__namespace.useRef(null);
257
+ const color = elementsCore.HttpMethodColors[item.data.method] || 'gray';
258
+ const isDeprecated = !!item.data.deprecated;
259
+ const { hideTryIt, hideSamples, hideTryItPanel, tryItCredentialsPolicy, corsProxy } = React__namespace.useContext(TryItContext);
260
+ const onClick = React__namespace.useCallback(() => setIsExpanded(!isExpanded), [isExpanded]);
261
+ React__namespace.useEffect(() => {
262
+ var _a;
263
+ if (itemMatchesHash(hash, item)) {
264
+ setIsExpanded(true);
265
+ if ((_a = scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current) === null || _a === void 0 ? void 0 : _a.offsetTop) {
266
+ window.scrollTo(0, scrollRef.current.offsetTop);
267
+ }
268
+ }
269
+ }, [hash, item]);
270
+ return (React__namespace.createElement(mosaic.Box, { ref: scrollRef, w: "full", my: 2, border: true, borderColor: { default: isExpanded ? 'light' : 'transparent', hover: 'light' }, bg: { default: isExpanded ? 'code' : 'transparent', hover: 'code' } },
271
+ React__namespace.createElement(mosaic.Flex, { mx: "auto", alignItems: "center", cursor: "pointer", fontSize: "lg", p: 2, onClick: onClick, color: "current" },
272
+ React__namespace.createElement(mosaic.Box, { w: 24, textTransform: "uppercase", textAlign: "center", fontWeight: "semibold", border: true, rounded: true, px: 2, bg: "canvas", className: cn(`sl-mr-5 sl-text-base`, `sl-text-${color}`, `sl-border-${color}`) }, item.data.method || 'UNKNOWN'),
273
+ React__namespace.createElement(mosaic.Box, { flex: 1, fontWeight: "medium", wordBreak: "all" }, item.type === types.NodeType.HttpOperation ? item.data.path : item.name),
274
+ isDeprecated && React__namespace.createElement(elementsCore.DeprecatedBadge, null)),
275
+ React__namespace.createElement(Collapse, { isOpen: isExpanded },
276
+ React__namespace.createElement(mosaic.Box, { flex: 1, p: 2, fontWeight: "medium", mx: "auto", fontSize: "xl" }, item.name),
277
+ hideTryItPanel ? (React__namespace.createElement(mosaic.Box, { as: elementsCore.ParsedDocs, layoutOptions: { noHeading: true, hideTryItPanel: true, hideSamples, hideTryIt }, node: item, p: 4 })) : (React__namespace.createElement(mosaic.Tabs, { appearance: "line" },
278
+ React__namespace.createElement(mosaic.TabList, null,
279
+ React__namespace.createElement(mosaic.Tab, null, "Docs"),
280
+ React__namespace.createElement(mosaic.Tab, null, "TryIt")),
281
+ React__namespace.createElement(mosaic.TabPanels, null,
282
+ React__namespace.createElement(mosaic.TabPanel, null,
283
+ React__namespace.createElement(elementsCore.ParsedDocs, { className: "sl-px-4", node: item, location: location, layoutOptions: { noHeading: true, hideTryItPanel: false, hideSamples, hideTryIt } })),
284
+ React__namespace.createElement(mosaic.TabPanel, null,
285
+ React__namespace.createElement(elementsCore.TryItWithRequestSamples, { httpOperation: item.data, tryItCredentialsPolicy: tryItCredentialsPolicy, corsProxy: corsProxy, hideSamples: hideSamples, hideTryIt: hideTryIt }))))))));
286
+ });
287
+ Item.displayName = 'Item';
288
+ const Collapse = ({ isOpen, children }) => {
289
+ if (!isOpen)
290
+ return null;
291
+ return React__namespace.createElement(mosaic.Box, null, children);
292
+ };
303
293
  Collapse.displayName = 'Collapse';
304
294
 
305
- const APIWithResponsiveSidebarLayout = ({ serviceNode, logo, hideTryIt, compact, hideSchemas, hideInternal, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, renderExtensionAddon, }) => {
306
- const container = React__namespace.useRef(null);
307
- const tree = React__namespace.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
308
- const location = reactRouterDom.useLocation();
309
- const { pathname } = location;
310
- const isRootPath = !pathname || pathname === '/';
311
- const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
312
- const layoutOptions = React__namespace.useMemo(() => ({ hideTryIt: hideTryIt, compact: compact, hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== types.NodeType.HttpService }), [hideTryIt, hideExport, node, compact]);
313
- if (!node) {
314
- const firstSlug = findFirstNodeSlug(tree);
315
- if (firstSlug) {
316
- return React__namespace.createElement(reactRouterDom.Redirect, { to: firstSlug });
317
- }
318
- }
319
- if (hideInternal && node && isInternal(node)) {
320
- return React__namespace.createElement(reactRouterDom.Redirect, { to: "/" });
321
- }
322
- const handleTocClick = () => {
323
- if (container.current) {
324
- container.current.scrollIntoView();
325
- }
326
- };
327
- return (React__namespace.createElement(elementsCore.ResponsiveSidebarLayout, { onTocClick: handleTocClick, tree: tree, logo: logo !== null && logo !== void 0 ? logo : serviceNode.data.logo, ref: container, name: serviceNode.name }, node && (React__namespace.createElement(elementsCore.ElementsOptionsProvider, { renderExtensionAddon: renderExtensionAddon },
328
- React__namespace.createElement(elementsCore.ParsedDocs, { key: pathname, uri: pathname, node: node, nodeTitle: node.name, layoutOptions: layoutOptions, location: location, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon })))));
295
+ const APIWithResponsiveSidebarLayout = ({ serviceNode, logo, hideTryItPanel, hideTryIt, hideSamples, compact, hideSchemas, hideInternal, hideExport, hideServerInfo, hideSecurityInfo, exportProps, tryItCredentialsPolicy, tryItCorsProxy, renderExtensionAddon, }) => {
296
+ const container = React__namespace.useRef(null);
297
+ const tree = React__namespace.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
298
+ const location = reactRouterDom.useLocation();
299
+ const { pathname } = location;
300
+ const isRootPath = !pathname || pathname === '/';
301
+ const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
302
+ const layoutOptions = React__namespace.useMemo(() => ({
303
+ hideTryIt: hideTryIt,
304
+ hideTryItPanel,
305
+ hideSamples,
306
+ hideSecurityInfo: hideSecurityInfo,
307
+ hideServerInfo: hideServerInfo,
308
+ compact: compact,
309
+ hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== types.NodeType.HttpService,
310
+ }), [hideTryIt, hideSecurityInfo, hideServerInfo, compact, hideExport, hideTryItPanel, hideSamples, node === null || node === void 0 ? void 0 : node.type]);
311
+ if (!node) {
312
+ const firstSlug = findFirstNodeSlug(tree);
313
+ if (firstSlug) {
314
+ return React__namespace.createElement(reactRouterDom.Redirect, { to: firstSlug });
315
+ }
316
+ }
317
+ if (hideInternal && node && isInternal(node)) {
318
+ return React__namespace.createElement(reactRouterDom.Redirect, { to: "/" });
319
+ }
320
+ const handleTocClick = () => {
321
+ if (container.current) {
322
+ container.current.scrollIntoView();
323
+ }
324
+ };
325
+ return (React__namespace.createElement(elementsCore.ResponsiveSidebarLayout, { onTocClick: handleTocClick, tree: tree, logo: logo !== null && logo !== void 0 ? logo : serviceNode.data.logo, ref: container, name: serviceNode.name }, node && (React__namespace.createElement(elementsCore.ElementsOptionsProvider, { renderExtensionAddon: renderExtensionAddon },
326
+ React__namespace.createElement(elementsCore.ParsedDocs, { key: pathname, uri: pathname, node: node, nodeTitle: node.name, layoutOptions: layoutOptions, location: location, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon })))));
329
327
  };
330
328
 
331
- const APIWithSidebarLayout = ({ serviceNode, logo, hideTryIt, hideSchemas, hideInternal, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, renderExtensionAddon, }) => {
332
- const container = React__namespace.useRef(null);
333
- const tree = React__namespace.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
334
- const location = reactRouterDom.useLocation();
335
- const { pathname } = location;
336
- const isRootPath = !pathname || pathname === '/';
337
- const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
338
- const layoutOptions = React__namespace.useMemo(() => ({ hideTryIt: hideTryIt, hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== types.NodeType.HttpService }), [hideTryIt, hideExport, node]);
339
- if (!node) {
340
- const firstSlug = findFirstNodeSlug(tree);
341
- if (firstSlug) {
342
- return React__namespace.createElement(reactRouterDom.Redirect, { to: firstSlug });
343
- }
344
- }
345
- if (hideInternal && node && isInternal(node)) {
346
- return React__namespace.createElement(reactRouterDom.Redirect, { to: "/" });
347
- }
348
- const sidebar = (React__namespace.createElement(Sidebar, { serviceNode: serviceNode, logo: logo, container: container, pathname: pathname, tree: tree }));
349
- return (React__namespace.createElement(elementsCore.SidebarLayout, { ref: container, sidebar: sidebar }, node && (React__namespace.createElement(elementsCore.ElementsOptionsProvider, { renderExtensionAddon: renderExtensionAddon },
350
- React__namespace.createElement(elementsCore.ParsedDocs, { key: pathname, uri: pathname, node: node, nodeTitle: node.name, layoutOptions: layoutOptions, location: location, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon })))));
351
- };
352
- const Sidebar = ({ serviceNode, logo, container, pathname, tree }) => {
353
- const handleTocClick = () => {
354
- if (container.current) {
355
- container.current.scrollIntoView();
356
- }
357
- };
358
- return (React__namespace.createElement(React__namespace.Fragment, null,
359
- React__namespace.createElement(mosaic.Flex, { ml: 4, mb: 5, alignItems: "center" },
360
- logo ? (React__namespace.createElement(elementsCore.Logo, { logo: { url: logo, altText: 'logo' } })) : (serviceNode.data.logo && React__namespace.createElement(elementsCore.Logo, { logo: serviceNode.data.logo })),
361
- React__namespace.createElement(mosaic.Heading, { size: 4 }, serviceNode.name)),
362
- React__namespace.createElement(mosaic.Flex, { flexGrow: true, flexShrink: true, overflowY: "auto", direction: "col" },
363
- React__namespace.createElement(elementsCore.TableOfContents, { tree: tree, activeId: pathname, Link: reactRouterDom.Link, onLinkClick: handleTocClick })),
364
- React__namespace.createElement(elementsCore.PoweredByLink, { source: serviceNode.name, pathname: pathname, packageType: "elements" })));
365
- };
329
+ const APIWithSidebarLayout = ({ serviceNode, logo, hideTryItPanel, hideTryIt, hideSamples, hideSchemas, hideSecurityInfo, hideServerInfo, hideInternal, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, renderExtensionAddon, }) => {
330
+ const container = React__namespace.useRef(null);
331
+ const tree = React__namespace.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
332
+ const location = reactRouterDom.useLocation();
333
+ const { pathname } = location;
334
+ const isRootPath = !pathname || pathname === '/';
335
+ const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
336
+ const layoutOptions = React__namespace.useMemo(() => ({
337
+ hideTryIt: hideTryIt,
338
+ hideTryItPanel,
339
+ hideSamples,
340
+ hideServerInfo: hideServerInfo,
341
+ hideSecurityInfo: hideSecurityInfo,
342
+ hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== types.NodeType.HttpService,
343
+ }), [hideTryIt, hideServerInfo, hideSecurityInfo, hideExport, hideTryItPanel, hideSamples, node === null || node === void 0 ? void 0 : node.type]);
344
+ if (!node) {
345
+ const firstSlug = findFirstNodeSlug(tree);
346
+ if (firstSlug) {
347
+ return React__namespace.createElement(reactRouterDom.Redirect, { to: firstSlug });
348
+ }
349
+ }
350
+ if (hideInternal && node && isInternal(node)) {
351
+ return React__namespace.createElement(reactRouterDom.Redirect, { to: "/" });
352
+ }
353
+ const sidebar = (React__namespace.createElement(Sidebar, { serviceNode: serviceNode, logo: logo, container: container, pathname: pathname, tree: tree }));
354
+ return (React__namespace.createElement(elementsCore.SidebarLayout, { ref: container, sidebar: sidebar }, node && (React__namespace.createElement(elementsCore.ElementsOptionsProvider, { renderExtensionAddon: renderExtensionAddon },
355
+ React__namespace.createElement(elementsCore.ParsedDocs, { key: pathname, uri: pathname, node: node, nodeTitle: node.name, layoutOptions: layoutOptions, location: location, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon })))));
356
+ };
357
+ const Sidebar = ({ serviceNode, logo, container, pathname, tree }) => {
358
+ const handleTocClick = () => {
359
+ if (container.current) {
360
+ container.current.scrollIntoView();
361
+ }
362
+ };
363
+ return (React__namespace.createElement(React__namespace.Fragment, null,
364
+ React__namespace.createElement(mosaic.Flex, { ml: 4, mb: 5, alignItems: "center" },
365
+ logo ? (React__namespace.createElement(elementsCore.Logo, { logo: { url: logo, altText: 'logo' } })) : (serviceNode.data.logo && React__namespace.createElement(elementsCore.Logo, { logo: serviceNode.data.logo })),
366
+ React__namespace.createElement(mosaic.Heading, { size: 4 }, serviceNode.name)),
367
+ React__namespace.createElement(mosaic.Flex, { flexGrow: true, flexShrink: true, overflowY: "auto", direction: "col" },
368
+ React__namespace.createElement(elementsCore.TableOfContents, { tree: tree, activeId: pathname, Link: reactRouterDom.Link, onLinkClick: handleTocClick })),
369
+ React__namespace.createElement(elementsCore.PoweredByLink, { source: serviceNode.name, pathname: pathname, packageType: "elements" })));
370
+ };
366
371
  Sidebar.displayName = 'Sidebar';
367
372
 
368
- var NodeTypes;
369
- (function (NodeTypes) {
370
- NodeTypes["Paths"] = "paths";
371
- NodeTypes["Path"] = "path";
372
- NodeTypes["Operation"] = "operation";
373
- NodeTypes["Webhooks"] = "webhooks";
374
- NodeTypes["Webhook"] = "webhook";
375
- NodeTypes["Components"] = "components";
376
- NodeTypes["Models"] = "models";
377
- NodeTypes["Model"] = "model";
373
+ var NodeTypes;
374
+ (function (NodeTypes) {
375
+ NodeTypes["Paths"] = "paths";
376
+ NodeTypes["Path"] = "path";
377
+ NodeTypes["Operation"] = "operation";
378
+ NodeTypes["Webhooks"] = "webhooks";
379
+ NodeTypes["Webhook"] = "webhook";
380
+ NodeTypes["Components"] = "components";
381
+ NodeTypes["Models"] = "models";
382
+ NodeTypes["Model"] = "model";
378
383
  })(NodeTypes || (NodeTypes = {}));
379
384
 
380
- const oas2SourceMap = [
381
- {
382
- match: 'paths',
383
- type: NodeTypes.Paths,
384
- children: [
385
- {
386
- notMatch: '^x-',
387
- type: NodeTypes.Path,
388
- children: [
389
- {
390
- match: 'get|post|put|delete|options|head|patch|trace',
391
- type: NodeTypes.Operation,
392
- },
393
- ],
394
- },
395
- ],
396
- },
397
- {
398
- match: 'definitions',
399
- type: NodeTypes.Models,
400
- children: [
401
- {
402
- notMatch: '^x-',
403
- type: NodeTypes.Model,
404
- },
405
- ],
406
- },
385
+ const oas2SourceMap = [
386
+ {
387
+ match: 'paths',
388
+ type: NodeTypes.Paths,
389
+ children: [
390
+ {
391
+ notMatch: '^x-',
392
+ type: NodeTypes.Path,
393
+ children: [
394
+ {
395
+ match: 'get|post|put|delete|options|head|patch|trace',
396
+ type: NodeTypes.Operation,
397
+ },
398
+ ],
399
+ },
400
+ ],
401
+ },
402
+ {
403
+ match: 'definitions',
404
+ type: NodeTypes.Models,
405
+ children: [
406
+ {
407
+ notMatch: '^x-',
408
+ type: NodeTypes.Model,
409
+ },
410
+ ],
411
+ },
407
412
  ];
408
413
 
409
- const oas3SourceMap = [
410
- {
411
- match: 'paths',
412
- type: NodeTypes.Paths,
413
- children: [
414
- {
415
- notMatch: '^x-',
416
- type: NodeTypes.Path,
417
- children: [
418
- {
419
- match: 'get|post|put|delete|options|head|patch|trace',
420
- type: NodeTypes.Operation,
421
- },
422
- ],
423
- },
424
- ],
425
- },
426
- {
427
- match: 'webhooks',
428
- type: NodeTypes.Webhooks,
429
- children: [
430
- {
431
- notMatch: '^x-',
432
- type: NodeTypes.Webhook,
433
- children: [
434
- {
435
- match: 'get|post|put|delete|options|head|patch|trace',
436
- type: NodeTypes.Webhook,
437
- },
438
- ],
439
- },
440
- ],
441
- },
442
- {
443
- match: 'components',
444
- type: NodeTypes.Components,
445
- children: [
446
- {
447
- match: 'schemas',
448
- type: NodeTypes.Models,
449
- children: [
450
- {
451
- notMatch: '^x-',
452
- type: NodeTypes.Model,
453
- },
454
- ],
455
- },
456
- ],
457
- },
414
+ const oas3SourceMap = [
415
+ {
416
+ match: 'paths',
417
+ type: NodeTypes.Paths,
418
+ children: [
419
+ {
420
+ notMatch: '^x-',
421
+ type: NodeTypes.Path,
422
+ children: [
423
+ {
424
+ match: 'get|post|put|delete|options|head|patch|trace',
425
+ type: NodeTypes.Operation,
426
+ },
427
+ ],
428
+ },
429
+ ],
430
+ },
431
+ {
432
+ match: 'webhooks',
433
+ type: NodeTypes.Webhooks,
434
+ children: [
435
+ {
436
+ notMatch: '^x-',
437
+ type: NodeTypes.Webhook,
438
+ children: [
439
+ {
440
+ match: 'get|post|put|delete|options|head|patch|trace',
441
+ type: NodeTypes.Webhook,
442
+ },
443
+ ],
444
+ },
445
+ ],
446
+ },
447
+ {
448
+ match: 'components',
449
+ type: NodeTypes.Components,
450
+ children: [
451
+ {
452
+ match: 'schemas',
453
+ type: NodeTypes.Models,
454
+ children: [
455
+ {
456
+ notMatch: '^x-',
457
+ type: NodeTypes.Model,
458
+ },
459
+ ],
460
+ },
461
+ ],
462
+ },
458
463
  ];
459
464
 
460
- const isOas2 = (parsed) => isObject__default["default"](parsed) &&
461
- 'swagger' in parsed &&
462
- Number.parseInt(String(parsed.swagger)) === 2;
463
- const isOas3 = (parsed) => isObject__default["default"](parsed) &&
464
- 'openapi' in parsed &&
465
- Number.parseFloat(String(parsed.openapi)) >= 3;
466
- const isOas31 = (parsed) => isObject__default["default"](parsed) &&
467
- 'openapi' in parsed &&
468
- Number.parseFloat(String(parsed.openapi)) === 3.1;
469
- const OAS_MODEL_REGEXP = /((definitions|components)\/?(schemas)?)\//;
470
- function transformOasToServiceNode(apiDescriptionDocument) {
471
- if (isOas31(apiDescriptionDocument)) {
472
- return computeServiceNode(Object.assign(Object.assign({}, apiDescriptionDocument), { jsonSchemaDialect: 'http://json-schema.org/draft-07/schema#' }), oas3SourceMap, oas3.transformOas3Service, oas3.transformOas3Operation);
473
- }
474
- if (isOas3(apiDescriptionDocument)) {
475
- return computeServiceNode(apiDescriptionDocument, oas3SourceMap, oas3.transformOas3Service, oas3.transformOas3Operation);
476
- }
477
- else if (isOas2(apiDescriptionDocument)) {
478
- return computeServiceNode(apiDescriptionDocument, oas2SourceMap, oas2.transformOas2Service, oas2.transformOas2Operation);
479
- }
480
- return null;
481
- }
482
- function computeServiceNode(document, map, transformService, transformOperation) {
483
- var _a;
484
- const serviceDocument = transformService({ document });
485
- const serviceNode = {
486
- type: types.NodeType.HttpService,
487
- uri: '/',
488
- name: serviceDocument.name,
489
- data: serviceDocument,
490
- tags: ((_a = serviceDocument.tags) === null || _a === void 0 ? void 0 : _a.map(tag => tag.name)) || [],
491
- children: computeChildNodes(document, document, map, transformOperation),
492
- };
493
- return serviceNode;
494
- }
495
- function computeChildNodes(document, data, map, transformer, parentUri = '') {
496
- var _a, _b;
497
- const nodes = [];
498
- if (!isObject__default["default"](data))
499
- return nodes;
500
- for (const key of Object.keys(data)) {
501
- const sanitizedKey = json.encodePointerFragment(key);
502
- const match = findMapMatch(sanitizedKey, map);
503
- if (match) {
504
- const uri = `${parentUri}/${sanitizedKey}`;
505
- const jsonPath = json.pointerToPath(`#${uri}`);
506
- if (match.type === NodeTypes.Operation && jsonPath.length === 3) {
507
- const path = String(jsonPath[1]);
508
- const method = String(jsonPath[2]);
509
- const operationDocument = transformer({
510
- document,
511
- name: path,
512
- method,
513
- config: oas.OPERATION_CONFIG,
514
- });
515
- let parsedUri;
516
- const encodedPath = String(json.encodePointerFragment(path));
517
- if (operationDocument.iid) {
518
- parsedUri = `/operations/${operationDocument.iid}`;
519
- }
520
- else {
521
- parsedUri = uri.replace(encodedPath, elementsCore.slugify(path));
522
- }
523
- nodes.push({
524
- type: types.NodeType.HttpOperation,
525
- uri: parsedUri,
526
- data: operationDocument,
527
- name: operationDocument.summary || operationDocument.iid || operationDocument.path,
528
- tags: ((_a = operationDocument.tags) === null || _a === void 0 ? void 0 : _a.map(tag => tag.name)) || [],
529
- });
530
- }
531
- else if (match.type === NodeTypes.Webhook && jsonPath.length === 3) {
532
- const name = String(jsonPath[1]);
533
- const method = String(jsonPath[2]);
534
- const webhookDocument = transformer({
535
- document,
536
- name,
537
- method,
538
- config: oas.WEBHOOK_CONFIG,
539
- });
540
- let parsedUri;
541
- const encodedPath = String(json.encodePointerFragment(name));
542
- if (webhookDocument.iid) {
543
- parsedUri = `/webhooks/${webhookDocument.iid}`;
544
- }
545
- else {
546
- parsedUri = uri.replace(encodedPath, elementsCore.slugify(name));
547
- }
548
- nodes.push({
549
- type: types.NodeType.HttpWebhook,
550
- uri: parsedUri,
551
- data: webhookDocument,
552
- name: webhookDocument.summary || webhookDocument.name,
553
- tags: ((_b = webhookDocument.tags) === null || _b === void 0 ? void 0 : _b.map(tag => tag.name)) || [],
554
- });
555
- }
556
- else if (match.type === NodeTypes.Model) {
557
- const schemaDocument = get__default["default"](document, jsonPath);
558
- const parsedUri = uri.replace(OAS_MODEL_REGEXP, 'schemas/');
559
- nodes.push({
560
- type: types.NodeType.Model,
561
- uri: parsedUri,
562
- data: schemaDocument,
563
- name: schemaDocument.title || last__default["default"](uri.split('/')) || '',
564
- tags: schemaDocument['x-tags'] || [],
565
- });
566
- }
567
- if (match.children) {
568
- nodes.push(...computeChildNodes(document, data[key], match.children, transformer, uri));
569
- }
570
- }
571
- }
572
- return nodes;
573
- }
574
- function findMapMatch(key, map) {
575
- var _a;
576
- if (typeof key === 'number')
577
- return;
578
- for (const entry of map) {
579
- const escapedKey = key.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
580
- if (!!((_a = entry.match) === null || _a === void 0 ? void 0 : _a.match(escapedKey)) || (entry.notMatch !== void 0 && !entry.notMatch.match(escapedKey))) {
581
- return entry;
582
- }
583
- }
584
- }
585
- function isJson(value) {
586
- try {
587
- JSON.parse(value);
588
- }
589
- catch (e) {
590
- return false;
591
- }
592
- return true;
465
+ const isOas2 = (parsed) => isObject(parsed) &&
466
+ 'swagger' in parsed &&
467
+ Number.parseInt(String(parsed.swagger)) === 2;
468
+ const isOas3 = (parsed) => isObject(parsed) &&
469
+ 'openapi' in parsed &&
470
+ Number.parseFloat(String(parsed.openapi)) >= 3;
471
+ const isOas31 = (parsed) => isObject(parsed) &&
472
+ 'openapi' in parsed &&
473
+ Number.parseFloat(String(parsed.openapi)) === 3.1;
474
+ const OAS_MODEL_REGEXP = /((definitions|components)\/?(schemas)?)\//;
475
+ function transformOasToServiceNode(apiDescriptionDocument) {
476
+ if (isOas31(apiDescriptionDocument)) {
477
+ return computeServiceNode(Object.assign(Object.assign({}, apiDescriptionDocument), { jsonSchemaDialect: 'http://json-schema.org/draft-07/schema#' }), oas3SourceMap, oas3.transformOas3Service, oas3.transformOas3Operation);
478
+ }
479
+ if (isOas3(apiDescriptionDocument)) {
480
+ return computeServiceNode(apiDescriptionDocument, oas3SourceMap, oas3.transformOas3Service, oas3.transformOas3Operation);
481
+ }
482
+ else if (isOas2(apiDescriptionDocument)) {
483
+ return computeServiceNode(apiDescriptionDocument, oas2SourceMap, oas2.transformOas2Service, oas2.transformOas2Operation);
484
+ }
485
+ return null;
486
+ }
487
+ function computeServiceNode(document, map, transformService, transformOperation) {
488
+ var _a;
489
+ const serviceDocument = transformService({ document });
490
+ const serviceNode = {
491
+ type: types.NodeType.HttpService,
492
+ uri: '/',
493
+ name: serviceDocument.name,
494
+ data: serviceDocument,
495
+ tags: ((_a = serviceDocument.tags) === null || _a === void 0 ? void 0 : _a.map(tag => tag.name)) || [],
496
+ children: computeChildNodes(document, document, map, transformOperation),
497
+ };
498
+ return serviceNode;
499
+ }
500
+ function computeChildNodes(document, data, map, transformer, parentUri = '') {
501
+ var _a, _b;
502
+ const nodes = [];
503
+ if (!isObject(data))
504
+ return nodes;
505
+ for (const [key, value] of Object.entries(data)) {
506
+ const sanitizedKey = json.encodePointerFragment(key);
507
+ const match = findMapMatch(sanitizedKey, map);
508
+ if (match) {
509
+ const uri = `${parentUri}/${sanitizedKey}`;
510
+ const jsonPath = json.pointerToPath(`#${uri}`);
511
+ if (match.type === NodeTypes.Operation && jsonPath.length === 3) {
512
+ const path = String(jsonPath[1]);
513
+ const method = String(jsonPath[2]);
514
+ const operationDocument = transformer({
515
+ document,
516
+ name: path,
517
+ method,
518
+ config: oas.OPERATION_CONFIG,
519
+ });
520
+ let parsedUri;
521
+ const encodedPath = String(json.encodePointerFragment(path));
522
+ if (operationDocument.iid) {
523
+ parsedUri = `/operations/${operationDocument.iid}`;
524
+ }
525
+ else {
526
+ parsedUri = uri.replace(encodedPath, elementsCore.slugify(path));
527
+ }
528
+ nodes.push({
529
+ type: types.NodeType.HttpOperation,
530
+ uri: parsedUri,
531
+ data: operationDocument,
532
+ name: operationDocument.summary || operationDocument.iid || operationDocument.path,
533
+ tags: ((_a = operationDocument.tags) === null || _a === void 0 ? void 0 : _a.map(tag => tag.name)) || [],
534
+ });
535
+ }
536
+ else if (match.type === NodeTypes.Webhook && jsonPath.length === 3) {
537
+ const name = String(jsonPath[1]);
538
+ const method = String(jsonPath[2]);
539
+ const webhookDocument = transformer({
540
+ document,
541
+ name,
542
+ method,
543
+ config: oas.WEBHOOK_CONFIG,
544
+ });
545
+ let parsedUri;
546
+ const encodedPath = String(json.encodePointerFragment(name));
547
+ if (webhookDocument.iid) {
548
+ parsedUri = `/webhooks/${webhookDocument.iid}`;
549
+ }
550
+ else {
551
+ parsedUri = uri.replace(encodedPath, elementsCore.slugify(name));
552
+ }
553
+ nodes.push({
554
+ type: types.NodeType.HttpWebhook,
555
+ uri: parsedUri,
556
+ data: webhookDocument,
557
+ name: webhookDocument.summary || webhookDocument.name,
558
+ tags: ((_b = webhookDocument.tags) === null || _b === void 0 ? void 0 : _b.map(tag => tag.name)) || [],
559
+ });
560
+ }
561
+ else if (match.type === NodeTypes.Model) {
562
+ const schemaDocument = get(document, jsonPath);
563
+ const parsedUri = uri.replace(OAS_MODEL_REGEXP, 'schemas/');
564
+ nodes.push({
565
+ type: types.NodeType.Model,
566
+ uri: parsedUri,
567
+ data: schemaDocument,
568
+ name: schemaDocument.title || last(uri.split('/')) || '',
569
+ tags: schemaDocument['x-tags'] || [],
570
+ });
571
+ }
572
+ if (match.children) {
573
+ nodes.push(...computeChildNodes(document, value, match.children, transformer, uri));
574
+ }
575
+ }
576
+ }
577
+ return nodes;
578
+ }
579
+ function findMapMatch(key, map) {
580
+ var _a;
581
+ if (typeof key === 'number')
582
+ return;
583
+ for (const entry of map) {
584
+ const escapedKey = key.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
585
+ if (!!((_a = entry.match) === null || _a === void 0 ? void 0 : _a.match(escapedKey)) || (entry.notMatch !== void 0 && !entry.notMatch.match(escapedKey))) {
586
+ return entry;
587
+ }
588
+ }
589
+ }
590
+ function isJson(value) {
591
+ try {
592
+ JSON.parse(value);
593
+ }
594
+ catch (e) {
595
+ return false;
596
+ }
597
+ return true;
593
598
  }
594
599
 
595
- function useExportDocumentProps({ originalDocument, bundledDocument, }) {
596
- const isJsonDocument = typeof originalDocument === 'object' || (!!originalDocument && isJson(originalDocument));
597
- const exportDocument = React__namespace.useCallback((document) => {
598
- const type = isJsonDocument ? 'json' : 'yaml';
599
- const blob = new Blob([document], {
600
- type: `application/${type}`,
601
- });
602
- saver__default["default"].saveAs(blob, `document.${type}`);
603
- }, [isJsonDocument]);
604
- const exportOriginalDocument = React__namespace.useCallback(() => {
605
- const stringifiedDocument = typeof originalDocument === 'object' ? JSON.stringify(originalDocument, null, 2) : originalDocument || '';
606
- exportDocument(stringifiedDocument);
607
- }, [originalDocument, exportDocument]);
608
- const exportBundledDocument = React__namespace.useCallback(() => {
609
- const stringifiedDocument = isJsonDocument
610
- ? JSON.stringify(bundledDocument, null, 2)
611
- : yaml.safeStringify(bundledDocument);
612
- exportDocument(stringifiedDocument);
613
- }, [bundledDocument, isJsonDocument, exportDocument]);
614
- return {
615
- original: {
616
- onPress: exportOriginalDocument,
617
- },
618
- bundled: {
619
- onPress: exportBundledDocument,
620
- },
621
- };
600
+ function useExportDocumentProps({ originalDocument, bundledDocument, }) {
601
+ const isJsonDocument = typeof originalDocument === 'object' || (!!originalDocument && isJson(originalDocument));
602
+ const exportDocument = React__namespace.useCallback((document) => {
603
+ const type = isJsonDocument ? 'json' : 'yaml';
604
+ const blob = new Blob([document], {
605
+ type: `application/${type}`,
606
+ });
607
+ saver.saveAs(blob, `document.${type}`);
608
+ }, [isJsonDocument]);
609
+ const exportOriginalDocument = React__namespace.useCallback(() => {
610
+ const stringifiedDocument = typeof originalDocument === 'object' ? JSON.stringify(originalDocument, null, 2) : originalDocument || '';
611
+ exportDocument(stringifiedDocument);
612
+ }, [originalDocument, exportDocument]);
613
+ const exportBundledDocument = React__namespace.useCallback(() => {
614
+ const stringifiedDocument = isJsonDocument
615
+ ? JSON.stringify(bundledDocument, null, 2)
616
+ : yaml.safeStringify(bundledDocument);
617
+ exportDocument(stringifiedDocument);
618
+ }, [bundledDocument, isJsonDocument, exportDocument]);
619
+ return {
620
+ original: {
621
+ onPress: exportOriginalDocument,
622
+ },
623
+ bundled: {
624
+ onPress: exportBundledDocument,
625
+ },
626
+ };
622
627
  }
623
628
 
624
- const propsAreWithDocument = (props) => {
625
- return props.hasOwnProperty('apiDescriptionDocument');
626
- };
627
- const APIImpl = props => {
628
- const { layout = 'sidebar', apiDescriptionUrl = '', logo, hideTryIt, hideSchemas, hideInternal, hideExport, tryItCredentialsPolicy, tryItCorsProxy, maxRefDepth, renderExtensionAddon, } = props;
629
- const location = reactRouterDom.useLocation();
630
- const apiDescriptionDocument = propsAreWithDocument(props) ? props.apiDescriptionDocument : undefined;
631
- const { isResponsiveLayoutEnabled } = elementsCore.useResponsiveLayout();
632
- const { data: fetchedDocument, error } = reactQuery.useQuery([apiDescriptionUrl], () => fetch(apiDescriptionUrl).then(res => {
633
- if (res.ok) {
634
- return res.text();
635
- }
636
- throw new Error(`Unable to load description document, status code: ${res.status}`);
637
- }), {
638
- enabled: apiDescriptionUrl !== '' && !apiDescriptionDocument,
639
- });
640
- const document = apiDescriptionDocument || fetchedDocument || '';
641
- const parsedDocument = elementsCore.useParsedValue(document);
642
- const bundledDocument = elementsCore.useBundleRefsIntoDocument(parsedDocument, { baseUrl: apiDescriptionUrl });
643
- const serviceNode = React__namespace.useMemo(() => transformOasToServiceNode(bundledDocument), [bundledDocument]);
644
- const exportProps = useExportDocumentProps({ originalDocument: document, bundledDocument });
645
- if (error) {
646
- return (React__namespace.createElement(mosaic.Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
647
- React__namespace.createElement(elementsCore.NonIdealState, { title: "Document could not be loaded", description: "The API description document could not be fetched. This could indicate connectivity problems, or issues with the server hosting the spec.", icon: "exclamation-triangle" })));
648
- }
649
- if (!bundledDocument) {
650
- return (React__namespace.createElement(mosaic.Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen", color: "light" },
651
- React__namespace.createElement(mosaic.Box, { as: mosaic.Icon, icon: ['fal', 'circle-notch'], size: "3x", spin: true })));
652
- }
653
- if (!serviceNode) {
654
- return (React__namespace.createElement(mosaic.Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
655
- React__namespace.createElement(elementsCore.NonIdealState, { title: "Failed to parse OpenAPI file", description: "Please make sure your OpenAPI file is valid and try again" })));
656
- }
657
- return (React__namespace.createElement(elementsCore.InlineRefResolverProvider, { document: parsedDocument, maxRefDepth: maxRefDepth },
658
- layout === 'stacked' && (React__namespace.createElement(APIWithStackedLayout, { serviceNode: serviceNode, hideTryIt: hideTryIt, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon, location: location })),
659
- layout === 'sidebar' && (React__namespace.createElement(APIWithSidebarLayout, { logo: logo, serviceNode: serviceNode, hideTryIt: hideTryIt, hideSchemas: hideSchemas, hideInternal: hideInternal, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon })),
660
- layout === 'responsive' && (React__namespace.createElement(APIWithResponsiveSidebarLayout, { logo: logo, serviceNode: serviceNode, hideTryIt: hideTryIt, hideSchemas: hideSchemas, hideInternal: hideInternal, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon, compact: isResponsiveLayoutEnabled }))));
661
- };
662
- const API = flow__default["default"](elementsCore.withRouter, elementsCore.withStyles, elementsCore.withPersistenceBoundary, elementsCore.withMosaicProvider, elementsCore.withQueryClientProvider)(APIImpl);
629
+ const propsAreWithDocument = (props) => {
630
+ return props.hasOwnProperty('apiDescriptionDocument');
631
+ };
632
+ const APIImpl = props => {
633
+ const { layout = 'sidebar', apiDescriptionUrl = '', logo, hideTryItPanel, hideTryIt, hideSamples, hideSecurityInfo, hideServerInfo, hideSchemas, hideInternal, hideExport, tryItCredentialsPolicy, tryItCorsProxy, maxRefDepth, renderExtensionAddon, } = props;
634
+ const location = reactRouterDom.useLocation();
635
+ const apiDescriptionDocument = propsAreWithDocument(props) ? props.apiDescriptionDocument : undefined;
636
+ const { isResponsiveLayoutEnabled } = elementsCore.useResponsiveLayout();
637
+ const { data: fetchedDocument, error } = reactQuery.useQuery([apiDescriptionUrl], () => fetch(apiDescriptionUrl).then(res => {
638
+ if (res.ok) {
639
+ return res.text();
640
+ }
641
+ throw new Error(`Unable to load description document, status code: ${res.status}`);
642
+ }), {
643
+ enabled: apiDescriptionUrl !== '' && !apiDescriptionDocument,
644
+ });
645
+ const document = apiDescriptionDocument || fetchedDocument || '';
646
+ const parsedDocument = elementsCore.useParsedValue(document);
647
+ const bundledDocument = elementsCore.useBundleRefsIntoDocument(parsedDocument, { baseUrl: apiDescriptionUrl });
648
+ const serviceNode = React__namespace.useMemo(() => transformOasToServiceNode(bundledDocument), [bundledDocument]);
649
+ const exportProps = useExportDocumentProps({ originalDocument: document, bundledDocument });
650
+ if (error) {
651
+ return (React__namespace.createElement(mosaic.Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
652
+ React__namespace.createElement(elementsCore.NonIdealState, { title: "Document could not be loaded", description: "The API description document could not be fetched. This could indicate connectivity problems, or issues with the server hosting the spec.", icon: "exclamation-triangle" })));
653
+ }
654
+ if (!bundledDocument) {
655
+ return (React__namespace.createElement(mosaic.Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen", color: "light" },
656
+ React__namespace.createElement(mosaic.Box, { as: mosaic.Icon, icon: ['fal', 'circle-notch'], size: "3x", spin: true })));
657
+ }
658
+ if (!serviceNode) {
659
+ return (React__namespace.createElement(mosaic.Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
660
+ React__namespace.createElement(elementsCore.NonIdealState, { title: "Failed to parse OpenAPI file", description: "Please make sure your OpenAPI file is valid and try again" })));
661
+ }
662
+ return (React__namespace.createElement(elementsCore.InlineRefResolverProvider, { document: parsedDocument, maxRefDepth: maxRefDepth },
663
+ layout === 'stacked' && (React__namespace.createElement(APIWithStackedLayout, { serviceNode: serviceNode, hideTryIt: hideTryIt, hideSamples: hideSamples, hideTryItPanel: hideTryItPanel, hideSecurityInfo: hideSecurityInfo, hideServerInfo: hideServerInfo, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon, location: location })),
664
+ layout === 'sidebar' && (React__namespace.createElement(APIWithSidebarLayout, { logo: logo, serviceNode: serviceNode, hideTryItPanel: hideTryItPanel, hideTryIt: hideTryIt, hideSamples: hideSamples, hideSecurityInfo: hideSecurityInfo, hideServerInfo: hideServerInfo, hideSchemas: hideSchemas, hideInternal: hideInternal, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon })),
665
+ layout === 'responsive' && (React__namespace.createElement(APIWithResponsiveSidebarLayout, { logo: logo, serviceNode: serviceNode, hideTryItPanel: hideTryItPanel, hideTryIt: hideTryIt, hideSamples: hideSamples, hideSecurityInfo: hideSecurityInfo, hideServerInfo: hideServerInfo, hideSchemas: hideSchemas, hideInternal: hideInternal, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon, compact: isResponsiveLayoutEnabled }))));
666
+ };
667
+ const API = flow(elementsCore.withRouter, elementsCore.withStyles, elementsCore.withPersistenceBoundary, elementsCore.withMosaicProvider, elementsCore.withQueryClientProvider)(APIImpl);
663
668
 
664
669
  exports.API = API;
665
670
  exports.APIWithStackedLayout = APIWithStackedLayout;