docusaurus-theme-openapi-docs 3.0.0-beta.4 → 3.0.0-beta.6
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/lib/markdown/utils.js +4 -4
- package/lib/markdown/utils.test.d.ts +1 -0
- package/lib/markdown/utils.test.js +43 -0
- package/lib/theme/ApiExplorer/Body/index.js +8 -1
- package/lib/theme/ApiExplorer/CodeSnippets/code-snippets-types.d.ts +21 -0
- package/lib/theme/ApiExplorer/CodeSnippets/code-snippets-types.js +8 -0
- package/lib/theme/ApiExplorer/CodeSnippets/index.d.ts +2 -12
- package/lib/theme/ApiExplorer/CodeSnippets/index.js +86 -8
- package/lib/theme/ApiExplorer/CodeSnippets/languages.d.ts +3 -0
- package/lib/theme/ApiExplorer/CodeSnippets/languages.js +48 -0
- package/lib/theme/ApiExplorer/CodeSnippets/languages.json +0 -96
- package/lib/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +14 -0
- package/lib/theme/ApiExplorer/CodeTabs/index.d.ts +5 -1
- package/lib/theme/ApiExplorer/CodeTabs/index.js +11 -3
- package/lib/theme/ApiExplorer/index.js +1 -1
- package/lib/theme/ApiItem/index.d.ts +2 -2
- package/lib/theme/ApiItem/index.js +24 -0
- package/lib/theme/ApiTabs/_ApiTabs.scss +3 -1
- package/lib/theme/ApiTabs/index.d.ts +5 -1
- package/lib/theme/ApiTabs/index.js +15 -3
- package/lib/theme/Markdown/index.js +37 -0
- package/lib/theme/OperationTabs/_OperationTabs.scss +71 -0
- package/lib/theme/OperationTabs/index.d.ts +3 -0
- package/lib/theme/OperationTabs/index.js +232 -0
- package/lib/theme/SchemaItem/index.js +8 -10
- package/lib/theme/SchemaTabs/_SchemaTabs.scss +0 -4
- package/lib/theme/styles.scss +5 -0
- package/package.json +3 -3
- package/src/markdown/utils.test.ts +48 -0
- package/src/markdown/utils.ts +4 -4
- package/src/theme/ApiExplorer/Body/index.tsx +3 -1
- package/src/theme/ApiExplorer/CodeSnippets/code-snippets-types.ts +55 -0
- package/src/theme/ApiExplorer/CodeSnippets/index.tsx +94 -21
- package/src/theme/ApiExplorer/CodeSnippets/languages.json +0 -96
- package/src/theme/ApiExplorer/CodeSnippets/languages.ts +53 -0
- package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +14 -0
- package/src/theme/ApiExplorer/CodeTabs/index.tsx +21 -5
- package/src/theme/ApiExplorer/index.tsx +1 -1
- package/src/theme/ApiItem/index.tsx +21 -1
- package/src/theme/ApiTabs/_ApiTabs.scss +3 -1
- package/src/theme/ApiTabs/index.tsx +16 -5
- package/src/theme/Markdown/index.js +37 -0
- package/src/theme/OperationTabs/_OperationTabs.scss +71 -0
- package/src/theme/OperationTabs/index.tsx +216 -0
- package/src/theme/SchemaItem/index.tsx +5 -8
- package/src/theme/SchemaTabs/_SchemaTabs.scss +0 -4
- package/src/theme/styles.scss +5 -0
- package/src/theme-openapi.d.ts +4 -0
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { TabProps } from "@docusaurus/theme-common/internal";
|
|
3
|
-
export
|
|
3
|
+
export interface TabListProps extends TabProps {
|
|
4
|
+
label: string;
|
|
5
|
+
id: string;
|
|
6
|
+
}
|
|
7
|
+
export default function ApiTabs(props: TabListProps): React.JSX.Element;
|
|
@@ -60,7 +60,15 @@ const internal_1 = require("@docusaurus/theme-common/internal");
|
|
|
60
60
|
const useIsBrowser_1 = __importDefault(require("@docusaurus/useIsBrowser"));
|
|
61
61
|
const Heading_1 = __importDefault(require("@theme/Heading"));
|
|
62
62
|
const clsx_1 = __importDefault(require("clsx"));
|
|
63
|
-
function TabList({
|
|
63
|
+
function TabList({
|
|
64
|
+
className,
|
|
65
|
+
block,
|
|
66
|
+
selectedValue,
|
|
67
|
+
selectValue,
|
|
68
|
+
tabValues,
|
|
69
|
+
label = "Responses",
|
|
70
|
+
id = "responses",
|
|
71
|
+
}) {
|
|
64
72
|
const tabRefs = [];
|
|
65
73
|
const { blockElementScrollPositionUntilNextRender } = (0,
|
|
66
74
|
internal_1.useScrollPositionBlocker)();
|
|
@@ -123,8 +131,12 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
|
|
|
123
131
|
{ className: "openapi-tabs__response-header-section" },
|
|
124
132
|
react_1.default.createElement(
|
|
125
133
|
Heading_1.default,
|
|
126
|
-
{
|
|
127
|
-
|
|
134
|
+
{
|
|
135
|
+
as: "h2",
|
|
136
|
+
id: id,
|
|
137
|
+
className: "openapi-tabs__heading openapi-tabs__response-header",
|
|
138
|
+
},
|
|
139
|
+
label
|
|
128
140
|
),
|
|
129
141
|
react_1.default.createElement(
|
|
130
142
|
"div",
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React from "react";
|
|
9
|
+
|
|
10
|
+
import CodeBlock from "@theme/CodeBlock";
|
|
11
|
+
import ReactMarkdown from "react-markdown";
|
|
12
|
+
import rehypeRaw from "rehype-raw";
|
|
13
|
+
|
|
14
|
+
function Markdown({ children }) {
|
|
15
|
+
return (
|
|
16
|
+
<div>
|
|
17
|
+
<ReactMarkdown
|
|
18
|
+
children={children}
|
|
19
|
+
rehypePlugins={[rehypeRaw]}
|
|
20
|
+
components={{
|
|
21
|
+
pre: "div",
|
|
22
|
+
code({ node, inline, className, children, ...props }) {
|
|
23
|
+
const match = /language-(\w+)/.exec(className || "");
|
|
24
|
+
if (inline) return <code>{children}</code>;
|
|
25
|
+
return !inline && match ? (
|
|
26
|
+
<CodeBlock className={className}>{children}</CodeBlock>
|
|
27
|
+
) : (
|
|
28
|
+
<CodeBlock>{children}</CodeBlock>
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
}}
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default Markdown;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
.openapi-tabs__operation-container {
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.openapi-tabs__operation-header {
|
|
15
|
+
margin-bottom: 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.openapi-tabs__operation-item {
|
|
19
|
+
display: flex;
|
|
20
|
+
align-items: center;
|
|
21
|
+
justify-content: center;
|
|
22
|
+
padding: 0.35rem 0.7rem;
|
|
23
|
+
border: 1px solid transparent;
|
|
24
|
+
margin-top: 0 !important;
|
|
25
|
+
margin-right: 0.5rem;
|
|
26
|
+
font-weight: var(--ifm-font-weight-bold);
|
|
27
|
+
font-size: 12px;
|
|
28
|
+
white-space: nowrap;
|
|
29
|
+
transition: 300ms;
|
|
30
|
+
|
|
31
|
+
&:hover {
|
|
32
|
+
background-color: transparent;
|
|
33
|
+
border: 1px solid var(--ifm-toc-border-color);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
&.active {
|
|
37
|
+
border: 1px solid var(--ifm-tabs-color-active-border);
|
|
38
|
+
color: var(--ifm-tabs-color-active);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&:last-child {
|
|
42
|
+
margin-right: 0 !important;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.openapi-tabs__operation-list-container {
|
|
47
|
+
overflow-y: hidden;
|
|
48
|
+
overflow-x: scroll;
|
|
49
|
+
scroll-behavior: smooth;
|
|
50
|
+
|
|
51
|
+
&::-webkit-scrollbar {
|
|
52
|
+
display: none;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.openapi-tabs__operation-schema-container {
|
|
57
|
+
max-width: 600px;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@media screen and (max-width: 500px) {
|
|
61
|
+
.operationTabsTopSection {
|
|
62
|
+
flex-direction: column;
|
|
63
|
+
align-items: flex-start;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.operationTabsContainer {
|
|
67
|
+
width: 100%;
|
|
68
|
+
margin-top: var(--ifm-spacing-vertical);
|
|
69
|
+
padding: 0;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
var __createBinding =
|
|
9
|
+
(this && this.__createBinding) ||
|
|
10
|
+
(Object.create
|
|
11
|
+
? function (o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (
|
|
15
|
+
!desc ||
|
|
16
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
17
|
+
) {
|
|
18
|
+
desc = {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return m[k];
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
Object.defineProperty(o, k2, desc);
|
|
26
|
+
}
|
|
27
|
+
: function (o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
o[k2] = m[k];
|
|
30
|
+
});
|
|
31
|
+
var __setModuleDefault =
|
|
32
|
+
(this && this.__setModuleDefault) ||
|
|
33
|
+
(Object.create
|
|
34
|
+
? function (o, v) {
|
|
35
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
+
}
|
|
37
|
+
: function (o, v) {
|
|
38
|
+
o["default"] = v;
|
|
39
|
+
});
|
|
40
|
+
var __importStar =
|
|
41
|
+
(this && this.__importStar) ||
|
|
42
|
+
function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null)
|
|
46
|
+
for (var k in mod)
|
|
47
|
+
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
48
|
+
__createBinding(result, mod, k);
|
|
49
|
+
__setModuleDefault(result, mod);
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
var __importDefault =
|
|
53
|
+
(this && this.__importDefault) ||
|
|
54
|
+
function (mod) {
|
|
55
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
56
|
+
};
|
|
57
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
|
+
const react_1 = __importStar(require("react"));
|
|
59
|
+
const internal_1 = require("@docusaurus/theme-common/internal");
|
|
60
|
+
const useIsBrowser_1 = __importDefault(require("@docusaurus/useIsBrowser"));
|
|
61
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
62
|
+
function TabList({ className, block, selectedValue, selectValue, tabValues }) {
|
|
63
|
+
const tabRefs = [];
|
|
64
|
+
const { blockElementScrollPositionUntilNextRender } = (0,
|
|
65
|
+
internal_1.useScrollPositionBlocker)();
|
|
66
|
+
const handleTabChange = (event) => {
|
|
67
|
+
const newTab = event.currentTarget;
|
|
68
|
+
const newTabIndex = tabRefs.indexOf(newTab);
|
|
69
|
+
const newTabValue = tabValues[newTabIndex].value;
|
|
70
|
+
if (newTabValue !== selectedValue) {
|
|
71
|
+
blockElementScrollPositionUntilNextRender(newTab);
|
|
72
|
+
selectValue(newTabValue);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const handleKeydown = (event) => {
|
|
76
|
+
let focusElement = null;
|
|
77
|
+
switch (event.key) {
|
|
78
|
+
case "Enter": {
|
|
79
|
+
handleTabChange(event);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case "ArrowRight": {
|
|
83
|
+
const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
|
|
84
|
+
focusElement = tabRefs[nextTab] ?? tabRefs[0];
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case "ArrowLeft": {
|
|
88
|
+
const prevTab = tabRefs.indexOf(event.currentTarget) - 1;
|
|
89
|
+
focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1];
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
default:
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
focusElement?.focus();
|
|
96
|
+
};
|
|
97
|
+
const tabItemListContainerRef = (0, react_1.useRef)(null);
|
|
98
|
+
const [showTabArrows, setShowTabArrows] = (0, react_1.useState)(false);
|
|
99
|
+
(0, react_1.useEffect)(() => {
|
|
100
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
101
|
+
for (let entry of entries) {
|
|
102
|
+
if (entry.target.clientWidth < entry.target.scrollWidth) {
|
|
103
|
+
setShowTabArrows(true);
|
|
104
|
+
} else {
|
|
105
|
+
setShowTabArrows(false);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
resizeObserver.observe(tabItemListContainerRef.current);
|
|
110
|
+
return () => {
|
|
111
|
+
resizeObserver.disconnect();
|
|
112
|
+
};
|
|
113
|
+
}, []);
|
|
114
|
+
const handleRightClick = () => {
|
|
115
|
+
tabItemListContainerRef.current.scrollLeft += 90;
|
|
116
|
+
};
|
|
117
|
+
const handleLeftClick = () => {
|
|
118
|
+
tabItemListContainerRef.current.scrollLeft -= 90;
|
|
119
|
+
};
|
|
120
|
+
return react_1.default.createElement(
|
|
121
|
+
"div",
|
|
122
|
+
{ className: "tabs__container" },
|
|
123
|
+
react_1.default.createElement(
|
|
124
|
+
"div",
|
|
125
|
+
{ className: "openapi-tabs__operation-container" },
|
|
126
|
+
showTabArrows &&
|
|
127
|
+
react_1.default.createElement("button", {
|
|
128
|
+
className: (0, clsx_1.default)("openapi-tabs__arrow", "left"),
|
|
129
|
+
onClick: handleLeftClick,
|
|
130
|
+
}),
|
|
131
|
+
react_1.default.createElement(
|
|
132
|
+
"ul",
|
|
133
|
+
{
|
|
134
|
+
ref: tabItemListContainerRef,
|
|
135
|
+
role: "tablist",
|
|
136
|
+
"aria-orientation": "horizontal",
|
|
137
|
+
className: (0, clsx_1.default)(
|
|
138
|
+
"openapi-tabs__operation-list-container",
|
|
139
|
+
"tabs",
|
|
140
|
+
{
|
|
141
|
+
"tabs--block": block,
|
|
142
|
+
},
|
|
143
|
+
className
|
|
144
|
+
),
|
|
145
|
+
},
|
|
146
|
+
tabValues.map(({ value, label, attributes }) => {
|
|
147
|
+
return react_1.default.createElement(
|
|
148
|
+
"li",
|
|
149
|
+
{
|
|
150
|
+
// TODO extract TabListItem
|
|
151
|
+
role: "tab",
|
|
152
|
+
tabIndex: selectedValue === value ? 0 : -1,
|
|
153
|
+
"aria-selected": selectedValue === value,
|
|
154
|
+
key: value,
|
|
155
|
+
ref: (tabControl) => tabRefs.push(tabControl),
|
|
156
|
+
onKeyDown: handleKeydown,
|
|
157
|
+
onFocus: handleTabChange,
|
|
158
|
+
onClick: (e) => handleTabChange(e),
|
|
159
|
+
...attributes,
|
|
160
|
+
className: (0, clsx_1.default)(
|
|
161
|
+
"tabs__item",
|
|
162
|
+
"openapi-tabs__operation-item",
|
|
163
|
+
attributes?.className,
|
|
164
|
+
{
|
|
165
|
+
active: selectedValue === value,
|
|
166
|
+
}
|
|
167
|
+
),
|
|
168
|
+
},
|
|
169
|
+
label ?? value
|
|
170
|
+
);
|
|
171
|
+
})
|
|
172
|
+
),
|
|
173
|
+
showTabArrows &&
|
|
174
|
+
react_1.default.createElement("button", {
|
|
175
|
+
className: (0, clsx_1.default)("openapi-tabs__arrow", "right"),
|
|
176
|
+
onClick: handleRightClick,
|
|
177
|
+
})
|
|
178
|
+
)
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
function TabContent({ lazy, children, selectedValue }) {
|
|
182
|
+
const childTabs = (Array.isArray(children) ? children : [children]).filter(
|
|
183
|
+
Boolean
|
|
184
|
+
);
|
|
185
|
+
if (lazy) {
|
|
186
|
+
const selectedTabItem = childTabs.find(
|
|
187
|
+
(tabItem) => tabItem.props.value === selectedValue
|
|
188
|
+
);
|
|
189
|
+
if (!selectedTabItem) {
|
|
190
|
+
// fail-safe or fail-fast? not sure what's best here
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
return (0, react_1.cloneElement)(selectedTabItem, {
|
|
194
|
+
className: "margin-top--md",
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return react_1.default.createElement(
|
|
198
|
+
"div",
|
|
199
|
+
{ className: "margin-top--md" },
|
|
200
|
+
childTabs.map((tabItem, i) =>
|
|
201
|
+
(0, react_1.cloneElement)(tabItem, {
|
|
202
|
+
key: i,
|
|
203
|
+
hidden: tabItem.props.value !== selectedValue,
|
|
204
|
+
})
|
|
205
|
+
)
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
function TabsComponent(props) {
|
|
209
|
+
const tabs = (0, internal_1.useTabs)(props);
|
|
210
|
+
return react_1.default.createElement(
|
|
211
|
+
"div",
|
|
212
|
+
{ className: "tabs-container" },
|
|
213
|
+
react_1.default.createElement(TabList, { ...props, ...tabs }),
|
|
214
|
+
react_1.default.createElement(TabContent, { ...props, ...tabs })
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
function OperationTabs(props) {
|
|
218
|
+
const isBrowser = (0, useIsBrowser_1.default)();
|
|
219
|
+
return react_1.default.createElement(
|
|
220
|
+
TabsComponent,
|
|
221
|
+
// Remount tabs after hydration
|
|
222
|
+
// Temporary fix for https://github.com/facebook/docusaurus/issues/5653
|
|
223
|
+
{
|
|
224
|
+
// Remount tabs after hydration
|
|
225
|
+
// Temporary fix for https://github.com/facebook/docusaurus/issues/5653
|
|
226
|
+
key: String(isBrowser),
|
|
227
|
+
...props,
|
|
228
|
+
},
|
|
229
|
+
(0, internal_1.sanitizeTabsChildren)(props.children)
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
exports.default = OperationTabs;
|
|
@@ -103,16 +103,14 @@ function SchemaItem({
|
|
|
103
103
|
})
|
|
104
104
|
)
|
|
105
105
|
);
|
|
106
|
-
const renderDefaultValue = (0, utils_1.guard)(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
})
|
|
115
|
-
)
|
|
106
|
+
const renderDefaultValue = (0, utils_1.guard)(defaultValue, (value) =>
|
|
107
|
+
react_1.default.createElement(
|
|
108
|
+
"div",
|
|
109
|
+
{ className: "" },
|
|
110
|
+
react_1.default.createElement(react_markdown_1.default, {
|
|
111
|
+
children: `**Default value:** \`${value}\``,
|
|
112
|
+
})
|
|
113
|
+
)
|
|
116
114
|
);
|
|
117
115
|
const schemaContent = react_1.default.createElement(
|
|
118
116
|
"div",
|
package/lib/theme/styles.scss
CHANGED
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
@use "./DiscriminatorTabs/DiscriminatorTabs";
|
|
37
37
|
@use "./MimeTabs/MimeTabs";
|
|
38
38
|
@use "./SchemaTabs/SchemaTabs";
|
|
39
|
+
@use "./OperationTabs/OperationTabs";
|
|
39
40
|
/* Code Samples */
|
|
40
41
|
@use "./ResponseSamples/ResponseSamples";
|
|
41
42
|
/* Markdown Styling */
|
|
@@ -158,3 +159,7 @@
|
|
|
158
159
|
.openapi-left-panel__container {
|
|
159
160
|
border-right: thin solid var(--ifm-toc-border-color);
|
|
160
161
|
}
|
|
162
|
+
|
|
163
|
+
.openapi-tabs__heading {
|
|
164
|
+
margin-bottom: 1rem;
|
|
165
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-theme-openapi-docs",
|
|
3
3
|
"description": "OpenAPI theme for Docusaurus.",
|
|
4
|
-
"version": "3.0.0-beta.
|
|
4
|
+
"version": "3.0.0-beta.6",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"clsx": "^1.1.1",
|
|
45
45
|
"copy-text-to-clipboard": "^3.1.0",
|
|
46
46
|
"crypto-js": "^4.1.1",
|
|
47
|
-
"docusaurus-plugin-openapi-docs": "^3.0.0-beta.
|
|
47
|
+
"docusaurus-plugin-openapi-docs": "^3.0.0-beta.6",
|
|
48
48
|
"docusaurus-plugin-sass": "^0.2.3",
|
|
49
49
|
"file-saver": "^2.0.5",
|
|
50
50
|
"lodash": "^4.17.20",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"engines": {
|
|
70
70
|
"node": ">=14"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "e2334e1ceb562f3dc021f861bd16393ef343ba40"
|
|
73
73
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import { guard } from "./utils";
|
|
9
|
+
|
|
10
|
+
describe("guard", () => {
|
|
11
|
+
it("should guard empty strings", () => {
|
|
12
|
+
const actual = guard("", (_) => {
|
|
13
|
+
throw new Error("Should not be called");
|
|
14
|
+
});
|
|
15
|
+
expect(actual).toBe("");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("should guard undefined", () => {
|
|
19
|
+
const actual = guard(undefined, (value) => {
|
|
20
|
+
throw new Error("Should not be called");
|
|
21
|
+
});
|
|
22
|
+
expect(actual).toBe("");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should not guard strings", () => {
|
|
26
|
+
const actual = guard("hello", (value) => value);
|
|
27
|
+
expect(actual).toBe("hello");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should not guard numbers", () => {
|
|
31
|
+
const actual = guard(1, (value) => `${value}`);
|
|
32
|
+
expect(actual).toBe("1");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should not guard numbers equals to 0", () => {
|
|
36
|
+
const actual = guard(0, (value) => `${value}`);
|
|
37
|
+
expect(actual).toBe("0");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should not guard false booleans", () => {
|
|
41
|
+
const actual = guard(false, (value) => `${value}`);
|
|
42
|
+
expect(actual).toBe("false");
|
|
43
|
+
});
|
|
44
|
+
it("should not guard true booleans", () => {
|
|
45
|
+
const actual = guard(true, (value) => `${value}`);
|
|
46
|
+
expect(actual).toBe("true");
|
|
47
|
+
});
|
|
48
|
+
});
|
package/src/markdown/utils.ts
CHANGED
|
@@ -26,11 +26,11 @@ export function guard<T>(
|
|
|
26
26
|
value: T | undefined | string,
|
|
27
27
|
cb: (value: T) => Children
|
|
28
28
|
): string {
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
return render(children);
|
|
29
|
+
if (value === undefined || value === "") {
|
|
30
|
+
return "";
|
|
32
31
|
}
|
|
33
|
-
|
|
32
|
+
const children = cb(value as T);
|
|
33
|
+
return render(children);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export function render(children: Children): string {
|
|
@@ -14,6 +14,7 @@ import FormSelect from "@theme/ApiExplorer/FormSelect";
|
|
|
14
14
|
import FormTextInput from "@theme/ApiExplorer/FormTextInput";
|
|
15
15
|
import LiveApp from "@theme/ApiExplorer/LiveEditor";
|
|
16
16
|
import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
|
|
17
|
+
import Markdown from "@theme/Markdown";
|
|
17
18
|
import SchemaTabs from "@theme/SchemaTabs";
|
|
18
19
|
import TabItem from "@theme/TabItem";
|
|
19
20
|
import { RequestBodyObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
|
|
@@ -303,6 +304,7 @@ function Body({
|
|
|
303
304
|
</TabItem>
|
|
304
305
|
{/* @ts-ignore */}
|
|
305
306
|
<TabItem label="Example" value="example">
|
|
307
|
+
{example.summary && <Markdown children={example.summary} />}
|
|
306
308
|
{exampleBody && (
|
|
307
309
|
<LiveApp
|
|
308
310
|
action={dispatch}
|
|
@@ -340,7 +342,7 @@ function Body({
|
|
|
340
342
|
value={example.label}
|
|
341
343
|
key={example.label}
|
|
342
344
|
>
|
|
343
|
-
{example.summary && <
|
|
345
|
+
{example.summary && <Markdown children={example.summary} />}
|
|
344
346
|
{example.body && (
|
|
345
347
|
<LiveApp action={dispatch} language={language}>
|
|
346
348
|
{example.body}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
// https://github.com/github-linguist/linguist/blob/master/lib/linguist/popular.yml
|
|
9
|
+
export type CodeSampleLanguage =
|
|
10
|
+
| "C"
|
|
11
|
+
| "C#"
|
|
12
|
+
| "C++"
|
|
13
|
+
| "CoffeeScript"
|
|
14
|
+
| "CSS"
|
|
15
|
+
| "Dart"
|
|
16
|
+
| "DM"
|
|
17
|
+
| "Elixir"
|
|
18
|
+
| "Go"
|
|
19
|
+
| "Groovy"
|
|
20
|
+
| "HTML"
|
|
21
|
+
| "Java"
|
|
22
|
+
| "JavaScript"
|
|
23
|
+
| "Kotlin"
|
|
24
|
+
| "Objective-C"
|
|
25
|
+
| "Perl"
|
|
26
|
+
| "PHP"
|
|
27
|
+
| "PowerShell"
|
|
28
|
+
| "Python"
|
|
29
|
+
| "Ruby"
|
|
30
|
+
| "Rust"
|
|
31
|
+
| "Scala"
|
|
32
|
+
| "Shell"
|
|
33
|
+
| "Swift"
|
|
34
|
+
| "TypeScript";
|
|
35
|
+
|
|
36
|
+
export interface Language {
|
|
37
|
+
highlight: string;
|
|
38
|
+
language: string;
|
|
39
|
+
codeSampleLanguage: CodeSampleLanguage;
|
|
40
|
+
logoClass: string;
|
|
41
|
+
variant: string;
|
|
42
|
+
variants: string[];
|
|
43
|
+
options?: { [key: string]: boolean };
|
|
44
|
+
sample?: string;
|
|
45
|
+
samples?: string[];
|
|
46
|
+
samplesSources?: string[];
|
|
47
|
+
samplesLabels?: string[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// https://redocly.com/docs/api-reference-docs/specification-extensions/x-code-samples
|
|
51
|
+
export interface CodeSample {
|
|
52
|
+
source: string;
|
|
53
|
+
lang: CodeSampleLanguage;
|
|
54
|
+
label?: string;
|
|
55
|
+
}
|