@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.esm.js CHANGED
@@ -17,615 +17,632 @@ 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
+ hideTryItPanel: false,
176
+ hideSamples: false,
177
+ tryItCredentialsPolicy: 'omit',
178
+ });
179
+ TryItContext.displayName = 'TryItContext';
180
+ const LocationContext = React.createContext({
181
+ location: {
182
+ hash: '',
183
+ key: '',
184
+ pathname: '',
185
+ search: '',
186
+ state: '',
187
+ },
188
+ });
189
+ LocationContext.displayName = 'LocationContext';
190
+ const APIWithStackedLayout = ({ serviceNode, hideTryItPanel, hideTryIt, hideSamples, hideExport, hideSecurityInfo, hideServerInfo, exportProps, tryItCredentialsPolicy, tryItCorsProxy, renderExtensionAddon, showPoweredByLink = true, location, }) => {
191
+ const { groups: operationGroups } = computeTagGroups(serviceNode, NodeType.HttpOperation);
192
+ const { groups: webhookGroups } = computeTagGroups(serviceNode, NodeType.HttpWebhook);
193
+ return (React.createElement(LocationContext.Provider, { value: { location } },
194
+ React.createElement(TryItContext.Provider, { value: { hideTryItPanel, hideTryIt, hideSamples, tryItCredentialsPolicy, corsProxy: tryItCorsProxy } },
195
+ React.createElement(Flex, { w: "full", flexDirection: "col", m: "auto", className: "sl-max-w-4xl" },
196
+ React.createElement(Box, { w: "full", borderB: true },
197
+ 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 })),
198
+ operationGroups.length > 0 && webhookGroups.length > 0 ? React.createElement(Heading, { size: 2 }, "Endpoints") : null,
199
+ operationGroups.map(group => (React.createElement(Group, { key: group.title, group: group }))),
200
+ webhookGroups.length > 0 ? React.createElement(Heading, { size: 2 }, "Webhooks") : null,
201
+ webhookGroups.map(group => (React.createElement(Group, { key: group.title, group: group })))))));
202
+ };
203
+ APIWithStackedLayout.displayName = 'APIWithStackedLayout';
204
+ const Group = React.memo(({ group }) => {
205
+ const [isExpanded, setIsExpanded] = React.useState(false);
206
+ const scrollRef = React.useRef(null);
207
+ const { location: { hash }, } = React.useContext(LocationContext);
208
+ const urlHashMatches = hash.substr(1) === group.title;
209
+ const onClick = React.useCallback(() => setIsExpanded(!isExpanded), [isExpanded]);
210
+ const shouldExpand = React.useMemo(() => {
211
+ return urlHashMatches || group.items.some(item => itemMatchesHash(hash, item));
212
+ }, [group, hash, urlHashMatches]);
213
+ React.useEffect(() => {
214
+ var _a;
215
+ if (shouldExpand) {
216
+ setIsExpanded(true);
217
+ if (urlHashMatches && ((_a = scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current) === null || _a === void 0 ? void 0 : _a.offsetTop)) {
218
+ window.scrollTo(0, scrollRef.current.offsetTop);
219
+ }
220
+ }
221
+ }, [shouldExpand, urlHashMatches, group, hash]);
222
+ return (React.createElement(Box, null,
223
+ 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' } },
224
+ React.createElement(Box, { fontSize: "lg", fontWeight: "medium" }, group.title),
225
+ React.createElement(Icon, { className: "sl-mr-2", icon: isExpanded ? 'chevron-down' : 'chevron-right', size: "sm" })),
226
+ React.createElement(Collapse, { isOpen: isExpanded }, group.items.map(item => {
227
+ return React.createElement(Item, { key: item.uri, item: item });
228
+ }))));
229
+ });
230
+ Group.displayName = 'Group';
231
+ const Item = React.memo(({ item }) => {
232
+ const { location } = React.useContext(LocationContext);
233
+ const { hash } = location;
234
+ const [isExpanded, setIsExpanded] = React.useState(false);
235
+ const scrollRef = React.useRef(null);
236
+ const color = HttpMethodColors[item.data.method] || 'gray';
237
+ const isDeprecated = !!item.data.deprecated;
238
+ const { hideTryIt, hideSamples, hideTryItPanel, tryItCredentialsPolicy, corsProxy } = React.useContext(TryItContext);
239
+ const onClick = React.useCallback(() => setIsExpanded(!isExpanded), [isExpanded]);
240
+ React.useEffect(() => {
241
+ var _a;
242
+ if (itemMatchesHash(hash, item)) {
243
+ setIsExpanded(true);
244
+ if ((_a = scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current) === null || _a === void 0 ? void 0 : _a.offsetTop) {
245
+ window.scrollTo(0, scrollRef.current.offsetTop);
246
+ }
247
+ }
248
+ }, [hash, item]);
249
+ 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' } },
250
+ React.createElement(Flex, { mx: "auto", alignItems: "center", cursor: "pointer", fontSize: "lg", p: 2, onClick: onClick, color: "current" },
251
+ 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'),
252
+ React.createElement(Box, { flex: 1, fontWeight: "medium", wordBreak: "all" }, item.type === NodeType.HttpOperation ? item.data.path : item.name),
253
+ isDeprecated && React.createElement(DeprecatedBadge, null)),
254
+ React.createElement(Collapse, { isOpen: isExpanded },
255
+ React.createElement(Box, { flex: 1, p: 2, fontWeight: "medium", mx: "auto", fontSize: "xl" }, item.name),
256
+ hideTryItPanel ? (React.createElement(Box, { as: ParsedDocs, layoutOptions: { noHeading: true, hideTryItPanel: true, hideSamples, hideTryIt }, node: item, p: 4 })) : (React.createElement(Tabs, { appearance: "line" },
257
+ React.createElement(TabList, null,
258
+ React.createElement(Tab, null, "Docs"),
259
+ React.createElement(Tab, null, "TryIt")),
260
+ React.createElement(TabPanels, null,
261
+ React.createElement(TabPanel, null,
262
+ React.createElement(ParsedDocs, { className: "sl-px-4", node: item, location: location, layoutOptions: { noHeading: true, hideTryItPanel: false, hideSamples, hideTryIt } })),
263
+ React.createElement(TabPanel, null,
264
+ React.createElement(TryItWithRequestSamples, { httpOperation: item.data, tryItCredentialsPolicy: tryItCredentialsPolicy, corsProxy: corsProxy, hideSamples: hideSamples, hideTryIt: hideTryIt }))))))));
265
+ });
266
+ Item.displayName = 'Item';
267
+ const Collapse = ({ isOpen, children }) => {
268
+ if (!isOpen)
269
+ return null;
270
+ return React.createElement(Box, null, children);
271
+ };
270
272
  Collapse.displayName = 'Collapse';
