@jpmorganchase/elemental 7.0.1 → 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 +6 -0
- package/components/API/APIWithSidebarLayout.d.ts +6 -0
- package/components/API/APIWithStackedLayout.d.ts +5 -1
- package/components/API/utils.d.ts +1 -0
- package/containers/API.d.ts +5 -0
- package/containers/API.spec.d.ts +0 -2
- package/index.esm.js +653 -624
- package/index.js +667 -650
- package/index.mjs +653 -624
- package/package.json +4 -4
- package/styles.min.css +1 -1
- package/web-components.min.js +1 -1
- package/web-components.min.js.LICENSE.txt +34 -25
package/index.esm.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { isHttpOperation, isHttpWebhookOperation, isHttpService, HttpMethodColors, DeprecatedBadge, ParsedDocs, TryItWithRequestSamples, Docs, ResponsiveSidebarLayout, ElementsOptionsProvider, SidebarLayout, Logo, TableOfContents, PoweredByLink, slugify, withRouter, withStyles, withPersistenceBoundary, withMosaicProvider, withQueryClientProvider, useResponsiveLayout, useParsedValue, useBundleRefsIntoDocument, NonIdealState, InlineRefResolverProvider } from '@jpmorganchase/elemental-core';
|
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
2
|
import { Box, Flex, Icon, Tabs, TabList, Tab, TabPanels, TabPanel, Heading } from '@stoplight/mosaic';
|
3
3
|
import { NodeType } from '@stoplight/types';
|
4
4
|
import cn from 'classnames';
|
@@ -6,7 +6,7 @@ import * as React from 'react';
|
|
6
6
|
import defaults from 'lodash/defaults.js';
|
7
7
|
import flow from 'lodash/flow.js';
|
8
8
|
import { useQuery } from 'react-query';
|
9
|
-
import { useLocation,
|
9
|
+
import { useLocation, Navigate, Link } from 'react-router-dom';
|
10
10
|
import { safeStringify } from '@stoplight/yaml';
|
11
11
|
import saver from 'file-saver';
|
12
12
|
import { OPERATION_CONFIG, WEBHOOK_CONFIG } from '@stoplight/http-spec/oas';
|
@@ -17,648 +17,677 @@ 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
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
const
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
.
|
47
|
-
const
|
48
|
-
const
|
49
|
-
const
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
}
|
66
|
-
const
|
67
|
-
const
|
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
|
-
const
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
const
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
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
|
+
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, '') : '/';
|
163
170
|
};
|
164
171
|
|
165
|
-
const itemUriMatchesPathname = (itemUri, pathname) => itemUri === pathname;
|
166
|
-
const TryItContext = React.createContext({
|
167
|
-
hideTryIt: false,
|
168
|
-
|
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
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
},
|
208
|
-
React.
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
})
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
const
|
228
|
-
const
|
229
|
-
const
|
230
|
-
const
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
React.createElement(
|
250
|
-
React.createElement(Box, {
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
React.createElement(
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
}
|
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);
|
277
|
+
};
|
267
278
|
Collapse.displayName = 'Collapse';
|
268
279
|
|
269
|
-
const APIWithResponsiveSidebarLayout = ({ serviceNode, logo, hideTryIt, compact, hideSchemas, hideInternal, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, renderExtensionAddon, }) => {
|
270
|
-
const container = React.useRef(null);
|
271
|
-
const tree = React.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
|
272
|
-
const location = useLocation();
|
273
|
-
const { pathname } = location;
|
274
|
-
const
|
275
|
-
const
|
276
|
-
const
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
}
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
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 })))));
|
293
313
|
};
|
294
314
|
|
295
|
-
const APIWithSidebarLayout = ({ serviceNode, logo, hideTryIt, hideSchemas, hideInternal, hideExport, hideInlineExamples = false, exportProps, tryItCredentialsPolicy, tryItCorsProxy, renderExtensionAddon, tryItOutDefaultServer, useCustomNav, layout, }) => {
|
296
|
-
const container = React.useRef(null);
|
297
|
-
const tree = React.useMemo(() => {
|
298
|
-
if (!useCustomNav)
|
299
|
-
return computeAPITree(serviceNode, { hideSchemas, hideInternal });
|
300
|
-
else
|
301
|
-
return [];
|
302
|
-
}, [serviceNode, hideSchemas, hideInternal, useCustomNav]);
|
303
|
-
const location = useLocation();
|
304
|
-
const { pathname } = location;
|
305
|
-
const
|
306
|
-
const
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
}
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
};
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
};
|
329
|
-
return (React.createElement(React.
|
330
|
-
React.createElement(
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
}
|
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" })));
|
365
|
+
};
|
337
366
|
Sidebar.displayName = 'Sidebar';
|
338
367
|
|
339
|
-
var NodeTypes;
|
340
|
-
(function (NodeTypes) {
|
341
|
-
NodeTypes["Paths"] = "paths";
|
342
|
-
NodeTypes["Path"] = "path";
|
343
|
-
NodeTypes["Operation"] = "operation";
|
344
|
-
NodeTypes["Webhooks"] = "webhooks";
|
345
|
-
NodeTypes["Webhook"] = "webhook";
|
346
|
-
NodeTypes["Components"] = "components";
|
347
|
-
NodeTypes["Models"] = "models";
|
348
|
-
NodeTypes["Model"] = "model";
|
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";
|
349
378
|
})(NodeTypes || (NodeTypes = {}));
|
350
379
|
|
351
|
-
const oas2SourceMap = [
|
352
|
-
{
|
353
|
-
match: 'paths',
|
354
|
-
type: NodeTypes.Paths,
|
355
|
-
children: [
|
356
|
-
{
|
357
|
-
notMatch: '^x-',
|
358
|
-
type: NodeTypes.Path,
|
359
|
-
children: [
|
360
|
-
{
|
361
|
-
match: 'get|post|put|delete|options|head|patch|trace',
|
362
|
-
type: NodeTypes.Operation,
|
363
|
-
},
|
364
|
-
],
|
365
|
-
},
|
366
|
-
],
|
367
|
-
},
|
368
|
-
{
|
369
|
-
match: 'definitions',
|
370
|
-
type: NodeTypes.Models,
|
371
|
-
children: [
|
372
|
-
{
|
373
|
-
notMatch: '^x-',
|
374
|
-
type: NodeTypes.Model,
|
375
|
-
},
|
376
|
-
],
|
377
|
-
},
|
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
|
+
},
|
378
407
|
];
|
379
408
|
|
380
|
-
const oas3SourceMap = [
|
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: 'webhooks',
|
399
|
-
type: NodeTypes.Webhooks,
|
400
|
-
children: [
|
401
|
-
{
|
402
|
-
notMatch: '^x-',
|
403
|
-
type: NodeTypes.Webhook,
|
404
|
-
children: [
|
405
|
-
{
|
406
|
-
match: 'get|post|put|delete|options|head|patch|trace',
|
407
|
-
type: NodeTypes.Webhook,
|
408
|
-
},
|
409
|
-
],
|
410
|
-
},
|
411
|
-
],
|
412
|
-
},
|
413
|
-
{
|
414
|
-
match: 'components',
|
415
|
-
type: NodeTypes.Components,
|
416
|
-
children: [
|
417
|
-
{
|
418
|
-
match: 'schemas',
|
419
|
-
type: NodeTypes.Models,
|
420
|
-
children: [
|
421
|
-
{
|
422
|
-
notMatch: '^x-',
|
423
|
-
type: NodeTypes.Model,
|
424
|
-
},
|
425
|
-
],
|
426
|
-
},
|
427
|
-
],
|
428
|
-
},
|
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
|
+
},
|
429
458
|
];
|
430
459
|
|
431
|
-
const isOas2 = (parsed) => isObject(parsed) &&
|
432
|
-
'swagger' in parsed &&
|
433
|
-
Number.parseInt(String(parsed.swagger)) === 2;
|
434
|
-
const isOas3 = (parsed) => isObject(parsed) &&
|
435
|
-
'openapi' in parsed &&
|
436
|
-
Number.parseFloat(String(parsed.openapi)) >= 3;
|
437
|
-
const isOas31 = (parsed) => isObject(parsed) &&
|
438
|
-
'openapi' in parsed &&
|
439
|
-
Number.parseFloat(String(parsed.openapi)) === 3.1;
|
440
|
-
const OAS_MODEL_REGEXP = /((definitions|components)\/?(schemas)?)\//;
|
441
|
-
function transformOasToServiceNode(apiDescriptionDocument) {
|
442
|
-
if (isOas31(apiDescriptionDocument)) {
|
443
|
-
return computeServiceNode(Object.assign(Object.assign({}, apiDescriptionDocument), { jsonSchemaDialect: 'http://json-schema.org/draft-07/schema#' }), oas3SourceMap, transformOas3Service, transformOas3Operation);
|
444
|
-
}
|
445
|
-
if (isOas3(apiDescriptionDocument)) {
|
446
|
-
return computeServiceNode(apiDescriptionDocument, oas3SourceMap, transformOas3Service, transformOas3Operation);
|
447
|
-
}
|
448
|
-
else if (isOas2(apiDescriptionDocument)) {
|
449
|
-
return computeServiceNode(apiDescriptionDocument, oas2SourceMap, transformOas2Service, transformOas2Operation);
|
450
|
-
}
|
451
|
-
return null;
|
452
|
-
}
|
453
|
-
function computeServiceNode(document, map, transformService, transformOperation) {
|
454
|
-
var _a;
|
455
|
-
const serviceDocument = transformService({ document });
|
456
|
-
const serviceNode = {
|
457
|
-
type: NodeType.HttpService,
|
458
|
-
uri: '/',
|
459
|
-
name: serviceDocument.name,
|
460
|
-
data: serviceDocument,
|
461
|
-
tags: ((_a = serviceDocument.tags) === null || _a === void 0 ? void 0 : _a.map(tag => tag.name)) || [],
|
462
|
-
children: computeChildNodes(document, document, map, transformOperation),
|
463
|
-
};
|
464
|
-
return serviceNode;
|
465
|
-
}
|
466
|
-
function computeChildNodes(document, data, map, transformer, parentUri = '') {
|
467
|
-
var _a, _b;
|
468
|
-
const nodes = [];
|
469
|
-
if (!isObject(data))
|
470
|
-
return nodes;
|
471
|
-
for (const key of Object.
|
472
|
-
const sanitizedKey = encodePointerFragment(key);
|
473
|
-
const match = findMapMatch(sanitizedKey, map);
|
474
|
-
if (match) {
|
475
|
-
const uri = `${parentUri}/${sanitizedKey}`;
|
476
|
-
const jsonPath = pointerToPath(`#${uri}`);
|
477
|
-
if (match.type === NodeTypes.Operation && jsonPath.length === 3) {
|
478
|
-
const path = String(jsonPath[1]);
|
479
|
-
const method = String(jsonPath[2]);
|
480
|
-
const operationDocument = transformer({
|
481
|
-
document,
|
482
|
-
name: path,
|
483
|
-
method,
|
484
|
-
config: OPERATION_CONFIG,
|
485
|
-
});
|
486
|
-
let parsedUri;
|
487
|
-
const encodedPath = String(encodePointerFragment(path));
|
488
|
-
if (operationDocument.iid) {
|
489
|
-
parsedUri = `/operations/${operationDocument.iid}`;
|
490
|
-
}
|
491
|
-
else {
|
492
|
-
parsedUri = uri.replace(encodedPath, slugify(path));
|
493
|
-
}
|
494
|
-
nodes.push({
|
495
|
-
type: NodeType.HttpOperation,
|
496
|
-
uri: parsedUri,
|
497
|
-
data: operationDocument,
|
498
|
-
name: operationDocument.summary || operationDocument.iid || operationDocument.path,
|
499
|
-
tags: ((_a = operationDocument.tags) === null || _a === void 0 ? void 0 : _a.map(tag => tag.name)) || [],
|
500
|
-
});
|
501
|
-
}
|
502
|
-
else if (match.type === NodeTypes.Webhook && jsonPath.length === 3) {
|
503
|
-
const name = String(jsonPath[1]);
|
504
|
-
const method = String(jsonPath[2]);
|
505
|
-
const webhookDocument = transformer({
|
506
|
-
document,
|
507
|
-
name,
|
508
|
-
method,
|
509
|
-
config: WEBHOOK_CONFIG,
|
510
|
-
});
|
511
|
-
let parsedUri;
|
512
|
-
const encodedPath = String(encodePointerFragment(name));
|
513
|
-
if (webhookDocument.iid) {
|
514
|
-
parsedUri = `/webhooks/${webhookDocument.iid}`;
|
515
|
-
}
|
516
|
-
else {
|
517
|
-
parsedUri = uri.replace(encodedPath, slugify(name));
|
518
|
-
}
|
519
|
-
nodes.push({
|
520
|
-
type: NodeType.HttpWebhook,
|
521
|
-
uri: parsedUri,
|
522
|
-
data: webhookDocument,
|
523
|
-
name: webhookDocument.summary || webhookDocument.name,
|
524
|
-
tags: ((_b = webhookDocument.tags) === null || _b === void 0 ? void 0 : _b.map(tag => tag.name)) || [],
|
525
|
-
});
|
526
|
-
}
|
527
|
-
else if (match.type === NodeTypes.Model) {
|
528
|
-
const schemaDocument = get(document, jsonPath);
|
529
|
-
const parsedUri = uri.replace(OAS_MODEL_REGEXP, 'schemas/');
|
530
|
-
nodes.push({
|
531
|
-
type: NodeType.Model,
|
532
|
-
uri: parsedUri,
|
533
|
-
data: schemaDocument,
|
534
|
-
name: schemaDocument.title || last(uri.split('/')) || '',
|
535
|
-
tags: schemaDocument['x-tags'] || [],
|
536
|
-
});
|
537
|
-
}
|
538
|
-
if (match.children) {
|
539
|
-
nodes.push(...computeChildNodes(document,
|
540
|
-
}
|
541
|
-
}
|
542
|
-
}
|
543
|
-
return nodes;
|
544
|
-
}
|
545
|
-
function findMapMatch(key, map) {
|
546
|
-
var _a;
|
547
|
-
if (typeof key === 'number')
|
548
|
-
return;
|
549
|
-
for (const entry of map) {
|
550
|
-
const escapedKey = key.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
|
551
|
-
if (!!((_a = entry.match) === null || _a === void 0 ? void 0 : _a.match(escapedKey)) || (entry.notMatch !== void 0 && !entry.notMatch.match(escapedKey))) {
|
552
|
-
return entry;
|
553
|
-
}
|
554
|
-
}
|
555
|
-
}
|
556
|
-
function isJson(value) {
|
557
|
-
try {
|
558
|
-
JSON.parse(value);
|
559
|
-
}
|
560
|
-
catch (e) {
|
561
|
-
return false;
|
562
|
-
}
|
563
|
-
return true;
|
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;
|
564
593
|
}
|
565
594
|
|
566
|
-
function useExportDocumentProps({ originalDocument, bundledDocument, }) {
|
567
|
-
const isJsonDocument = typeof originalDocument === 'object' || (!!originalDocument && isJson(originalDocument));
|
568
|
-
const exportDocument = React.useCallback((document) => {
|
569
|
-
const type = isJsonDocument ? 'json' : 'yaml';
|
570
|
-
const blob = new Blob([document], {
|
571
|
-
type: `application/${type}`,
|
572
|
-
});
|
573
|
-
saver.saveAs(blob, `document.${type}`);
|
574
|
-
}, [isJsonDocument]);
|
575
|
-
const exportOriginalDocument = React.useCallback(() => {
|
576
|
-
const stringifiedDocument = typeof originalDocument === 'object' ? JSON.stringify(originalDocument, null, 2) : originalDocument || '';
|
577
|
-
exportDocument(stringifiedDocument);
|
578
|
-
}, [originalDocument, exportDocument]);
|
579
|
-
const exportBundledDocument = React.useCallback(() => {
|
580
|
-
const stringifiedDocument = isJsonDocument
|
581
|
-
? JSON.stringify(bundledDocument, null, 2)
|
582
|
-
: safeStringify(bundledDocument);
|
583
|
-
exportDocument(stringifiedDocument);
|
584
|
-
}, [bundledDocument, isJsonDocument, exportDocument]);
|
585
|
-
return {
|
586
|
-
original: {
|
587
|
-
onPress: exportOriginalDocument,
|
588
|
-
},
|
589
|
-
bundled: {
|
590
|
-
onPress: exportBundledDocument,
|
591
|
-
},
|
592
|
-
};
|
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
|
+
};
|
593
622
|
}
|
594
623
|
|
595
|
-
const propsAreWithDocument = (props) => {
|
596
|
-
return props.hasOwnProperty('apiDescriptionDocument');
|
597
|
-
};
|
598
|
-
const APIImpl = props => {
|
599
|
-
const { layout = 'sidebar', apiDescriptionUrl = '', logo, hideTryIt, hideSchemas, hideInternal, hideExport, hideInlineExamples, tryItCredentialsPolicy, tryItCorsProxy, maxRefDepth, renderExtensionAddon, tryItOutDefaultServer, useCustomNav, } = props;
|
600
|
-
const location = useLocation();
|
601
|
-
const apiDescriptionDocument = propsAreWithDocument(props) ? props.apiDescriptionDocument : undefined;
|
602
|
-
const { isResponsiveLayoutEnabled } = useResponsiveLayout();
|
603
|
-
const { data: fetchedDocument, error } = useQuery([apiDescriptionUrl], () => fetch(apiDescriptionUrl).then(res => {
|
604
|
-
if (res.ok) {
|
605
|
-
return res.text();
|
606
|
-
}
|
607
|
-
throw new Error(`Unable to load description document, status code: ${res.status}`);
|
608
|
-
}), {
|
609
|
-
enabled: apiDescriptionUrl !== '' && !apiDescriptionDocument,
|
610
|
-
});
|
611
|
-
const document = apiDescriptionDocument || fetchedDocument || '';
|
612
|
-
const parsedDocument = useParsedValue(document);
|
613
|
-
const bundledDocument = useBundleRefsIntoDocument(parsedDocument, { baseUrl: apiDescriptionUrl });
|
614
|
-
const serviceNode = React.useMemo(() => transformOasToServiceNode(bundledDocument), [bundledDocument]);
|
615
|
-
const exportProps = useExportDocumentProps({ originalDocument: document, bundledDocument });
|
616
|
-
if (error) {
|
617
|
-
return (React.createElement(Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
|
618
|
-
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" })));
|
619
|
-
}
|
620
|
-
if (!bundledDocument) {
|
621
|
-
return (React.createElement(Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen", color: "light" },
|
622
|
-
React.createElement(Box, { as: Icon, icon: ['fal', 'circle-notch'], size: "3x", spin: true })));
|
623
|
-
}
|
624
|
-
if (!serviceNode) {
|
625
|
-
return (React.createElement(Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
|
626
|
-
React.createElement(NonIdealState, { title: "Failed to parse OpenAPI file", description: "Please make sure your OpenAPI file is valid and try again" })));
|
627
|
-
}
|
628
|
-
return (React.createElement(InlineRefResolverProvider, { document: parsedDocument, maxRefDepth: maxRefDepth },
|
629
|
-
layout === 'stacked' && (React.createElement(APIWithStackedLayout, { serviceNode: serviceNode, hideTryIt: hideTryIt, hideExport: hideExport, hideInlineExamples: hideInlineExamples, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon, location: location, tryItOutDefaultServer: tryItOutDefaultServer })),
|
630
|
-
layout === 'sidebar' && (React.createElement(APIWithSidebarLayout, { logo: logo, serviceNode: serviceNode, hideTryIt: hideTryIt, hideSchemas: hideSchemas, hideInternal: hideInternal, hideExport: hideExport, hideInlineExamples: hideInlineExamples, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon, tryItOutDefaultServer: tryItOutDefaultServer, useCustomNav: useCustomNav, layout: layout })),
|
631
|
-
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 }))));
|
632
|
-
};
|
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
|
+
};
|
633
662
|
const API = flow(withRouter, withStyles, withPersistenceBoundary, withMosaicProvider, withQueryClientProvider)(APIImpl);
|
634
663
|
|
635
|
-
const useGetOasNavTree = (apiDescriptionDocument) => {
|
636
|
-
const parsedDocument = useParsedValue(apiDescriptionDocument);
|
637
|
-
const bundledDocument = useBundleRefsIntoDocument(parsedDocument);
|
638
|
-
if (!bundledDocument)
|
639
|
-
return [];
|
640
|
-
const groupSchemas = (tree) => {
|
641
|
-
const targetTitle = 'Schemas';
|
642
|
-
const newTree = tree.reduce((accumulator, currentObject) => {
|
643
|
-
var _a;
|
644
|
-
if (currentObject.title === targetTitle) {
|
645
|
-
accumulator.matchedObject = currentObject;
|
646
|
-
}
|
647
|
-
else if ((_a = currentObject.id) === null || _a === void 0 ? void 0 : _a.includes(targetTitle.toLowerCase())) {
|
648
|
-
accumulator.matchedObject.items = accumulator.matchedObject.items || [];
|
649
|
-
accumulator.matchedObject.items.push(currentObject);
|
650
|
-
}
|
651
|
-
else {
|
652
|
-
accumulator.others = accumulator.others || [];
|
653
|
-
accumulator.others.push(currentObject);
|
654
|
-
}
|
655
|
-
return accumulator;
|
656
|
-
}, {});
|
657
|
-
const navTree = [...newTree.others, newTree.matchedObject];
|
658
|
-
return navTree;
|
659
|
-
};
|
660
|
-
const apiTree = computeAPITree(transformOasToServiceNode(bundledDocument));
|
661
|
-
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);
|
662
691
|
};
|
663
692
|
|
664
693
|
export { API, APIWithStackedLayout, transformOasToServiceNode, useExportDocumentProps, useGetOasNavTree };
|