docusaurus-theme-openapi-docs 4.0.1 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/markdown/utils.d.ts +5 -4
- package/lib/theme/ApiExplorer/CodeSnippets/code-snippets-types.d.ts +1 -1
- package/lib/theme/ApiExplorer/CodeSnippets/index.js +4 -113
- package/lib/theme/ApiExplorer/CodeSnippets/languages.d.ts +1 -0
- package/lib/theme/ApiExplorer/CodeSnippets/languages.js +30 -6
- package/lib/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +196 -2
- package/lib/theme/ApiExplorer/CodeTabs/index.js +34 -8
- package/lib/theme/ApiExplorer/MethodEndpoint/index.d.ts +2 -1
- package/lib/theme/ApiExplorer/MethodEndpoint/index.js +5 -2
- package/lib/theme/ApiExplorer/ParamOptions/index.js +1 -0
- package/lib/theme/ApiExplorer/Request/_Request.scss +5 -0
- package/lib/theme/ApiExplorer/index.js +6 -0
- package/lib/theme/ApiItem/Layout/index.d.ts +3 -0
- package/lib/theme/ApiItem/Layout/index.js +121 -0
- package/lib/theme/ApiItem/Layout/styles.module.css +17 -0
- package/lib/theme/ApiItem/index.js +16 -5
- package/lib/theme/ApiTabs/_ApiTabs.scss +0 -1
- package/lib/theme/ArrayBrackets/index.d.ts +3 -0
- package/lib/theme/ArrayBrackets/index.js +50 -0
- package/lib/theme/ParamsDetails/index.d.ts +6 -0
- package/lib/theme/ParamsDetails/index.js +134 -0
- package/lib/theme/ParamsItem/index.d.ts +3 -1
- package/lib/theme/ParamsItem/index.js +77 -16
- package/lib/theme/RequestSchema/index.d.ts +15 -0
- package/lib/theme/RequestSchema/index.js +235 -0
- package/lib/theme/ResponseExamples/index.d.ts +48 -0
- package/lib/theme/ResponseExamples/index.js +290 -0
- package/lib/theme/ResponseSchema/index.d.ts +15 -0
- package/lib/theme/ResponseSchema/index.js +206 -0
- package/lib/theme/Schema/index.d.ts +8 -0
- package/lib/theme/Schema/index.js +879 -0
- package/lib/theme/SchemaItem/index.d.ts +9 -9
- package/lib/theme/SchemaItem/index.js +110 -20
- package/lib/theme/SkeletonLoader/index.d.ts +6 -0
- package/lib/theme/SkeletonLoader/index.js +20 -0
- package/lib/theme/StatusCodes/index.d.ts +9 -0
- package/lib/theme/StatusCodes/index.js +78 -0
- package/lib/theme/styles.scss +56 -9
- package/package.json +9 -7
- package/src/markdown/utils.ts +7 -6
- package/src/plugin-content-docs.d.ts +2 -0
- package/src/theme/ApiExplorer/CodeSnippets/code-snippets-types.ts +2 -0
- package/src/theme/ApiExplorer/CodeSnippets/index.tsx +8 -113
- package/src/theme/ApiExplorer/CodeSnippets/languages.ts +26 -5
- package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +196 -2
- package/src/theme/ApiExplorer/CodeTabs/index.tsx +40 -9
- package/src/theme/ApiExplorer/MethodEndpoint/index.tsx +7 -3
- package/src/theme/ApiExplorer/ParamOptions/index.tsx +1 -0
- package/src/theme/ApiExplorer/Request/_Request.scss +5 -0
- package/src/theme/ApiExplorer/index.tsx +2 -0
- package/src/theme/ApiItem/Layout/index.tsx +85 -0
- package/src/theme/ApiItem/Layout/styles.module.css +17 -0
- package/src/theme/ApiItem/index.tsx +15 -3
- package/src/theme/ApiTabs/_ApiTabs.scss +0 -1
- package/src/theme/ArrayBrackets/index.tsx +37 -0
- package/src/theme/ParamsDetails/index.tsx +88 -0
- package/src/theme/ParamsItem/index.tsx +80 -17
- package/src/theme/RequestSchema/index.tsx +164 -0
- package/src/theme/ResponseExamples/index.tsx +290 -0
- package/src/theme/ResponseSchema/index.tsx +151 -0
- package/src/theme/Schema/index.tsx +928 -0
- package/src/theme/SchemaItem/index.tsx +116 -25
- package/src/theme/SkeletonLoader/index.tsx +18 -0
- package/src/theme/StatusCodes/index.tsx +72 -0
- package/src/theme/styles.scss +56 -9
- package/src/theme-classic.d.ts +0 -2
- package/src/theme-openapi.d.ts +4 -0
|
@@ -11,39 +11,71 @@ import CodeBlock from "@theme/CodeBlock";
|
|
|
11
11
|
import clsx from "clsx";
|
|
12
12
|
import ReactMarkdown from "react-markdown";
|
|
13
13
|
import rehypeRaw from "rehype-raw";
|
|
14
|
+
import remarkGfm from "remark-gfm";
|
|
14
15
|
|
|
15
16
|
import { createDescription } from "../../markdown/createDescription";
|
|
16
17
|
import { guard } from "../../markdown/utils";
|
|
17
18
|
|
|
18
19
|
export interface Props {
|
|
19
|
-
children
|
|
20
|
-
collapsible
|
|
21
|
-
name
|
|
22
|
-
qualifierMessage
|
|
23
|
-
required
|
|
24
|
-
schemaName
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
collapsible?: boolean;
|
|
22
|
+
name?: string;
|
|
23
|
+
qualifierMessage?: string | undefined;
|
|
24
|
+
required?: boolean;
|
|
25
|
+
schemaName?: string;
|
|
25
26
|
// TODO should probably be typed
|
|
26
|
-
schema
|
|
27
|
-
discriminator
|
|
27
|
+
schema?: any;
|
|
28
|
+
discriminator?: boolean;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
31
|
+
const transformEnumDescriptions = (
|
|
32
|
+
enumDescriptions?: Record<string, string>
|
|
33
|
+
) => {
|
|
34
|
+
if (enumDescriptions) {
|
|
35
|
+
return Object.entries(enumDescriptions);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return [];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const getEnumDescriptionMarkdown = (enumDescriptions?: [string, string][]) => {
|
|
42
|
+
if (enumDescriptions?.length) {
|
|
43
|
+
return `| Enum Value | Description |
|
|
44
|
+
| ---- | ----- |
|
|
45
|
+
${enumDescriptions
|
|
46
|
+
.map((desc) => {
|
|
47
|
+
return `| ${desc[0]} | ${desc[1]} | `.replaceAll("\n", "<br/>");
|
|
48
|
+
})
|
|
49
|
+
.join("\n")}
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return "";
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default function SchemaItem(props: Props) {
|
|
57
|
+
const {
|
|
58
|
+
children: collapsibleSchemaContent,
|
|
59
|
+
collapsible,
|
|
60
|
+
name,
|
|
61
|
+
qualifierMessage,
|
|
62
|
+
required,
|
|
63
|
+
schemaName,
|
|
64
|
+
schema,
|
|
65
|
+
} = props;
|
|
39
66
|
let deprecated;
|
|
40
67
|
let schemaDescription;
|
|
41
|
-
let defaultValue;
|
|
68
|
+
let defaultValue: string | undefined;
|
|
69
|
+
let example: string | undefined;
|
|
42
70
|
let nullable;
|
|
71
|
+
let enumDescriptions: [string, string][] = [];
|
|
72
|
+
|
|
43
73
|
if (schema) {
|
|
44
74
|
deprecated = schema.deprecated;
|
|
45
75
|
schemaDescription = schema.description;
|
|
76
|
+
enumDescriptions = transformEnumDescriptions(schema["x-enumDescriptions"]);
|
|
46
77
|
defaultValue = schema.default;
|
|
78
|
+
example = schema.example;
|
|
47
79
|
nullable = schema.nullable;
|
|
48
80
|
}
|
|
49
81
|
|
|
@@ -60,6 +92,21 @@ export default function SchemaItem({
|
|
|
60
92
|
<span className="openapi-schema__nullable">nullable</span>
|
|
61
93
|
));
|
|
62
94
|
|
|
95
|
+
const renderEnumDescriptions = guard(
|
|
96
|
+
getEnumDescriptionMarkdown(enumDescriptions),
|
|
97
|
+
(value) => {
|
|
98
|
+
return (
|
|
99
|
+
<div style={{ marginTop: ".5rem" }}>
|
|
100
|
+
<ReactMarkdown
|
|
101
|
+
remarkPlugins={[remarkGfm]}
|
|
102
|
+
rehypePlugins={[rehypeRaw]}
|
|
103
|
+
children={value}
|
|
104
|
+
/>
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
|
|
63
110
|
const renderSchemaDescription = guard(schemaDescription, (description) => (
|
|
64
111
|
<div>
|
|
65
112
|
<ReactMarkdown
|
|
@@ -90,11 +137,53 @@ export default function SchemaItem({
|
|
|
90
137
|
</div>
|
|
91
138
|
));
|
|
92
139
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
140
|
+
function renderDefaultValue() {
|
|
141
|
+
if (defaultValue !== undefined) {
|
|
142
|
+
if (typeof defaultValue === "string") {
|
|
143
|
+
return (
|
|
144
|
+
<div>
|
|
145
|
+
<strong>Default value: </strong>
|
|
146
|
+
<span>
|
|
147
|
+
<code>{defaultValue}</code>
|
|
148
|
+
</span>
|
|
149
|
+
</div>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return (
|
|
153
|
+
<div>
|
|
154
|
+
<strong>Default value: </strong>
|
|
155
|
+
<span>
|
|
156
|
+
<code>{JSON.stringify(defaultValue)}</code>
|
|
157
|
+
</span>
|
|
158
|
+
</div>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function renderExample() {
|
|
165
|
+
if (example !== undefined) {
|
|
166
|
+
if (typeof example === "string") {
|
|
167
|
+
return (
|
|
168
|
+
<div>
|
|
169
|
+
<strong>Example: </strong>
|
|
170
|
+
<span>
|
|
171
|
+
<code>{example}</code>
|
|
172
|
+
</span>
|
|
173
|
+
</div>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
return (
|
|
177
|
+
<div>
|
|
178
|
+
<strong>Example: </strong>
|
|
179
|
+
<span>
|
|
180
|
+
<code>{JSON.stringify(example)}</code>
|
|
181
|
+
</span>
|
|
182
|
+
</div>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
98
187
|
|
|
99
188
|
const schemaContent = (
|
|
100
189
|
<div>
|
|
@@ -114,9 +203,11 @@ export default function SchemaItem({
|
|
|
114
203
|
{renderRequired}
|
|
115
204
|
{renderDeprecated}
|
|
116
205
|
</span>
|
|
117
|
-
{renderQualifierMessage}
|
|
118
|
-
{renderDefaultValue}
|
|
119
206
|
{renderSchemaDescription}
|
|
207
|
+
{renderEnumDescriptions}
|
|
208
|
+
{renderQualifierMessage}
|
|
209
|
+
{renderDefaultValue()}
|
|
210
|
+
{renderExample()}
|
|
120
211
|
{collapsibleSchemaContent ?? collapsibleSchemaContent}
|
|
121
212
|
</div>
|
|
122
213
|
);
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
interface Props {
|
|
11
|
+
size?: "sm" | "md" | "lg";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const SkeletonLoader: React.FC<Props> = (props) => {
|
|
15
|
+
return <div className={`openapi-skeleton ${props.size ?? "md"}`}></div>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default SkeletonLoader;
|
|
@@ -0,0 +1,72 @@
|
|
|
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 ApiTabs from "@theme/ApiTabs";
|
|
11
|
+
import Details from "@theme/Details";
|
|
12
|
+
import { ResponseHeaders } from "@theme/ResponseExamples";
|
|
13
|
+
import ResponseSchema from "@theme/ResponseSchema";
|
|
14
|
+
import TabItem from "@theme/TabItem";
|
|
15
|
+
import { createDescription } from "docusaurus-plugin-openapi-docs/lib/markdown/createDescription";
|
|
16
|
+
import { ApiItem } from "docusaurus-plugin-openapi-docs/lib/types";
|
|
17
|
+
|
|
18
|
+
interface Props {
|
|
19
|
+
id?: string;
|
|
20
|
+
label?: string;
|
|
21
|
+
responses: ApiItem["responses"];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const StatusCodes: React.FC<Props> = ({ label, id, responses }: any) => {
|
|
25
|
+
if (!responses) return null;
|
|
26
|
+
|
|
27
|
+
const codes = Object.keys(responses);
|
|
28
|
+
if (codes.length === 0) return null;
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<ApiTabs label={label} id={id}>
|
|
32
|
+
{codes.map((code) => {
|
|
33
|
+
const response = responses[code];
|
|
34
|
+
const responseHeaders = response.headers;
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
<TabItem key={code} label={code} value={code}>
|
|
39
|
+
<div>
|
|
40
|
+
{response.description && (
|
|
41
|
+
<div style={{ marginTop: ".5rem", marginBottom: ".5rem" }}>
|
|
42
|
+
{createDescription(response.description)}
|
|
43
|
+
</div>
|
|
44
|
+
)}
|
|
45
|
+
</div>
|
|
46
|
+
{responseHeaders && (
|
|
47
|
+
<Details
|
|
48
|
+
className="openapi-markdown__details"
|
|
49
|
+
data-collapsed={true}
|
|
50
|
+
open={false}
|
|
51
|
+
style={{ textAlign: "left", marginBottom: "1rem" }}
|
|
52
|
+
summary={
|
|
53
|
+
<summary>
|
|
54
|
+
<strong>Response Headers</strong>
|
|
55
|
+
</summary>
|
|
56
|
+
}
|
|
57
|
+
>
|
|
58
|
+
<ResponseHeaders responseHeaders={responseHeaders} />
|
|
59
|
+
</Details>
|
|
60
|
+
)}
|
|
61
|
+
<ResponseSchema
|
|
62
|
+
title="Schema"
|
|
63
|
+
body={{ content: response.content }}
|
|
64
|
+
/>
|
|
65
|
+
</TabItem>
|
|
66
|
+
);
|
|
67
|
+
})}
|
|
68
|
+
</ApiTabs>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export default StatusCodes;
|
package/src/theme/styles.scss
CHANGED
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
--openapi-explorer-padding-input: 0.5rem;
|
|
82
82
|
--openapi-explorer-border-color: var(--ifm-toc-border-color);
|
|
83
83
|
--openapi-explorer-caret-bg: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"></path></svg>');
|
|
84
|
+
--openapi-skeleton-background: var(--ifm-color-emphasis-100);
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
[data-theme="dark"] {
|
|
@@ -92,16 +93,16 @@
|
|
|
92
93
|
height: 100%;
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
@media (min-width: 997px) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
// @media (min-width: 997px) {
|
|
97
|
+
// .docItemCol {
|
|
98
|
+
// max-width: 75% !important;
|
|
99
|
+
// }
|
|
99
100
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
101
|
+
// /* Prevent hydration FOUC, as the mobile TOC needs to be server-rendered */
|
|
102
|
+
// .tocMobile {
|
|
103
|
+
// display: none;
|
|
104
|
+
// }
|
|
105
|
+
// }
|
|
105
106
|
|
|
106
107
|
/* Begin OpenAPI theme styles */
|
|
107
108
|
// [data-theme="dark"] {
|
|
@@ -160,6 +161,52 @@
|
|
|
160
161
|
border-right: thin solid var(--ifm-toc-border-color);
|
|
161
162
|
}
|
|
162
163
|
|
|
164
|
+
@media (max-width: 997px) {
|
|
165
|
+
.schema {
|
|
166
|
+
margin-bottom: 1rem;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
163
170
|
.openapi-tabs__heading {
|
|
164
171
|
margin-bottom: 1rem;
|
|
165
172
|
}
|
|
173
|
+
|
|
174
|
+
/* Loading Skeleton */
|
|
175
|
+
@keyframes pulsing {
|
|
176
|
+
0% {
|
|
177
|
+
opacity: 1;
|
|
178
|
+
background-color: var(--ifm-color-emphasis-100);
|
|
179
|
+
}
|
|
180
|
+
50% {
|
|
181
|
+
opacity: 0.6;
|
|
182
|
+
background-color: var(--ifm-toc-border-color);
|
|
183
|
+
}
|
|
184
|
+
100% {
|
|
185
|
+
opacity: 1;
|
|
186
|
+
background-color: var(--ifm-color-emphasis-100);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.openapi-skeleton {
|
|
191
|
+
animation: pulsing 2s infinite ease-in-out;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/* Loading Skeleton */
|
|
195
|
+
.openapi-skeleton {
|
|
196
|
+
border-radius: var(--ifm-pre-border-radius);
|
|
197
|
+
background-color: var(--openapi-skeleton-background);
|
|
198
|
+
max-width: 100%;
|
|
199
|
+
margin: 1rem auto;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.openapi-skeleton.sm {
|
|
203
|
+
height: 100px;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.openapi-skeleton.md {
|
|
207
|
+
height: 350px;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
.openapi-skeleton.lg {
|
|
211
|
+
height: 96.5%;
|
|
212
|
+
}
|
package/src/theme-classic.d.ts
CHANGED
|
@@ -27,8 +27,6 @@ declare module "@docusaurus/theme-common/internal" {
|
|
|
27
27
|
export interface LineProps extends ILineProps {}
|
|
28
28
|
export interface CodeBlockProps extends ICodeBlockProps {}
|
|
29
29
|
|
|
30
|
-
export function useDoc();
|
|
31
|
-
|
|
32
30
|
export function usePrismTheme(): PrismTheme;
|
|
33
31
|
|
|
34
32
|
export function sanitizeTabsChildren(children: TabProps["children"]);
|
package/src/theme-openapi.d.ts
CHANGED