271
273
 
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 })))));
274
+ const APIWithResponsiveSidebarLayout = ({ serviceNode, logo, hideTryItPanel, hideTryIt, hideSamples, compact, hideSchemas, hideInternal, hideExport, hideServerInfo, hideSecurityInfo, exportProps, tryItCredentialsPolicy, tryItCorsProxy, renderExtensionAddon, }) => {
275
+ const container = React.useRef(null);
276
+ const tree = React.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
277
+ const location = useLocation();
278
+ const { pathname } = location;
279
+ const isRootPath = !pathname || pathname === '/';
280
+ const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
281
+ const layoutOptions = React.useMemo(() => ({
282
+ hideTryIt: hideTryIt,
283
+ hideTryItPanel,
284
+ hideSamples,
285
+ hideSecurityInfo: hideSecurityInfo,
286
+ hideServerInfo: hideServerInfo,
287
+ compact: compact,
288
+ hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== NodeType.HttpService,
289
+ }), [hideTryIt, hideSecurityInfo, hideServerInfo, compact, hideExport, hideTryItPanel, hideSamples, node === null || node === void 0 ? void 0 : node.type]);
290
+ if (!node) {
291
+ const firstSlug = findFirstNodeSlug(tree);
292
+ if (firstSlug) {
293
+ return React.createElement(Redirect, { to: firstSlug });
294
+ }
295
+ }
296
+ if (hideInternal && node && isInternal(node)) {
297
+ return React.createElement(Redirect, { to: "/" });
298
+ }
299
+ const handleTocClick = () => {
300
+ if (container.current) {
301
+ container.current.scrollIntoView();
302
+ }
303
+ };
304
+ 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 },
305
+ 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
306
  };
