@stoplight/elements 8.3.2 → 8.3.4

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