docusaurus-theme-openapi-docs 4.2.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.
@@ -7,16 +7,12 @@
7
7
 
8
8
  import React from "react";
9
9
 
10
- import CodeBlock from "@theme/CodeBlock";
10
+ import Markdown from "@theme/Markdown";
11
11
  import SchemaTabs from "@theme/SchemaTabs";
12
12
  import TabItem from "@theme/TabItem";
13
13
  /* eslint-disable import/no-extraneous-dependencies*/
14
14
  import clsx from "clsx";
15
- import ReactMarkdown from "react-markdown";
16
- import rehypeRaw from "rehype-raw";
17
- import remarkGfm from "remark-gfm";
18
15
 
19
- import { createDescription } from "../../markdown/createDescription";
20
16
  import { getQualifierMessage, getSchemaName } from "../../markdown/schema";
21
17
  import { guard, toString } from "../../markdown/utils";
22
18
 
@@ -97,34 +93,12 @@ function ParamsItem({ param, ...rest }: Props) {
97
93
  <span className="openapi-schema__deprecated">deprecated</span>
98
94
  ));
99
95
 
100
- const renderSchema = guard(getQualifierMessage(schema), (message) => (
101
- <div>
102
- <ReactMarkdown
103
- children={createDescription(message)}
104
- rehypePlugins={[rehypeRaw]}
105
- />
106
- </div>
96
+ const renderQualifier = guard(getQualifierMessage(schema), (qualifier) => (
97
+ <Markdown>{qualifier}</Markdown>
107
98
  ));
108
99
 
109
100
  const renderDescription = guard(description, (description) => (
110
- <>
111
- <ReactMarkdown
112
- children={createDescription(description)}
113
- components={{
114
- pre: "div",
115
- code({ node, inline, className, children, ...props }) {
116
- const match = /language-(\w+)/.exec(className || "");
117
- if (inline) return <code>{children}</code>;
118
- return !inline && match ? (
119
- <CodeBlock className={className}>{children}</CodeBlock>
120
- ) : (
121
- <CodeBlock>{children}</CodeBlock>
122
- );
123
- },
124
- }}
125
- rehypePlugins={[rehypeRaw]}
126
- />
127
- </>
101
+ <Markdown>{description}</Markdown>
128
102
  ));
129
103
 
130
104
  const renderEnumDescriptions = guard(
@@ -132,11 +106,7 @@ function ParamsItem({ param, ...rest }: Props) {
132
106
  (value) => {
133
107
  return (
134
108
  <div style={{ marginTop: ".5rem" }}>
135
- <ReactMarkdown
136
- rehypePlugins={[rehypeRaw]}
137
- remarkPlugins={[remarkGfm]}
138
- children={value}
139
- />
109
+ <Markdown>{value}</Markdown>
140
110
  </div>
141
111
  );
142
112
  }
@@ -217,7 +187,7 @@ function ParamsItem({ param, ...rest }: Props) {
217
187
  {renderSchemaRequired}
218
188
  {renderDeprecated}
219
189
  </span>
220
- {renderSchema}
190
+ {renderQualifier}
221
191
  {renderDescription}
222
192
  {renderEnumDescriptions}
223
193
  {renderDefaultValue()}
@@ -9,11 +9,11 @@ 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 SchemaNode from "@theme/Schema";
14
15
  import SkeletonLoader from "@theme/SkeletonLoader";
15
16
  import TabItem from "@theme/TabItem";
16
- import { createDescription } from "docusaurus-plugin-openapi-docs/lib/markdown/createDescription";
17
17
  import { MediaTypeObject } from "docusaurus-plugin-openapi-docs/lib/openapi/types";
18
18
 
19
19
  interface Props {
@@ -78,7 +78,7 @@ const RequestSchemaComponent: React.FC<Props> = ({ title, body, style }) => {
78
78
  <div style={{ textAlign: "left", marginLeft: "1rem" }}>
79
79
  {body.description && (
80
80
  <div style={{ marginTop: "1rem", marginBottom: "1rem" }}>
81
- {createDescription(body.description)}
81
+ <Markdown>{body.description}</Markdown>
82
82
  </div>
83
83
  )}
84
84
  </div>
@@ -131,7 +131,7 @@ const RequestSchemaComponent: React.FC<Props> = ({ title, body, style }) => {
131
131
  <div style={{ textAlign: "left", marginLeft: "1rem" }}>
132
132
  {body.description && (
133
133
  <div style={{ marginTop: "1rem", marginBottom: "1rem" }}>
134
- {createDescription(body.description)}
134
+ <Markdown>{body.description}</Markdown>
135
135
  </div>
136
136
  )}
137
137
  </div>
@@ -7,14 +7,12 @@
7
7
 
8
8
  import React from "react";
9
9
 
10
- import ParamsItem from "@theme/ParamsItem";
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 ParameterProps {
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
- }> = ({ responseExamples, mimeType }): any => {
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
- <div className="openapi-example__summary">
77
+ <Markdown className="openapi-example__summary">
186
78
  {exampleValue.summary}
187
- </div>
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
- export const ResponseExample: React.FC<{
93
+ interface ResponseExampleProps {
202
94
  responseExample: any;
203
95
  mimeType: string;
204
- }> = ({ responseExample, mimeType }) => {
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
- <div className="openapi-example__summary">
119
+ <Markdown className="openapi-example__summary">
223
120
  {responseExample.summary}
224
- </div>
121
+ </Markdown>
225
122
  )}
226
123
  <ResponseSamples responseExample={exampleContent} language={language} />
227
124
  </TabItem>
228
125
  );
229
126
  };
230
127
 
231
- export const ExampleFromSchema: React.FC<{ schema: any; mimeType: string }> = ({
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
- {createDescription(body.description)}
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 Markdown: React.FC<MarkdownProps> = ({ text }) => {
45
+ const MarkdownWrapper: React.FC<MarkdownProps> = ({ text }) => {
48
46
  return (
49
47
  <div style={{ marginTop: ".5rem", marginBottom: ".5rem" }}>
50
- <ReactMarkdown
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 && <Markdown text={schema.description} />}
260
+ {schema.description && (
261
+ <MarkdownWrapper text={schema.description} />
262
+ )}
266
263
  {getQualifierMessage(discriminator) && (
267
- <Markdown text={getQualifierMessage(discriminator)} />
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
- const discriminatorProperty = schema.properties![discriminator.propertyName];
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![discriminator.propertyName] = {
357
- ...schema.properties![discriminator.propertyName],
358
- ...subProperties[discriminator.propertyName],
359
- };
360
- if (subSchema.required && !schema.required) {
361
- schema.required = subSchema.required;
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 && <Markdown text={schema.description} />}
490
+ {schema.description && <MarkdownWrapper text={schema.description} />}
484
491
  {getQualifierMessage(schema) && (
485
- <Markdown text={getQualifierMessage(schema)} />
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 CodeBlock from "@theme/CodeBlock";
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
- <ReactMarkdown
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
- <div>
112
- <ReactMarkdown
113
- children={createDescription(description)}
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
- <div>
133
- <ReactMarkdown
134
- children={createDescription(message)}
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"> {schemaName}</span>
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 { ResponseHeaders } from "@theme/ResponseExamples";
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
- {createDescription(response.description)}
42
+ <Markdown>{response.description}</Markdown>
43
43
  </div>
44
44
  )}
45
45
  </div>