297
307
 
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
- };
308
+ const APIWithSidebarLayout = ({ serviceNode, logo, hideTryItPanel, hideTryIt, hideSamples, hideSchemas, hideSecurityInfo, hideServerInfo, hideInternal, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, renderExtensionAddon, }) => {
309
+ const container = React.useRef(null);
310
+ const tree = React.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
311
+ const location = useLocation();
312
+ const { pathname } = location;
313
+ const isRootPath = !pathname || pathname === '/';
314
+ const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
315
+ const layoutOptions = React.useMemo(() => ({
316
+ hideTryIt: hideTryIt,
317
+ hideTryItPanel,
318
+ hideSamples,
319
+ hideServerInfo: hideServerInfo,
320
+ hideSecurityInfo: hideSecurityInfo,
321
+ hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== NodeType.HttpService,
322
+ }), [hideTryIt, hideServerInfo, hideSecurityInfo, hideExport, hideTryItPanel, hideSamples, node === null || node === void 0 ? void 0 : node.type]);
323
+ if (!node) {
324
+ const firstSlug = findFirstNodeSlug(tree);
325
+ if (firstSlug) {
326
+ return React.createElement(Redirect, { to: firstSlug });
327
+ }
328
+ }
329
+ if (hideInternal && node && isInternal(node)) {
330
+ return React.createElement(Redirect, { to: "/" });
331
+ }
332
+ const sidebar = (React.createElement(Sidebar, { serviceNode: serviceNode, logo: logo, container: container, pathname: pathname, tree: tree }));
333
+ return (React.createElement(SidebarLayout, { ref: container, sidebar: sidebar }, node && (React.createElement(ElementsOptionsProvider, { renderExtensionAddon: renderExtensionAddon },
334
+ React.createElement(ParsedDocs, { key: pathname, uri: pathname, node: node, nodeTitle: node.name, layoutOptions: layoutOptions, location: location, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon })))));
335
+ };
336
+ const Sidebar = ({ serviceNode, logo, container, pathname, tree }) => {
337
+ const handleTocClick = () => {
338
+ if (container.current) {
339
+ container.current.scrollIntoView();
340
+ }
341
+ };
342
+ return (React.createElement(React.Fragment, null,
343
+ React.createElement(Flex, { ml: 4, mb: 5, alignItems: "center" },
344
+ logo ? (React.createElement(Logo, { logo: { url: logo, altText: 'logo' } })) : (serviceNode.data.logo && React.createElement(Logo, { logo: serviceNode.data.logo })),
345
+ React.createElement(Heading, { size: 4 }, serviceNode.name)),
346
+ React.createElement(Flex, { flexGrow: true, flexShrink: true, overflowY: "auto", direction: "col" },
347
+ React.createElement(TableOfContents, { tree: tree, activeId: pathname, Link: Link, onLinkClick: handleTocClick })),
348
+ React.createElement(PoweredByLink, { source: serviceNode.name, pathname: pathname, packageType: "elements" })));
349
+ };
333
350
  Sidebar.displayName = 'Sidebar';
334
351
 
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";
352
+ var NodeTypes;
353
+ (function (NodeTypes) {
354
+ NodeTypes["Paths"] = "paths";
355
+ NodeTypes["Path"] = "path";
356
+ NodeTypes["Operation"] = "operation";
357
+ NodeTypes["Webhooks"] = "webhooks";
358
+ NodeTypes["Webhook"] = "webhook";
359
+ NodeTypes["Components"] = "components";
360
+ NodeTypes["Models"] = "models";
361
+ NodeTypes["Model"] = "model";
345
362
  })(NodeTypes || (NodeTypes = {}));
