docusaurus-theme-openapi-docs 4.2.0 → 4.3.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/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 +41 -45
- package/lib/theme/ApiExplorer/buildPostmanRequest.js +1 -1
- package/lib/theme/Markdown/Details/_Details.scss +5 -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 +29 -21
- package/lib/theme/SchemaItem/index.js +7 -41
- package/lib/theme/StatusCodes/index.js +10 -7
- package/package.json +10 -6
- 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 +45 -47
- package/src/theme/ApiExplorer/buildPostmanRequest.ts +1 -1
- package/src/theme/Markdown/Details/_Details.scss +5 -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 +29 -22
- package/src/theme/SchemaItem/index.tsx +11 -35
- package/src/theme/StatusCodes/index.tsx +3 -3
|
@@ -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">
|
|
@@ -320,7 +317,10 @@ const DiscriminatorNode: React.FC<DiscriminatorNodeProps> = ({
|
|
|
320
317
|
let discriminatedSchemas: any = {};
|
|
321
318
|
let inferredMapping: any = {};
|
|
322
319
|
|
|
323
|
-
|
|
320
|
+
// default to empty object if no parent-level properties exist
|
|
321
|
+
const discriminatorProperty = schema.properties
|
|
322
|
+
? schema.properties![discriminator.propertyName]
|
|
323
|
+
: {};
|
|
324
324
|
|
|
325
325
|
if (schema.allOf) {
|
|
326
326
|
const mergedSchemas = mergeAllOf(schema) as SchemaObject;
|
|
@@ -353,21 +353,28 @@ const DiscriminatorNode: React.FC<DiscriminatorNodeProps> = ({
|
|
|
353
353
|
|
|
354
354
|
const subProperties = subSchema.properties || mergedSubSchema.properties;
|
|
355
355
|
if (subProperties[discriminator.propertyName]) {
|
|
356
|
-
schema.properties
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
356
|
+
if (schema.properties) {
|
|
357
|
+
schema.properties![discriminator.propertyName] = {
|
|
358
|
+
...schema.properties![discriminator.propertyName],
|
|
359
|
+
...subProperties[discriminator.propertyName],
|
|
360
|
+
};
|
|
361
|
+
if (subSchema.required && !schema.required) {
|
|
362
|
+
schema.required = subSchema.required;
|
|
363
|
+
}
|
|
364
|
+
// Avoid duplicating property
|
|
365
|
+
delete subProperties[discriminator.propertyName];
|
|
366
|
+
} else {
|
|
367
|
+
schema.properties = {};
|
|
368
|
+
schema.properties[discriminator.propertyName] =
|
|
369
|
+
subProperties[discriminator.propertyName];
|
|
370
|
+
// Avoid duplicating property
|
|
371
|
+
delete subProperties[discriminator.propertyName];
|
|
362
372
|
}
|
|
363
|
-
// Avoid duplicating property
|
|
364
|
-
delete subProperties[discriminator.propertyName];
|
|
365
373
|
}
|
|
366
374
|
});
|
|
367
375
|
|
|
368
376
|
const name = discriminator.propertyName;
|
|
369
377
|
const schemaName = getSchemaName(discriminatorProperty);
|
|
370
|
-
|
|
371
378
|
// Default case for discriminator without oneOf/anyOf/allOf
|
|
372
379
|
return (
|
|
373
380
|
<PropertyDiscriminator
|
|
@@ -480,9 +487,9 @@ const SchemaNodeDetails: React.FC<SchemaEdgeProps> = ({
|
|
|
480
487
|
}
|
|
481
488
|
>
|
|
482
489
|
<div style={{ marginLeft: "1rem" }}>
|
|
483
|
-
{schema.description && <
|
|
490
|
+
{schema.description && <MarkdownWrapper text={schema.description} />}
|
|
484
491
|
{getQualifierMessage(schema) && (
|
|
485
|
-
<
|
|
492
|
+
<MarkdownWrapper text={getQualifierMessage(schema)} />
|
|
486
493
|
)}
|
|
487
494
|
<SchemaNode schema={schema} schemaType={schemaType} />
|
|
488
495
|
</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() {
|
|
@@ -195,7 +169,9 @@ export default function SchemaItem(props: Props) {
|
|
|
195
169
|
>
|
|
196
170
|
{name}
|
|
197
171
|
</strong>
|
|
198
|
-
<span className="openapi-schema__name">
|
|
172
|
+
<span className="openapi-schema__name">
|
|
173
|
+
{Array.isArray(schemaName) ? schemaName.join(" | ") : schemaName}
|
|
174
|
+
</span>
|
|
199
175
|
{(nullable || required || deprecated) && (
|
|
200
176
|
<span className="openapi-schema__divider"></span>
|
|
201
177
|
)}
|
|
@@ -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>
|