docusaurus-theme-openapi-docs 0.0.0-952 → 0.0.0-953
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/Body/index.js +11 -2
- package/lib/theme/Markdown/index.js +160 -18
- package/lib/theme/ParamsItem/index.js +7 -48
- package/lib/theme/RequestSchema/index.js +11 -3
- package/lib/theme/ResponseExamples/index.d.ts +9 -39
- package/lib/theme/ResponseExamples/index.js +3 -99
- package/lib/theme/ResponseHeaders/index.d.ts +13 -0
- package/lib/theme/ResponseHeaders/index.js +39 -0
- package/lib/theme/ResponseSchema/index.js +4 -2
- package/lib/theme/Schema/index.js +9 -12
- package/lib/theme/SchemaItem/index.js +6 -39
- package/lib/theme/StatusCodes/index.js +10 -7
- package/package.json +4 -3
- package/src/theme/ApiExplorer/Body/index.tsx +3 -2
- package/src/theme/Markdown/index.js +160 -18
- package/src/theme/ParamsItem/index.tsx +6 -36
- package/src/theme/RequestSchema/index.tsx +3 -3
- package/src/theme/ResponseExamples/index.tsx +24 -122
- package/src/theme/ResponseHeaders/index.tsx +49 -0
- package/src/theme/ResponseSchema/index.tsx +2 -2
- package/src/theme/Schema/index.tsx +9 -12
- package/src/theme/SchemaItem/index.tsx +8 -34
- package/src/theme/StatusCodes/index.tsx +3 -3
|
@@ -7,14 +7,12 @@
|
|
|
7
7
|
|
|
8
8
|
import React from "react";
|
|
9
9
|
|
|
10
|
-
import
|
|
10
|
+
import Markdown from "@theme/Markdown";
|
|
11
11
|
import ResponseSamples from "@theme/ResponseSamples";
|
|
12
12
|
import TabItem from "@theme/TabItem";
|
|
13
|
-
import { createDescription } from "docusaurus-plugin-openapi-docs/lib/markdown/createDescription";
|
|
14
13
|
import { sampleResponseFromSchema } from "docusaurus-plugin-openapi-docs/lib/openapi/createResponseExample";
|
|
15
14
|
import format from "xml-formatter";
|
|
16
15
|
|
|
17
|
-
// Utility function
|
|
18
16
|
export function json2xml(o: Record<string, any>, tab: string): string {
|
|
19
17
|
const toXml = (v: any, name: string, ind: string): string => {
|
|
20
18
|
let xml = "";
|
|
@@ -52,120 +50,14 @@ export function json2xml(o: Record<string, any>, tab: string): string {
|
|
|
52
50
|
return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
|
|
53
51
|
}
|
|
54
52
|
|
|
55
|
-
interface
|
|
56
|
-
in: string;
|
|
57
|
-
name: string;
|
|
58
|
-
schema?: {
|
|
59
|
-
type?: string;
|
|
60
|
-
items?: Record<string, any>;
|
|
61
|
-
};
|
|
62
|
-
enumDescriptions?: [string, string][];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
interface ResponseHeaderProps {
|
|
66
|
-
description?: string;
|
|
67
|
-
example?: string;
|
|
68
|
-
schema?: {
|
|
69
|
-
type?: string;
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
interface ResponseExampleProps {
|
|
74
|
-
value: any;
|
|
75
|
-
summary?: string;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
interface Props {
|
|
79
|
-
parameters?: ParameterProps[];
|
|
80
|
-
type: string;
|
|
81
|
-
responseHeaders?: Record<string, ResponseHeaderProps>;
|
|
82
|
-
responseExamples?: Record<string, ResponseExampleProps>;
|
|
83
|
-
responseExample?: any;
|
|
84
|
-
schema?: any;
|
|
85
|
-
mimeType: string;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// React components
|
|
89
|
-
export const ParamsDetails: React.FC<Props> = ({ parameters, type }) => {
|
|
90
|
-
const params = parameters?.filter((param) => param?.in === type);
|
|
91
|
-
|
|
92
|
-
if (!params || params.length === 0) {
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return (
|
|
97
|
-
<details
|
|
98
|
-
className="openapi-markdown__details"
|
|
99
|
-
data-collapsed={false}
|
|
100
|
-
open={true}
|
|
101
|
-
style={{ marginBottom: "1rem" }}
|
|
102
|
-
>
|
|
103
|
-
<summary>
|
|
104
|
-
<h3 className="openapi-markdown__details-summary-header-params">
|
|
105
|
-
{`${type.charAt(0).toUpperCase() + type.slice(1)} Parameters`}
|
|
106
|
-
</h3>
|
|
107
|
-
</summary>
|
|
108
|
-
<div>
|
|
109
|
-
<ul>
|
|
110
|
-
{params.map((param, index) => (
|
|
111
|
-
<ParamsItem
|
|
112
|
-
key={index}
|
|
113
|
-
className="paramsItem"
|
|
114
|
-
// @ts-ignore
|
|
115
|
-
param={{
|
|
116
|
-
...param,
|
|
117
|
-
enumDescriptions: Object.entries(
|
|
118
|
-
param?.schema?.items?.["x-enumDescriptions"] ?? {}
|
|
119
|
-
),
|
|
120
|
-
}}
|
|
121
|
-
/>
|
|
122
|
-
))}
|
|
123
|
-
</ul>
|
|
124
|
-
</div>
|
|
125
|
-
</details>
|
|
126
|
-
);
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
export const ResponseHeaders: React.FC<{
|
|
130
|
-
responseHeaders?: Record<string, ResponseHeaderProps>;
|
|
131
|
-
}> = ({ responseHeaders }) => {
|
|
132
|
-
if (!responseHeaders) {
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return (
|
|
137
|
-
<ul style={{ marginLeft: "1rem" }}>
|
|
138
|
-
{Object.entries(responseHeaders).map(([headerName, headerObj]) => {
|
|
139
|
-
const { description, example, schema } = headerObj;
|
|
140
|
-
const type = schema?.type ?? "any";
|
|
141
|
-
|
|
142
|
-
return (
|
|
143
|
-
<li className="schemaItem" key={headerName}>
|
|
144
|
-
<details>
|
|
145
|
-
<summary>
|
|
146
|
-
<strong>{headerName}</strong>
|
|
147
|
-
{type && <span style={{ opacity: "0.6" }}> {type}</span>}
|
|
148
|
-
</summary>
|
|
149
|
-
<div>
|
|
150
|
-
{description && (
|
|
151
|
-
<div style={{ marginTop: ".5rem", marginBottom: ".5rem" }}>
|
|
152
|
-
{example && `Example: ${example}`}
|
|
153
|
-
{createDescription(description)}
|
|
154
|
-
</div>
|
|
155
|
-
)}
|
|
156
|
-
</div>
|
|
157
|
-
</details>
|
|
158
|
-
</li>
|
|
159
|
-
);
|
|
160
|
-
})}
|
|
161
|
-
</ul>
|
|
162
|
-
);
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
export const ResponseExamples: React.FC<{
|
|
53
|
+
interface ResponseExamplesProps {
|
|
166
54
|
responseExamples: any;
|
|
167
55
|
mimeType: string;
|
|
168
|
-
}
|
|
56
|
+
}
|
|
57
|
+
export const ResponseExamples: React.FC<ResponseExamplesProps> = ({
|
|
58
|
+
responseExamples,
|
|
59
|
+
mimeType,
|
|
60
|
+
}): any => {
|
|
169
61
|
let language = "shell";
|
|
170
62
|
if (mimeType.endsWith("json")) language = "json";
|
|
171
63
|
if (mimeType.endsWith("xml")) language = "xml";
|
|
@@ -182,9 +74,9 @@ export const ResponseExamples: React.FC<{
|
|
|
182
74
|
// @ts-ignore
|
|
183
75
|
<TabItem label={exampleName} value={exampleName} key={exampleName}>
|
|
184
76
|
{exampleValue.summary && (
|
|
185
|
-
<
|
|
77
|
+
<Markdown className="openapi-example__summary">
|
|
186
78
|
{exampleValue.summary}
|
|
187
|
-
</
|
|
79
|
+
</Markdown>
|
|
188
80
|
)}
|
|
189
81
|
<ResponseSamples
|
|
190
82
|
responseExample={responseExample}
|
|
@@ -198,10 +90,15 @@ export const ResponseExamples: React.FC<{
|
|
|
198
90
|
return examplesArray;
|
|
199
91
|
};
|
|
200
92
|
|
|
201
|
-
|
|
93
|
+
interface ResponseExampleProps {
|
|
202
94
|
responseExample: any;
|
|
203
95
|
mimeType: string;
|
|
204
|
-
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const ResponseExample: React.FC<ResponseExampleProps> = ({
|
|
99
|
+
responseExample,
|
|
100
|
+
mimeType,
|
|
101
|
+
}) => {
|
|
205
102
|
let language = "shell";
|
|
206
103
|
if (mimeType.endsWith("json")) {
|
|
207
104
|
language = "json";
|
|
@@ -219,16 +116,21 @@ export const ResponseExample: React.FC<{
|
|
|
219
116
|
// @ts-ignore
|
|
220
117
|
<TabItem label="Example" value="Example">
|
|
221
118
|
{responseExample.summary && (
|
|
222
|
-
<
|
|
119
|
+
<Markdown className="openapi-example__summary">
|
|
223
120
|
{responseExample.summary}
|
|
224
|
-
</
|
|
121
|
+
</Markdown>
|
|
225
122
|
)}
|
|
226
123
|
<ResponseSamples responseExample={exampleContent} language={language} />
|
|
227
124
|
</TabItem>
|
|
228
125
|
);
|
|
229
126
|
};
|
|
230
127
|
|
|
231
|
-
|
|
128
|
+
interface ExampleFromSchemaProps {
|
|
129
|
+
schema: any;
|
|
130
|
+
mimeType: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const ExampleFromSchema: React.FC<ExampleFromSchemaProps> = ({
|
|
232
134
|
schema,
|
|
233
135
|
mimeType,
|
|
234
136
|
}) => {
|
|
@@ -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;
|
|
@@ -9,6 +9,7 @@ import React, { Suspense } from "react";
|
|
|
9
9
|
|
|
10
10
|
import BrowserOnly from "@docusaurus/BrowserOnly";
|
|
11
11
|
import Details from "@theme/Details";
|
|
12
|
+
import Markdown from "@theme/Markdown";
|
|
12
13
|
import MimeTabs from "@theme/MimeTabs"; // Assume these components exist
|
|
13
14
|
import {
|
|
14
15
|
ExampleFromSchema,
|
|
@@ -19,7 +20,6 @@ import SchemaNode from "@theme/Schema";
|
|
|
19
20
|
import SchemaTabs from "@theme/SchemaTabs";
|
|
20
21
|
import SkeletonLoader from "@theme/SkeletonLoader";
|
|
21
22
|
import TabItem from "@theme/TabItem";
|
|
22
|
-
import { createDescription } from "docusaurus-plugin-openapi-docs/lib/markdown/createDescription";
|
|
23
23
|
import { MediaTypeObject } from "docusaurus-plugin-openapi-docs/lib/openapi/types";
|
|
24
24
|
|
|
25
25
|
interface Props {
|
|
@@ -99,7 +99,7 @@ const ResponseSchemaComponent: React.FC<Props> = ({
|
|
|
99
99
|
<div
|
|
100
100
|
style={{ marginTop: "1rem", marginBottom: "1rem" }}
|
|
101
101
|
>
|
|
102
|
-
{
|
|
102
|
+
<Markdown>{body.description}</Markdown>
|
|
103
103
|
</div>
|
|
104
104
|
)}
|
|
105
105
|
</div>
|
|
@@ -10,21 +10,19 @@ import React from "react";
|
|
|
10
10
|
import { ClosingArrayBracket, OpeningArrayBracket } from "@theme/ArrayBrackets";
|
|
11
11
|
import Details from "@theme/Details";
|
|
12
12
|
import DiscriminatorTabs from "@theme/DiscriminatorTabs";
|
|
13
|
+
import Markdown from "@theme/Markdown";
|
|
13
14
|
import SchemaItem from "@theme/SchemaItem";
|
|
14
15
|
import SchemaTabs from "@theme/SchemaTabs";
|
|
15
16
|
import TabItem from "@theme/TabItem";
|
|
16
17
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
17
18
|
import { merge } from "allof-merge";
|
|
18
19
|
import clsx from "clsx";
|
|
19
|
-
import { createDescription } from "docusaurus-plugin-openapi-docs/lib/markdown/createDescription";
|
|
20
20
|
import {
|
|
21
21
|
getQualifierMessage,
|
|
22
22
|
getSchemaName,
|
|
23
23
|
} from "docusaurus-plugin-openapi-docs/lib/markdown/schema";
|
|
24
24
|
import { SchemaObject } from "docusaurus-plugin-openapi-docs/lib/openapi/types";
|
|
25
25
|
import isEmpty from "lodash/isEmpty";
|
|
26
|
-
import ReactMarkdown from "react-markdown";
|
|
27
|
-
import rehypeRaw from "rehype-raw";
|
|
28
26
|
|
|
29
27
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
30
28
|
// const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
|
|
@@ -44,13 +42,10 @@ interface MarkdownProps {
|
|
|
44
42
|
}
|
|
45
43
|
|
|
46
44
|
// Renders string as markdown, useful for descriptions and qualifiers
|
|
47
|
-
const
|
|
45
|
+
const MarkdownWrapper: React.FC<MarkdownProps> = ({ text }) => {
|
|
48
46
|
return (
|
|
49
47
|
<div style={{ marginTop: ".5rem", marginBottom: ".5rem" }}>
|
|
50
|
-
<
|
|
51
|
-
children={createDescription(text)}
|
|
52
|
-
rehypePlugins={[rehypeRaw]}
|
|
53
|
-
/>
|
|
48
|
+
<Markdown>{text}</Markdown>
|
|
54
49
|
</div>
|
|
55
50
|
);
|
|
56
51
|
};
|
|
@@ -262,9 +257,11 @@ const PropertyDiscriminator: React.FC<SchemaEdgeProps> = ({
|
|
|
262
257
|
)}
|
|
263
258
|
</span>
|
|
264
259
|
<div style={{ marginLeft: "1rem" }}>
|
|
265
|
-
{schema.description &&
|
|
260
|
+
{schema.description && (
|
|
261
|
+
<MarkdownWrapper text={schema.description} />
|
|
262
|
+
)}
|
|
266
263
|
{getQualifierMessage(discriminator) && (
|
|
267
|
-
<
|
|
264
|
+
<MarkdownWrapper text={getQualifierMessage(discriminator)} />
|
|
268
265
|
)}
|
|
269
266
|
</div>
|
|
270
267
|
<DiscriminatorTabs className="openapi-tabs__discriminator">
|
|
@@ -480,9 +477,9 @@ const SchemaNodeDetails: React.FC<SchemaEdgeProps> = ({
|
|
|
480
477
|
}
|
|
481
478
|
>
|
|
482
479
|
<div style={{ marginLeft: "1rem" }}>
|
|
483
|
-
{schema.description && <
|
|
480
|
+
{schema.description && <MarkdownWrapper text={schema.description} />}
|
|
484
481
|
{getQualifierMessage(schema) && (
|
|
485
|
-
<
|
|
482
|
+
<MarkdownWrapper text={getQualifierMessage(schema)} />
|
|
486
483
|
)}
|
|
487
484
|
<SchemaNode schema={schema} schemaType={schemaType} />
|
|
488
485
|
</div>
|
|
@@ -7,13 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
import React, { ReactNode } from "react";
|
|
9
9
|
|
|
10
|
-
import
|
|
10
|
+
import Markdown from "@theme/Markdown";
|
|
11
11
|
import clsx from "clsx";
|
|
12
|
-
import ReactMarkdown from "react-markdown";
|
|
13
|
-
import rehypeRaw from "rehype-raw";
|
|
14
|
-
import remarkGfm from "remark-gfm";
|
|
15
12
|
|
|
16
|
-
import { createDescription } from "../../markdown/createDescription";
|
|
17
13
|
import { guard } from "../../markdown/utils";
|
|
18
14
|
|
|
19
15
|
export interface Props {
|
|
@@ -97,44 +93,22 @@ export default function SchemaItem(props: Props) {
|
|
|
97
93
|
(value) => {
|
|
98
94
|
return (
|
|
99
95
|
<div style={{ marginTop: ".5rem" }}>
|
|
100
|
-
<
|
|
101
|
-
remarkPlugins={[remarkGfm]}
|
|
102
|
-
rehypePlugins={[rehypeRaw]}
|
|
103
|
-
children={value}
|
|
104
|
-
/>
|
|
96
|
+
<Markdown>{value}</Markdown>
|
|
105
97
|
</div>
|
|
106
98
|
);
|
|
107
99
|
}
|
|
108
100
|
);
|
|
109
101
|
|
|
110
102
|
const renderSchemaDescription = guard(schemaDescription, (description) => (
|
|
111
|
-
|
|
112
|
-
<
|
|
113
|
-
|
|
114
|
-
components={{
|
|
115
|
-
pre: "div",
|
|
116
|
-
code({ node, inline, className, children, ...props }) {
|
|
117
|
-
const match = /language-(\w+)/.exec(className || "");
|
|
118
|
-
if (inline) return <code>{children}</code>;
|
|
119
|
-
return !inline && match ? (
|
|
120
|
-
<CodeBlock className={className}>{children}</CodeBlock>
|
|
121
|
-
) : (
|
|
122
|
-
<CodeBlock>{children}</CodeBlock>
|
|
123
|
-
);
|
|
124
|
-
},
|
|
125
|
-
}}
|
|
126
|
-
rehypePlugins={[rehypeRaw]}
|
|
127
|
-
/>
|
|
128
|
-
</div>
|
|
103
|
+
<>
|
|
104
|
+
<Markdown>{description}</Markdown>
|
|
105
|
+
</>
|
|
129
106
|
));
|
|
130
107
|
|
|
131
108
|
const renderQualifierMessage = guard(qualifierMessage, (message) => (
|
|
132
|
-
|
|
133
|
-
<
|
|
134
|
-
|
|
135
|
-
rehypePlugins={[rehypeRaw]}
|
|
136
|
-
/>
|
|
137
|
-
</div>
|
|
109
|
+
<>
|
|
110
|
+
<Markdown>{message}</Markdown>
|
|
111
|
+
</>
|
|
138
112
|
));
|
|
139
113
|
|
|
140
114
|
function renderDefaultValue() {
|
|
@@ -9,10 +9,10 @@ import React from "react";
|
|
|
9
9
|
|
|
10
10
|
import ApiTabs from "@theme/ApiTabs";
|
|
11
11
|
import Details from "@theme/Details";
|
|
12
|
-
import
|
|
12
|
+
import Markdown from "@theme/Markdown";
|
|
13
|
+
import ResponseHeaders from "@theme/ResponseHeaders";
|
|
13
14
|
import ResponseSchema from "@theme/ResponseSchema";
|
|
14
15
|
import TabItem from "@theme/TabItem";
|
|
15
|
-
import { createDescription } from "docusaurus-plugin-openapi-docs/lib/markdown/createDescription";
|
|
16
16
|
import { ApiItem } from "docusaurus-plugin-openapi-docs/lib/types";
|
|
17
17
|
|
|
18
18
|
interface Props {
|
|
@@ -39,7 +39,7 @@ const StatusCodes: React.FC<Props> = ({ label, id, responses }: any) => {
|
|
|
39
39
|
<div>
|
|
40
40
|
{response.description && (
|
|
41
41
|
<div style={{ marginTop: ".5rem", marginBottom: ".5rem" }}>
|
|
42
|
-
{
|
|
42
|
+
<Markdown>{response.description}</Markdown>
|
|
43
43
|
</div>
|
|
44
44
|
)}
|
|
45
45
|
</div>
|