346
363
 
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
- },
364
+ const oas2SourceMap = [
365
+ {
366
+ match: 'paths',
367
+ type: NodeTypes.Paths,
368
+ children: [
369
+ {
370
+ notMatch: '^x-',
371
+ type: NodeTypes.Path,
372
+ children: [
373
+ {
374
+ match: 'get|post|put|delete|options|head|patch|trace',
375
+ type: NodeTypes.Operation,
376
+ },
377
+ ],
378
+ },
379
+ ],
380
+ },
381
+ {
382
+ match: 'definitions',
383
+ type: NodeTypes.Models,
384
+ children: [
385
+ {
386
+ notMatch: '^x-',
387
+ type: NodeTypes.Model,
388
+ },
389
+ ],
390
+ },
374
391
  ];
375
392
 
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
- },
393
+ const oas3SourceMap = [
394
+ {
395
+ match: 'paths',
396
+ type: NodeTypes.Paths,
397
+ children: [
398
+ {
399
+ notMatch: '^x-',
400
+ type: NodeTypes.Path,
401
+ children: [
402
+ {
403
+ match: 'get|post|put|delete|options|head|patch|trace',
404
+ type: NodeTypes.Operation,
405
+ },
406
+ ],
407
+ },
408
+ ],
409
+ },
410
+ {
411
+ match: 'webhooks',
412
+ type: NodeTypes.Webhooks,
413
+ children: [
414
+ {
415
+ notMatch: '^x-',
416
+ type: NodeTypes.Webhook,
417
+ children: [
418
+ {
419
+ match: 'get|post|put|delete|options|head|patch|trace',
420
+ type: NodeTypes.Webhook,
421
+ },
422
+ ],
423
+ },
424
+ ],
425
+ },
426
+ {
427
+ match: 'components',
428
+ type: NodeTypes.Components,
429
+ children: [
430
+ {
431
+ match: 'schemas',
432
+ type: NodeTypes.Models,
433
+ children: [
434
+ {
435
+ notMatch: '^x-',
436
+ type: NodeTypes.Model,
437
+ },
438
+ ],
439
+ },
440
+ ],
441
+ },
425
442
  ];
