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