docusaurus-theme-openapi-docs 4.1.0 → 4.3.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/theme/ApiExplorer/ApiCodeBlock/Line/_Line.scss +0 -12
- package/lib/theme/ApiExplorer/Authorization/index.js +3 -0
- package/lib/theme/ApiExplorer/Body/index.js +11 -2
- package/lib/theme/ApiExplorer/CodeSnippets/index.js +2 -1
- package/lib/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +50 -0
- package/lib/theme/ApiItem/Layout/index.js +6 -2
- package/lib/theme/ApiItem/index.js +15 -4
- 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/Markdown/Details/_Details.scss +5 -2
- package/lib/theme/Markdown/index.js +160 -18
- package/lib/theme/ParamsDetails/index.d.ts +6 -0
- package/lib/theme/ParamsDetails/index.js +134 -0
- package/lib/theme/ParamsItem/index.d.ts +1 -0
- package/lib/theme/ParamsItem/index.js +11 -48
- package/lib/theme/RequestSchema/index.d.ts +15 -0
- package/lib/theme/RequestSchema/index.js +243 -0
- package/lib/theme/ResponseExamples/index.d.ts +18 -0
- package/lib/theme/ResponseExamples/index.js +194 -0
- package/lib/theme/ResponseHeaders/index.d.ts +13 -0
- package/lib/theme/ResponseHeaders/index.js +39 -0
- package/lib/theme/ResponseSchema/index.d.ts +15 -0
- package/lib/theme/ResponseSchema/index.js +208 -0
- package/lib/theme/Schema/index.d.ts +8 -0
- package/lib/theme/Schema/index.js +887 -0
- package/lib/theme/SchemaItem/index.d.ts +8 -8
- package/lib/theme/SchemaItem/index.js +11 -41
- 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 +81 -0
- package/lib/theme/styles.scss +56 -9
- package/package.json +13 -8
- package/src/theme/ApiExplorer/ApiCodeBlock/Line/_Line.scss +0 -12
- package/src/theme/ApiExplorer/Authorization/index.tsx +3 -0
- package/src/theme/ApiExplorer/Body/index.tsx +3 -2
- package/src/theme/ApiExplorer/CodeSnippets/index.tsx +2 -1
- package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +50 -0
- package/src/theme/ApiItem/Layout/index.tsx +5 -2
- package/src/theme/ApiItem/index.tsx +14 -2
- package/src/theme/ApiTabs/_ApiTabs.scss +0 -1
- package/src/theme/ArrayBrackets/index.tsx +37 -0
- package/src/theme/Markdown/Details/_Details.scss +5 -2
- package/src/theme/Markdown/index.js +160 -18
- package/src/theme/ParamsDetails/index.tsx +88 -0
- package/src/theme/ParamsItem/index.tsx +9 -36
- package/src/theme/RequestSchema/index.tsx +164 -0
- package/src/theme/ResponseExamples/index.tsx +192 -0
- package/src/theme/ResponseHeaders/index.tsx +49 -0
- package/src/theme/ResponseSchema/index.tsx +151 -0
- package/src/theme/Schema/index.tsx +935 -0
- package/src/theme/SchemaItem/index.tsx +21 -43
- package/src/theme/SkeletonLoader/index.tsx +18 -0
- package/src/theme/StatusCodes/index.tsx +72 -0
- package/src/theme/styles.scss +56 -9
|
@@ -0,0 +1,192 @@
|
|
|
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 Markdown from "@theme/Markdown";
|
|
11
|
+
import ResponseSamples from "@theme/ResponseSamples";
|
|
12
|
+
import TabItem from "@theme/TabItem";
|
|
13
|
+
import { sampleResponseFromSchema } from "docusaurus-plugin-openapi-docs/lib/openapi/createResponseExample";
|
|
14
|
+
import format from "xml-formatter";
|
|
15
|
+
|
|
16
|
+
export function json2xml(o: Record<string, any>, tab: string): string {
|
|
17
|
+
const toXml = (v: any, name: string, ind: string): string => {
|
|
18
|
+
let xml = "";
|
|
19
|
+
if (v instanceof Array) {
|
|
20
|
+
for (let i = 0, n = v.length; i < n; i++) {
|
|
21
|
+
xml += ind + toXml(v[i], name, ind + "\t") + "\n";
|
|
22
|
+
}
|
|
23
|
+
} else if (typeof v === "object") {
|
|
24
|
+
let hasChild = false;
|
|
25
|
+
xml += ind + "<" + name;
|
|
26
|
+
for (const m in v) {
|
|
27
|
+
if (m.charAt(0) === "@") {
|
|
28
|
+
xml += " " + m.substr(1) + '="' + v[m].toString() + '"';
|
|
29
|
+
} else {
|
|
30
|
+
hasChild = true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
xml += hasChild ? ">" : "/>";
|
|
34
|
+
if (hasChild) {
|
|
35
|
+
for (const m2 in v) {
|
|
36
|
+
if (m2 === "#text") xml += v[m2];
|
|
37
|
+
else if (m2 === "#cdata") xml += "<![CDATA[" + v[m2] + "]]>";
|
|
38
|
+
else if (m2.charAt(0) !== "@") xml += toXml(v[m2], m2, ind + "\t");
|
|
39
|
+
}
|
|
40
|
+
xml +=
|
|
41
|
+
(xml.charAt(xml.length - 1) === "\n" ? ind : "") + "</" + name + ">";
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
xml += ind + "<" + name + ">" + v.toString() + "</" + name + ">";
|
|
45
|
+
}
|
|
46
|
+
return xml;
|
|
47
|
+
};
|
|
48
|
+
let xml = "";
|
|
49
|
+
for (const m3 in o) xml += toXml(o[m3], m3, "");
|
|
50
|
+
return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface ResponseExamplesProps {
|
|
54
|
+
responseExamples: any;
|
|
55
|
+
mimeType: string;
|
|
56
|
+
}
|
|
57
|
+
export const ResponseExamples: React.FC<ResponseExamplesProps> = ({
|
|
58
|
+
responseExamples,
|
|
59
|
+
mimeType,
|
|
60
|
+
}): any => {
|
|
61
|
+
let language = "shell";
|
|
62
|
+
if (mimeType.endsWith("json")) language = "json";
|
|
63
|
+
if (mimeType.endsWith("xml")) language = "xml";
|
|
64
|
+
|
|
65
|
+
// Map response examples to an array of TabItem elements
|
|
66
|
+
const examplesArray = Object.entries(responseExamples).map(
|
|
67
|
+
([exampleName, exampleValue]: any) => {
|
|
68
|
+
const isObject = typeof exampleValue.value === "object";
|
|
69
|
+
const responseExample = isObject
|
|
70
|
+
? JSON.stringify(exampleValue.value, null, 2)
|
|
71
|
+
: exampleValue.value;
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
<TabItem label={exampleName} value={exampleName} key={exampleName}>
|
|
76
|
+
{exampleValue.summary && (
|
|
77
|
+
<Markdown className="openapi-example__summary">
|
|
78
|
+
{exampleValue.summary}
|
|
79
|
+
</Markdown>
|
|
80
|
+
)}
|
|
81
|
+
<ResponseSamples
|
|
82
|
+
responseExample={responseExample}
|
|
83
|
+
language={language}
|
|
84
|
+
/>
|
|
85
|
+
</TabItem>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return examplesArray;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
interface ResponseExampleProps {
|
|
94
|
+
responseExample: any;
|
|
95
|
+
mimeType: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const ResponseExample: React.FC<ResponseExampleProps> = ({
|
|
99
|
+
responseExample,
|
|
100
|
+
mimeType,
|
|
101
|
+
}) => {
|
|
102
|
+
let language = "shell";
|
|
103
|
+
if (mimeType.endsWith("json")) {
|
|
104
|
+
language = "json";
|
|
105
|
+
}
|
|
106
|
+
if (mimeType.endsWith("xml")) {
|
|
107
|
+
language = "xml";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const isObject = typeof responseExample === "object";
|
|
111
|
+
const exampleContent = isObject
|
|
112
|
+
? JSON.stringify(responseExample, null, 2)
|
|
113
|
+
: responseExample;
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
<TabItem label="Example" value="Example">
|
|
118
|
+
{responseExample.summary && (
|
|
119
|
+
<Markdown className="openapi-example__summary">
|
|
120
|
+
{responseExample.summary}
|
|
121
|
+
</Markdown>
|
|
122
|
+
)}
|
|
123
|
+
<ResponseSamples responseExample={exampleContent} language={language} />
|
|
124
|
+
</TabItem>
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
interface ExampleFromSchemaProps {
|
|
129
|
+
schema: any;
|
|
130
|
+
mimeType: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const ExampleFromSchema: React.FC<ExampleFromSchemaProps> = ({
|
|
134
|
+
schema,
|
|
135
|
+
mimeType,
|
|
136
|
+
}) => {
|
|
137
|
+
const responseExample = sampleResponseFromSchema(schema);
|
|
138
|
+
|
|
139
|
+
if (mimeType.endsWith("xml")) {
|
|
140
|
+
let responseExampleObject;
|
|
141
|
+
try {
|
|
142
|
+
responseExampleObject = JSON.parse(JSON.stringify(responseExample));
|
|
143
|
+
} catch {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (typeof responseExampleObject === "object") {
|
|
148
|
+
let xmlExample;
|
|
149
|
+
try {
|
|
150
|
+
xmlExample = format(json2xml(responseExampleObject, ""), {
|
|
151
|
+
indentation: " ",
|
|
152
|
+
lineSeparator: "\n",
|
|
153
|
+
collapseContent: true,
|
|
154
|
+
});
|
|
155
|
+
} catch {
|
|
156
|
+
const xmlExampleWithRoot = { root: responseExampleObject };
|
|
157
|
+
try {
|
|
158
|
+
xmlExample = format(json2xml(xmlExampleWithRoot, ""), {
|
|
159
|
+
indentation: " ",
|
|
160
|
+
lineSeparator: "\n",
|
|
161
|
+
collapseContent: true,
|
|
162
|
+
});
|
|
163
|
+
} catch {
|
|
164
|
+
xmlExample = json2xml(responseExampleObject, "");
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return (
|
|
168
|
+
// @ts-ignore
|
|
169
|
+
<TabItem label="Example (auto)" value="Example (auto)">
|
|
170
|
+
<ResponseSamples responseExample={xmlExample} language="xml" />
|
|
171
|
+
</TabItem>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (
|
|
177
|
+
typeof responseExample === "object" ||
|
|
178
|
+
typeof responseExample === "string"
|
|
179
|
+
) {
|
|
180
|
+
return (
|
|
181
|
+
// @ts-ignore
|
|
182
|
+
<TabItem label="Example (auto)" value="Example (auto)">
|
|
183
|
+
<ResponseSamples
|
|
184
|
+
responseExample={JSON.stringify(responseExample, null, 2)}
|
|
185
|
+
language="json"
|
|
186
|
+
/>
|
|
187
|
+
</TabItem>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return null;
|
|
192
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
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 SchemaItem from "@theme/SchemaItem";
|
|
11
|
+
|
|
12
|
+
import { getQualifierMessage, getSchemaName } from "../../markdown/schema";
|
|
13
|
+
|
|
14
|
+
interface ResponseHeadersProps {
|
|
15
|
+
description?: string;
|
|
16
|
+
example?: string;
|
|
17
|
+
schema?: {
|
|
18
|
+
type?: string;
|
|
19
|
+
format?: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const ResponseHeaders: React.FC<{
|
|
24
|
+
responseHeaders?: Record<string, ResponseHeadersProps>;
|
|
25
|
+
}> = ({ responseHeaders }) => {
|
|
26
|
+
if (!responseHeaders) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<ul style={{ marginLeft: "1rem" }}>
|
|
32
|
+
{Object.entries(responseHeaders).map(([name, schema]) => {
|
|
33
|
+
return (
|
|
34
|
+
<SchemaItem
|
|
35
|
+
name={name}
|
|
36
|
+
collapsible={false}
|
|
37
|
+
schemaName={getSchemaName(schema)}
|
|
38
|
+
qualifierMessage={getQualifierMessage(schema)}
|
|
39
|
+
schema={schema}
|
|
40
|
+
discriminator={false}
|
|
41
|
+
children={null}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
})}
|
|
45
|
+
</ul>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default ResponseHeaders;
|
|
@@ -0,0 +1,151 @@
|
|
|
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, { Suspense } from "react";
|
|
9
|
+
|
|
10
|
+
import BrowserOnly from "@docusaurus/BrowserOnly";
|
|
11
|
+
import Details from "@theme/Details";
|
|
12
|
+
import Markdown from "@theme/Markdown";
|
|
13
|
+
import MimeTabs from "@theme/MimeTabs"; // Assume these components exist
|
|
14
|
+
import {
|
|
15
|
+
ExampleFromSchema,
|
|
16
|
+
ResponseExample,
|
|
17
|
+
ResponseExamples,
|
|
18
|
+
} from "@theme/ResponseExamples";
|
|
19
|
+
import SchemaNode from "@theme/Schema";
|
|
20
|
+
import SchemaTabs from "@theme/SchemaTabs";
|
|
21
|
+
import SkeletonLoader from "@theme/SkeletonLoader";
|
|
22
|
+
import TabItem from "@theme/TabItem";
|
|
23
|
+
import { MediaTypeObject } from "docusaurus-plugin-openapi-docs/lib/openapi/types";
|
|
24
|
+
|
|
25
|
+
interface Props {
|
|
26
|
+
style?: React.CSSProperties;
|
|
27
|
+
title: string;
|
|
28
|
+
body: {
|
|
29
|
+
content?: {
|
|
30
|
+
[key: string]: MediaTypeObject;
|
|
31
|
+
};
|
|
32
|
+
description?: string;
|
|
33
|
+
required?: string[] | boolean;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const ResponseSchemaComponent: React.FC<Props> = ({
|
|
38
|
+
title,
|
|
39
|
+
body,
|
|
40
|
+
style,
|
|
41
|
+
}): any => {
|
|
42
|
+
if (
|
|
43
|
+
body === undefined ||
|
|
44
|
+
body.content === undefined ||
|
|
45
|
+
Object.keys(body).length === 0 ||
|
|
46
|
+
Object.keys(body.content).length === 0
|
|
47
|
+
) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Get all MIME types, including vendor-specific
|
|
52
|
+
const mimeTypes = Object.keys(body.content);
|
|
53
|
+
if (mimeTypes && mimeTypes.length) {
|
|
54
|
+
return (
|
|
55
|
+
<MimeTabs className="openapi-tabs__mime" schemaType="response">
|
|
56
|
+
{mimeTypes.map((mimeType: any) => {
|
|
57
|
+
const responseExamples = body.content![mimeType].examples;
|
|
58
|
+
const responseExample = body.content![mimeType].example;
|
|
59
|
+
const firstBody: any =
|
|
60
|
+
body.content![mimeType].schema ?? body.content![mimeType];
|
|
61
|
+
|
|
62
|
+
if (
|
|
63
|
+
firstBody === undefined &&
|
|
64
|
+
responseExample === undefined &&
|
|
65
|
+
responseExamples === undefined
|
|
66
|
+
) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (firstBody) {
|
|
71
|
+
return (
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
<TabItem key={mimeType} label={mimeType} value={mimeType}>
|
|
74
|
+
<SchemaTabs className="openapi-tabs__schema">
|
|
75
|
+
{/* @ts-ignore */}
|
|
76
|
+
<TabItem key={title} label={title} value={title}>
|
|
77
|
+
<Details
|
|
78
|
+
className="openapi-markdown__details response"
|
|
79
|
+
data-collapsed={false}
|
|
80
|
+
open={true}
|
|
81
|
+
style={style}
|
|
82
|
+
summary={
|
|
83
|
+
<>
|
|
84
|
+
<summary>
|
|
85
|
+
<strong className="openapi-markdown__details-summary-response">
|
|
86
|
+
{title}
|
|
87
|
+
{body.required === true && (
|
|
88
|
+
<span className="openapi-schema__required">
|
|
89
|
+
required
|
|
90
|
+
</span>
|
|
91
|
+
)}
|
|
92
|
+
</strong>
|
|
93
|
+
</summary>
|
|
94
|
+
</>
|
|
95
|
+
}
|
|
96
|
+
>
|
|
97
|
+
<div style={{ textAlign: "left", marginLeft: "1rem" }}>
|
|
98
|
+
{body.description && (
|
|
99
|
+
<div
|
|
100
|
+
style={{ marginTop: "1rem", marginBottom: "1rem" }}
|
|
101
|
+
>
|
|
102
|
+
<Markdown>{body.description}</Markdown>
|
|
103
|
+
</div>
|
|
104
|
+
)}
|
|
105
|
+
</div>
|
|
106
|
+
<ul style={{ marginLeft: "1rem" }}>
|
|
107
|
+
<SchemaNode schema={firstBody} schemaType="response" />
|
|
108
|
+
</ul>
|
|
109
|
+
</Details>
|
|
110
|
+
</TabItem>
|
|
111
|
+
{firstBody &&
|
|
112
|
+
ExampleFromSchema({
|
|
113
|
+
schema: firstBody,
|
|
114
|
+
mimeType: mimeType,
|
|
115
|
+
})}
|
|
116
|
+
|
|
117
|
+
{responseExamples &&
|
|
118
|
+
ResponseExamples({ responseExamples, mimeType })}
|
|
119
|
+
|
|
120
|
+
{responseExample &&
|
|
121
|
+
ResponseExample({ responseExample, mimeType })}
|
|
122
|
+
</SchemaTabs>
|
|
123
|
+
</TabItem>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
return undefined;
|
|
127
|
+
})}
|
|
128
|
+
</MimeTabs>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
return undefined;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const ResponseSchema: React.FC<Props> = (props) => {
|
|
135
|
+
return (
|
|
136
|
+
<BrowserOnly fallback={<SkeletonLoader size="md" />}>
|
|
137
|
+
{() => {
|
|
138
|
+
const LazyComponent = React.lazy(() =>
|
|
139
|
+
Promise.resolve({ default: ResponseSchemaComponent })
|
|
140
|
+
);
|
|
141
|
+
return (
|
|
142
|
+
<Suspense fallback={null}>
|
|
143
|
+
<LazyComponent {...props} />
|
|
144
|
+
</Suspense>
|
|
145
|
+
);
|
|
146
|
+
}}
|
|
147
|
+
</BrowserOnly>
|
|
148
|
+
);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export default ResponseSchema;
|