426
443
 
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;
444
+ const isOas2 = (parsed) => isObject(parsed) &&
445
+ 'swagger' in parsed &&
446
+ Number.parseInt(String(parsed.swagger)) === 2;
447
+ const isOas3 = (parsed) => isObject(parsed) &&
448
+ 'openapi' in parsed &&
449
+ Number.parseFloat(String(parsed.openapi)) >= 3;
450
+ const isOas31 = (parsed) => isObject(parsed) &&
451
+ 'openapi' in parsed &&
452
+ Number.parseFloat(String(parsed.openapi)) === 3.1;
453
+ const OAS_MODEL_REGEXP = /((definitions|components)\/?(schemas)?)\//;
454
+ function transformOasToServiceNode(apiDescriptionDocument) {
455
+ if (isOas31(apiDescriptionDocument)) {
456
+ return computeServiceNode(Object.assign(Object.assign({}, apiDescriptionDocument), { jsonSchemaDialect: 'http://json-schema.org/draft-07/schema#' }), oas3SourceMap, transformOas3Service, transformOas3Operation);
457
+ }
458
+ if (isOas3(apiDescriptionDocument)) {
459
+ return computeServiceNode(apiDescriptionDocument, oas3SourceMap, transformOas3Service, transformOas3Operation);
460
+ }
461
+ else if (isOas2(apiDescriptionDocument)) {
462
+ return computeServiceNode(apiDescriptionDocument, oas2SourceMap, transformOas2Service, transformOas2Operation);
463
+ }
464
+ return null;
465
+ }
466
+ function computeServiceNode(document, map, transformService, transformOperation) {
467
+ var _a;
468
+ const serviceDocument = transformService({ document });
469
+ const serviceNode = {
470
+ type: NodeType.HttpService,
471
+ uri: '/',
472
+ name: serviceDocument.name,
473
+ data: serviceDocument,
474
+ tags: ((_a = serviceDocument.tags) === null || _a === void 0 ? void 0 : _a.map(tag => tag.name)) || [],
475
+ children: computeChildNodes(document, document, map, transformOperation),
476
+ };
477
+ return serviceNode;
478
+ }
479
+ function computeChildNodes(document, data, map, transformer, parentUri = '') {
480
+ var _a, _b;
481
+ const nodes = [];
482
+ if (!isObject(data))
483
+ return nodes;
484
+ for (const [key, value] of Object.entries(data)) {
485
+ const sanitizedKey = encodePointerFragment(key);
486
+ const match = findMapMatch(sanitizedKey, map);
487
+ if (match) {
488
+ const uri = `${parentUri}/${sanitizedKey}`;
489
+ const jsonPath = pointerToPath(`#${uri}`);
490
+ if (match.type === NodeTypes.Operation && jsonPath.length === 3) {
491
+ const path = String(jsonPath[1]);
492
+ const method = String(jsonPath[2]);
493
+ const operationDocument = transformer({
494
+ document,
495
+ name: path,
496
+ method,
497
+ config: OPERATION_CONFIG,
498
+ });
499
+ let parsedUri;
500
+ const encodedPath = String(encodePointerFragment(path));
501
+ if (operationDocument.iid) {
502
+ parsedUri = `/operations/${operationDocument.iid}`;
503
+ }
504
+ else {
505
+ parsedUri = uri.replace(encodedPath, slugify(path));
506
+ }
507
+ nodes.push({
508
+ type: NodeType.HttpOperation,
509
+ uri: parsedUri,
510
+ data: operationDocument,
511
+ name: operationDocument.summary || operationDocument.iid || operationDocument.path,
512
+ tags: ((_a = operationDocument.tags) === null || _a === void 0 ? void 0 : _a.map(tag => tag.name)) || [],
513
+ });
514
+ }
515
+ else if (match.type === NodeTypes.Webhook && jsonPath.length === 3) {
516
+ const name = String(jsonPath[1]);
517
+ const method = String(jsonPath[2]);
518
+ const webhookDocument = transformer({
519
+ document,
520
+ name,
521
+ method,
522
+ config: WEBHOOK_CONFIG,
523
+ });
524
+ let parsedUri;
525
+ const encodedPath = String(encodePointerFragment(name));
526
+ if (webhookDocument.iid) {
527
+ parsedUri = `/webhooks/${webhookDocument.iid}`;
528
+ }
529
+ else {
530
+ parsedUri = uri.replace(encodedPath, slugify(name));
531
+ }
532
+ nodes.push({
533
+ type: NodeType.HttpWebhook,
534
+ uri: parsedUri,
535
+ data: webhookDocument,
536
+ name: webhookDocument.summary || webhookDocument.name,
537
+ tags: ((_b = webhookDocument.tags) === null || _b === void 0 ? void 0 : _b.map(tag => tag.name)) || [],
538
+ });
539
+ }
540
+ else if (match.type === NodeTypes.Model) {
541
+ const schemaDocument = get(document, jsonPath);
542
+ const parsedUri = uri.replace(OAS_MODEL_REGEXP, 'schemas/');
543
+ nodes.push({
544
+ type: NodeType.Model,
545
+ uri: parsedUri,
546
+ data: schemaDocument,
547
+ name: schemaDocument.title || last(uri.split('/')) || '',
548
+ tags: schemaDocument['x-tags'] || [],
549
+ });
550
+ }
551
+ if (match.children) {
552
+ nodes.push(...computeChildNodes(document, value, match.children, transformer, uri));
553
+ }
554
+ }
555
+ }
556
+ return nodes;
557
+ }
558
+ function findMapMatch(key, map) {
559
+ var _a;
560
+ if (typeof key === 'number')
561
+ return;
562
+ for (const entry of map) {
563
+ const escapedKey = key.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
564
+ if (!!((_a = entry.match) === null || _a === void 0 ? void 0 : _a.match(escapedKey)) || (entry.notMatch !== void 0 && !entry.notMatch.match(escapedKey))) {
565
+ return entry;
566
+ }
567
+ }
568
+ }
569
+ function isJson(value) {
570
+ try {
571
+ JSON.parse(value);
572
+ }
573
+ catch (e) {
574
+ return false;
575
+ }
576
+ return true;
560
577
  }
561
578
 
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
- };
579
+ function useExportDocumentProps({ originalDocument, bundledDocument, }) {
580
+ const isJsonDocument = typeof originalDocument === 'object' || (!!originalDocument && isJson(originalDocument));
581
+ const exportDocument = React.useCallback((document) => {
582
+ const type = isJsonDocument ? 'json' : 'yaml';
583
+ const blob = new Blob([document], {
584
+ type: `application/${type}`,
585
+ });
586
+ saver.saveAs(blob, `document.${type}`);
587
+ }, [isJsonDocument]);
588
+ const exportOriginalDocument = React.useCallback(() => {
589
+ const stringifiedDocument = typeof originalDocument === 'object' ? JSON.stringify(originalDocument, null, 2) : originalDocument || '';
590
+ exportDocument(stringifiedDocument);
591
+ }, [originalDocument, exportDocument]);
592
+ const exportBundledDocument = React.useCallback(() => {
593
+ const stringifiedDocument = isJsonDocument
594
+ ? JSON.stringify(bundledDocument, null, 2)
595
+ : safeStringify(bundledDocument);
596
+ exportDocument(stringifiedDocument);
597
+ }, [bundledDocument, isJsonDocument, exportDocument]);
598
+ return {
599
+ original: {
600
+ onPress: exportOriginalDocument,
601
+ },
602
+ bundled: {
603
+ onPress: exportBundledDocument,
604
+ },
605
+ };
589
606
  }
590
607
 
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
- };
608
+ const propsAreWithDocument = (props) => {
609
+ return props.hasOwnProperty('apiDescriptionDocument');
610
+ };
611
+ const APIImpl = props => {
612
+ const { layout = 'sidebar', apiDescriptionUrl = '', logo, hideTryItPanel, hideTryIt, hideSamples, hideSecurityInfo, hideServerInfo, hideSchemas, hideInternal, hideExport, tryItCredentialsPolicy, tryItCorsProxy, maxRefDepth, renderExtensionAddon, } = props;
613
+ const location = useLocation();
614
+ const apiDescriptionDocument = propsAreWithDocument(props) ? props.apiDescriptionDocument : undefined;
615
+ const { isResponsiveLayoutEnabled } = useResponsiveLayout();
616
+ const { data: fetchedDocument, error } = useQuery([apiDescriptionUrl], () => fetch(apiDescriptionUrl).then(res => {
617
+ if (res.ok) {
618
+ return res.text();
619
+ }
620
+ throw new Error(`Unable to load description document, status code: ${res.status}`);
621
+ }), {
622
+ enabled: apiDescriptionUrl !== '' && !apiDescriptionDocument,
623
+ });
624
+ const document = apiDescriptionDocument || fetchedDocument || '';
625
+ const parsedDocument = useParsedValue(document);
626
+ const bundledDocument = useBundleRefsIntoDocument(parsedDocument, { baseUrl: apiDescriptionUrl });
627
+ const serviceNode = React.useMemo(() => transformOasToServiceNode(bundledDocument), [bundledDocument]);
628
+ const exportProps = useExportDocumentProps({ originalDocument: document, bundledDocument });
629
+ if (error) {
630
+ return (React.createElement(Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
631
+ 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" })));
632
+ }
633
+ if (!bundledDocument) {
634
+ return (React.createElement(Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen", color: "light" },
635
+ React.createElement(Box, { as: Icon, icon: ['fal', 'circle-notch'], size: "3x", spin: true })));
636
+ }
637
+ if (!serviceNode) {
638
+ return (React.createElement(Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
639
+ React.createElement(NonIdealState, { title: "Failed to parse OpenAPI file", description: "Please make sure your OpenAPI file is valid and try again" })));
640
+ }
641
+ return (React.createElement(InlineRefResolverProvider, { document: parsedDocument, maxRefDepth: maxRefDepth },
642
+ layout === 'stacked' && (React.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 })),
643
+ layout === 'sidebar' && (React.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 })),
644
+ layout === 'responsive' && (React.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 }))));
645
+ };
629
646
  const API = flow(withRouter, withStyles, withPersistenceBoundary, withMosaicProvider, withQueryClientProvider)(APIImpl);
630
647
 
631
648
  export { API, APIWithStackedLayout, transformOasToServiceNode, useExportDocumentProps };