docusaurus-theme-openapi-docs 0.0.0-1079 → 0.0.0-1080
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/schema.js +3 -0
- package/lib/theme/Example/_Example.scss +11 -0
- package/lib/theme/Example/index.d.ts +24 -0
- package/lib/theme/Example/index.js +170 -0
- package/lib/theme/ParamsItem/index.d.ts +1 -1
- package/lib/theme/ParamsItem/index.js +7 -101
- package/lib/theme/ResponseSchema/index.js +97 -88
- package/lib/theme/SchemaItem/index.js +7 -46
- package/lib/theme/styles.scss +2 -0
- package/lib/theme/translationIds.d.ts +3 -0
- package/lib/theme/translationIds.js +4 -0
- package/package.json +3 -3
- package/src/markdown/schema.ts +5 -0
- package/src/theme/Example/_Example.scss +11 -0
- package/src/theme/Example/index.tsx +168 -0
- package/src/theme/ParamsItem/index.tsx +10 -71
- package/src/theme/ResponseSchema/index.tsx +73 -67
- package/src/theme/SchemaItem/index.tsx +7 -37
- package/src/theme/styles.scss +2 -0
- package/src/theme/translationIds.ts +4 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -56,6 +56,9 @@ export declare const OPENAPI_STATUS_CODES: {
|
|
|
56
56
|
RESPONSE_HEADERS: string;
|
|
57
57
|
SCHEMA_TITLE: string;
|
|
58
58
|
};
|
|
59
|
+
export declare const OPENAPI_SCHEMA: {
|
|
60
|
+
NO_SCHEMA: string;
|
|
61
|
+
};
|
|
59
62
|
export declare const OPENAPI_SCHEMA_ITEM: {
|
|
60
63
|
REQUIRED: string;
|
|
61
64
|
DEPRECATED: string;
|
|
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.OPENAPI_SECURITY_SCHEMES =
|
|
10
10
|
exports.OPENAPI_PARAMS_DETAILS =
|
|
11
11
|
exports.OPENAPI_SCHEMA_ITEM =
|
|
12
|
+
exports.OPENAPI_SCHEMA =
|
|
12
13
|
exports.OPENAPI_STATUS_CODES =
|
|
13
14
|
exports.OPENAPI_BODY =
|
|
14
15
|
exports.OPENAPI_RESPONSE_EXAMPLES =
|
|
@@ -79,6 +80,9 @@ exports.OPENAPI_STATUS_CODES = {
|
|
|
79
80
|
RESPONSE_HEADERS: "theme.openapi.statusCodes.responseHeaders",
|
|
80
81
|
SCHEMA_TITLE: "theme.openapi.statusCodes.schemaTitle",
|
|
81
82
|
};
|
|
83
|
+
exports.OPENAPI_SCHEMA = {
|
|
84
|
+
NO_SCHEMA: "theme.openapi.schema.noSchema",
|
|
85
|
+
};
|
|
82
86
|
exports.OPENAPI_SCHEMA_ITEM = {
|
|
83
87
|
REQUIRED: "theme.openapi.schemaItem.required",
|
|
84
88
|
DEPRECATED: "theme.openapi.schemaItem.deprecated",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-theme-openapi-docs",
|
|
3
3
|
"description": "OpenAPI theme for Docusaurus.",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-1080",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@types/postman-collection": "^3.5.11",
|
|
39
39
|
"@types/react-modal": "^3.16.3",
|
|
40
40
|
"concurrently": "^9.2.0",
|
|
41
|
-
"docusaurus-plugin-openapi-docs": "0.0.0-
|
|
41
|
+
"docusaurus-plugin-openapi-docs": "0.0.0-1080",
|
|
42
42
|
"docusaurus-plugin-sass": "^0.2.6",
|
|
43
43
|
"eslint-plugin-prettier": "^5.5.1"
|
|
44
44
|
},
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"engines": {
|
|
82
82
|
"node": ">=14"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "4ee6a0705e5fd50fc7c80d735ebd5239c5cca770"
|
|
85
85
|
}
|
package/src/markdown/schema.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
8
|
import { translate } from "@docusaurus/Translate";
|
|
9
|
+
|
|
9
10
|
import { OPENAPI_SCHEMA_ITEM } from "../theme/translationIds";
|
|
10
11
|
import { SchemaObject } from "../types";
|
|
11
12
|
|
|
@@ -42,6 +43,10 @@ function prettyName(schema: SchemaObject, circular?: boolean) {
|
|
|
42
43
|
// return schema.type;
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
if (Array.isArray(schema.type)) {
|
|
47
|
+
return schema.type.join(" | ");
|
|
48
|
+
}
|
|
49
|
+
|
|
45
50
|
return schema.title ?? schema.type;
|
|
46
51
|
}
|
|
47
52
|
|
|
@@ -0,0 +1,168 @@
|
|
|
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 { translate } from "@docusaurus/Translate";
|
|
11
|
+
import { ExampleObject } from "@theme/ParamsItem";
|
|
12
|
+
import SchemaTabs from "@theme/SchemaTabs";
|
|
13
|
+
import TabItem from "@theme/TabItem";
|
|
14
|
+
import { OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";
|
|
15
|
+
|
|
16
|
+
const EXAMPLE_CLASS_NAME = "openapi-example";
|
|
17
|
+
const EXAMPLES_CLASS_NAME = "openapi-examples";
|
|
18
|
+
|
|
19
|
+
type ExampleType = string;
|
|
20
|
+
type ExamplesType = Record<string, ExampleObject> | string[];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Example Component Props
|
|
24
|
+
*/
|
|
25
|
+
type ExampleProps = {
|
|
26
|
+
example?: ExampleType;
|
|
27
|
+
examples?: ExamplesType;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Example Component
|
|
32
|
+
*/
|
|
33
|
+
export const Example = ({ example, examples }: ExampleProps) => {
|
|
34
|
+
if (example !== undefined) {
|
|
35
|
+
return renderExample(example);
|
|
36
|
+
}
|
|
37
|
+
if (examples !== undefined) {
|
|
38
|
+
return renderExamples(examples);
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Format example value
|
|
45
|
+
*
|
|
46
|
+
* @param example
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
const formatExample = (example: any) => {
|
|
50
|
+
if (typeof example === "object" && example !== null) {
|
|
51
|
+
return JSON.stringify(example);
|
|
52
|
+
}
|
|
53
|
+
return String(example);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const renderExample = (example: ExampleType) => {
|
|
57
|
+
return (
|
|
58
|
+
<div className={EXAMPLE_CLASS_NAME}>
|
|
59
|
+
<strong>
|
|
60
|
+
{translate({
|
|
61
|
+
id: OPENAPI_SCHEMA_ITEM.EXAMPLE,
|
|
62
|
+
message: "Example:",
|
|
63
|
+
})}{" "}
|
|
64
|
+
</strong>
|
|
65
|
+
<span>
|
|
66
|
+
<code>{formatExample(example)}</code>
|
|
67
|
+
</span>
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const renderExamples = (examples: ExamplesType) => {
|
|
73
|
+
if (Array.isArray(examples)) {
|
|
74
|
+
return renderStringArrayExamples(examples);
|
|
75
|
+
}
|
|
76
|
+
return renderExamplesRecord(examples);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Render string examples
|
|
81
|
+
*
|
|
82
|
+
* @param examples
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
export function renderStringArrayExamples(examples: string[]) {
|
|
86
|
+
if (examples.length === 0) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
// If there's only one example, display it without tabs
|
|
90
|
+
if (examples.length === 1) {
|
|
91
|
+
return renderExample(examples[0]);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Multiple examples - use tabs
|
|
95
|
+
const exampleEntries = examples.reduce(
|
|
96
|
+
(acc, example, index) => ({
|
|
97
|
+
...acc,
|
|
98
|
+
[`Example ${index + 1}`]: {
|
|
99
|
+
value: example,
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
{} as Record<string, ExampleObject>
|
|
103
|
+
);
|
|
104
|
+
return renderExamplesRecord(exampleEntries);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const renderExamplesRecord = (
|
|
108
|
+
examples: Record<string, ExampleObject>
|
|
109
|
+
) => {
|
|
110
|
+
const exampleEntries = Object.entries(examples);
|
|
111
|
+
// If there's only one example, display it without tabs
|
|
112
|
+
if (exampleEntries.length === 1) {
|
|
113
|
+
const firstExample = exampleEntries[0][1];
|
|
114
|
+
if (!firstExample) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
return renderExample(firstExample.value);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<div className={EXAMPLES_CLASS_NAME}>
|
|
122
|
+
<strong>
|
|
123
|
+
{translate({
|
|
124
|
+
id: OPENAPI_SCHEMA_ITEM.EXAMPLES,
|
|
125
|
+
message: "Examples:",
|
|
126
|
+
})}
|
|
127
|
+
</strong>
|
|
128
|
+
<SchemaTabs>
|
|
129
|
+
{exampleEntries.map(([exampleName, exampleProperties]) =>
|
|
130
|
+
renderExampleObject(exampleName, exampleProperties)
|
|
131
|
+
)}
|
|
132
|
+
</SchemaTabs>
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Render example object
|
|
139
|
+
*
|
|
140
|
+
* @param exampleName
|
|
141
|
+
* @param exampleProperties
|
|
142
|
+
* @returns
|
|
143
|
+
*/
|
|
144
|
+
const renderExampleObject = (
|
|
145
|
+
exampleName: string,
|
|
146
|
+
exampleProperties: ExampleObject
|
|
147
|
+
) => {
|
|
148
|
+
return (
|
|
149
|
+
// @ts-ignore
|
|
150
|
+
<TabItem value={exampleName} label={exampleName}>
|
|
151
|
+
{exampleProperties.summary && <p>{exampleProperties.summary}</p>}
|
|
152
|
+
{exampleProperties.description && (
|
|
153
|
+
<p>
|
|
154
|
+
<strong>
|
|
155
|
+
{translate({
|
|
156
|
+
id: OPENAPI_SCHEMA_ITEM.DESCRIPTION,
|
|
157
|
+
message: "Description:",
|
|
158
|
+
})}{" "}
|
|
159
|
+
</strong>
|
|
160
|
+
<span>{exampleProperties.description}</span>
|
|
161
|
+
</p>
|
|
162
|
+
)}
|
|
163
|
+
{exampleProperties.value !== undefined
|
|
164
|
+
? renderExample(exampleProperties.value)
|
|
165
|
+
: undefined}
|
|
166
|
+
</TabItem>
|
|
167
|
+
);
|
|
168
|
+
};
|
|
@@ -8,16 +8,14 @@
|
|
|
8
8
|
import React from "react";
|
|
9
9
|
|
|
10
10
|
import { translate } from "@docusaurus/Translate";
|
|
11
|
-
|
|
11
|
+
import { Example } from "@theme/Example";
|
|
12
12
|
import Markdown from "@theme/Markdown";
|
|
13
|
-
import SchemaTabs from "@theme/SchemaTabs";
|
|
14
|
-
import TabItem from "@theme/TabItem";
|
|
15
13
|
/* eslint-disable import/no-extraneous-dependencies*/
|
|
16
|
-
import clsx from "clsx";
|
|
17
14
|
import { OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";
|
|
15
|
+
import clsx from "clsx";
|
|
18
16
|
|
|
19
17
|
import { getQualifierMessage, getSchemaName } from "../../markdown/schema";
|
|
20
|
-
import { guard
|
|
18
|
+
import { guard } from "../../markdown/utils";
|
|
21
19
|
|
|
22
20
|
export interface ExampleObject {
|
|
23
21
|
summary?: string;
|
|
@@ -31,7 +29,7 @@ export interface Props {
|
|
|
31
29
|
param: {
|
|
32
30
|
description: string;
|
|
33
31
|
example: any;
|
|
34
|
-
examples: Record<string, ExampleObject
|
|
32
|
+
examples: Record<string, ExampleObject> | undefined;
|
|
35
33
|
name: string;
|
|
36
34
|
required: boolean;
|
|
37
35
|
deprecated: boolean;
|
|
@@ -64,19 +62,14 @@ ${enumDescriptions
|
|
|
64
62
|
};
|
|
65
63
|
|
|
66
64
|
function ParamsItem({ param, ...rest }: Props) {
|
|
67
|
-
const {
|
|
68
|
-
description,
|
|
69
|
-
example,
|
|
70
|
-
examples,
|
|
71
|
-
name,
|
|
72
|
-
required,
|
|
73
|
-
deprecated,
|
|
74
|
-
enumDescriptions,
|
|
75
|
-
} = param;
|
|
65
|
+
const { description, name, required, deprecated, enumDescriptions } = param;
|
|
76
66
|
|
|
77
67
|
let schema = param.schema;
|
|
78
68
|
let defaultValue: string | undefined;
|
|
79
69
|
|
|
70
|
+
let examples = param.examples ?? (schema?.examples as any[] | undefined);
|
|
71
|
+
let example = param.example ?? schema?.example;
|
|
72
|
+
|
|
80
73
|
if (!schema) {
|
|
81
74
|
schema = { type: "any" };
|
|
82
75
|
}
|
|
@@ -162,60 +155,6 @@ function ParamsItem({ param, ...rest }: Props) {
|
|
|
162
155
|
return undefined;
|
|
163
156
|
}
|
|
164
157
|
|
|
165
|
-
const renderExample = guard(toString(example), (example) => (
|
|
166
|
-
<div>
|
|
167
|
-
<strong>
|
|
168
|
-
{translate({
|
|
169
|
-
id: OPENAPI_SCHEMA_ITEM.EXAMPLE,
|
|
170
|
-
message: "Example:",
|
|
171
|
-
})}{" "}
|
|
172
|
-
</strong>
|
|
173
|
-
{example}
|
|
174
|
-
</div>
|
|
175
|
-
));
|
|
176
|
-
|
|
177
|
-
const renderExamples = guard(examples, (examples) => {
|
|
178
|
-
const exampleEntries = Object.entries(examples);
|
|
179
|
-
return (
|
|
180
|
-
<>
|
|
181
|
-
<strong>
|
|
182
|
-
{translate({
|
|
183
|
-
id: OPENAPI_SCHEMA_ITEM.EXAMPLES,
|
|
184
|
-
message: "Examples:",
|
|
185
|
-
})}
|
|
186
|
-
</strong>
|
|
187
|
-
<SchemaTabs>
|
|
188
|
-
{exampleEntries.map(([exampleName, exampleProperties]) => (
|
|
189
|
-
// @ts-ignore
|
|
190
|
-
<TabItem value={exampleName} label={exampleName}>
|
|
191
|
-
{exampleProperties.summary && <p>{exampleProperties.summary}</p>}
|
|
192
|
-
{exampleProperties.description && (
|
|
193
|
-
<p>
|
|
194
|
-
<strong>
|
|
195
|
-
{translate({
|
|
196
|
-
id: OPENAPI_SCHEMA_ITEM.DESCRIPTION,
|
|
197
|
-
message: "Description:",
|
|
198
|
-
})}{" "}
|
|
199
|
-
</strong>
|
|
200
|
-
<span>{exampleProperties.description}</span>
|
|
201
|
-
</p>
|
|
202
|
-
)}
|
|
203
|
-
<p>
|
|
204
|
-
<strong>
|
|
205
|
-
{translate({
|
|
206
|
-
id: OPENAPI_SCHEMA_ITEM.EXAMPLE,
|
|
207
|
-
message: "Example:",
|
|
208
|
-
})}{" "}
|
|
209
|
-
</strong>
|
|
210
|
-
<code>{exampleProperties.value}</code>
|
|
211
|
-
</p>
|
|
212
|
-
</TabItem>
|
|
213
|
-
))}
|
|
214
|
-
</SchemaTabs>
|
|
215
|
-
</>
|
|
216
|
-
);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
158
|
return (
|
|
220
159
|
<div className="openapi-params__list-item">
|
|
221
160
|
<span className="openapi-schema__container">
|
|
@@ -237,8 +176,8 @@ function ParamsItem({ param, ...rest }: Props) {
|
|
|
237
176
|
{renderDescription}
|
|
238
177
|
{renderEnumDescriptions}
|
|
239
178
|
{renderDefaultValue()}
|
|
240
|
-
{
|
|
241
|
-
{
|
|
179
|
+
<Example example={example} />
|
|
180
|
+
<Example examples={examples} />
|
|
242
181
|
</div>
|
|
243
182
|
);
|
|
244
183
|
}
|
|
@@ -7,10 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
import React from "react";
|
|
9
9
|
|
|
10
|
-
import { translate } from "@docusaurus/Translate";
|
|
11
|
-
import { OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";
|
|
12
|
-
|
|
13
10
|
import BrowserOnly from "@docusaurus/BrowserOnly";
|
|
11
|
+
import { translate } from "@docusaurus/Translate";
|
|
14
12
|
import Details from "@theme/Details";
|
|
15
13
|
import Markdown from "@theme/Markdown";
|
|
16
14
|
import MimeTabs from "@theme/MimeTabs"; // Assume these components exist
|
|
@@ -23,6 +21,7 @@ import SchemaNode from "@theme/Schema";
|
|
|
23
21
|
import SchemaTabs from "@theme/SchemaTabs";
|
|
24
22
|
import SkeletonLoader from "@theme/SkeletonLoader";
|
|
25
23
|
import TabItem from "@theme/TabItem";
|
|
24
|
+
import { OPENAPI_SCHEMA, OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";
|
|
26
25
|
import { MediaTypeObject } from "docusaurus-plugin-openapi-docs/lib/openapi/types";
|
|
27
26
|
|
|
28
27
|
interface Props {
|
|
@@ -57,79 +56,86 @@ const ResponseSchemaComponent: React.FC<Props> = ({
|
|
|
57
56
|
return (
|
|
58
57
|
<MimeTabs className="openapi-tabs__mime" schemaType="response">
|
|
59
58
|
{mimeTypes.map((mimeType: any) => {
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
59
|
+
const mediaTypeObject = body.content?.[mimeType];
|
|
60
|
+
const responseExamples = mediaTypeObject?.examples;
|
|
61
|
+
const responseExample = mediaTypeObject?.example;
|
|
62
|
+
const firstBody = mediaTypeObject?.schema;
|
|
64
63
|
|
|
65
64
|
if (
|
|
66
|
-
firstBody
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
!firstBody ||
|
|
66
|
+
(firstBody.properties &&
|
|
67
|
+
Object.keys(firstBody.properties).length === 0)
|
|
69
68
|
) {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (firstBody) {
|
|
74
69
|
return (
|
|
75
70
|
// @ts-ignore
|
|
76
71
|
<TabItem key={mimeType} label={mimeType} value={mimeType}>
|
|
77
|
-
<
|
|
78
|
-
{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
open={true}
|
|
84
|
-
style={style}
|
|
85
|
-
summary={
|
|
86
|
-
<>
|
|
87
|
-
<summary>
|
|
88
|
-
<strong className="openapi-markdown__details-summary-response">
|
|
89
|
-
{title}
|
|
90
|
-
{body.required === true && (
|
|
91
|
-
<span className="openapi-schema__required">
|
|
92
|
-
{translate({
|
|
93
|
-
id: OPENAPI_SCHEMA_ITEM.REQUIRED,
|
|
94
|
-
message: "required",
|
|
95
|
-
})}
|
|
96
|
-
</span>
|
|
97
|
-
)}
|
|
98
|
-
</strong>
|
|
99
|
-
</summary>
|
|
100
|
-
</>
|
|
101
|
-
}
|
|
102
|
-
>
|
|
103
|
-
<div style={{ textAlign: "left", marginLeft: "1rem" }}>
|
|
104
|
-
{body.description && (
|
|
105
|
-
<div
|
|
106
|
-
style={{ marginTop: "1rem", marginBottom: "1rem" }}
|
|
107
|
-
>
|
|
108
|
-
<Markdown>{body.description}</Markdown>
|
|
109
|
-
</div>
|
|
110
|
-
)}
|
|
111
|
-
</div>
|
|
112
|
-
<ul style={{ marginLeft: "1rem" }}>
|
|
113
|
-
<SchemaNode schema={firstBody} schemaType="response" />
|
|
114
|
-
</ul>
|
|
115
|
-
</Details>
|
|
116
|
-
</TabItem>
|
|
117
|
-
{firstBody &&
|
|
118
|
-
ExampleFromSchema({
|
|
119
|
-
schema: firstBody,
|
|
120
|
-
mimeType: mimeType,
|
|
121
|
-
})}
|
|
122
|
-
|
|
123
|
-
{responseExamples &&
|
|
124
|
-
ResponseExamples({ responseExamples, mimeType })}
|
|
125
|
-
|
|
126
|
-
{responseExample &&
|
|
127
|
-
ResponseExample({ responseExample, mimeType })}
|
|
128
|
-
</SchemaTabs>
|
|
72
|
+
<div>
|
|
73
|
+
{translate({
|
|
74
|
+
id: OPENAPI_SCHEMA.NO_SCHEMA,
|
|
75
|
+
message: "No schema",
|
|
76
|
+
})}
|
|
77
|
+
</div>
|
|
129
78
|
</TabItem>
|
|
130
79
|
);
|
|
131
80
|
}
|
|
132
|
-
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
<TabItem key={mimeType} label={mimeType} value={mimeType}>
|
|
85
|
+
<SchemaTabs className="openapi-tabs__schema">
|
|
86
|
+
{/* @ts-ignore */}
|
|
87
|
+
<TabItem key={title} label={title} value={title}>
|
|
88
|
+
<Details
|
|
89
|
+
className="openapi-markdown__details response"
|
|
90
|
+
data-collapsed={false}
|
|
91
|
+
open={true}
|
|
92
|
+
style={style}
|
|
93
|
+
summary={
|
|
94
|
+
<>
|
|
95
|
+
<summary>
|
|
96
|
+
<strong className="openapi-markdown__details-summary-response">
|
|
97
|
+
{title}
|
|
98
|
+
{body.required === true && (
|
|
99
|
+
<span className="openapi-schema__required">
|
|
100
|
+
{translate({
|
|
101
|
+
id: OPENAPI_SCHEMA_ITEM.REQUIRED,
|
|
102
|
+
message: "required",
|
|
103
|
+
})}
|
|
104
|
+
</span>
|
|
105
|
+
)}
|
|
106
|
+
</strong>
|
|
107
|
+
</summary>
|
|
108
|
+
</>
|
|
109
|
+
}
|
|
110
|
+
>
|
|
111
|
+
<div style={{ textAlign: "left", marginLeft: "1rem" }}>
|
|
112
|
+
{body.description && (
|
|
113
|
+
<div
|
|
114
|
+
style={{ marginTop: "1rem", marginBottom: "1rem" }}
|
|
115
|
+
>
|
|
116
|
+
<Markdown>{body.description}</Markdown>
|
|
117
|
+
</div>
|
|
118
|
+
)}
|
|
119
|
+
</div>
|
|
120
|
+
<ul style={{ marginLeft: "1rem" }}>
|
|
121
|
+
<SchemaNode schema={firstBody} schemaType="response" />
|
|
122
|
+
</ul>
|
|
123
|
+
</Details>
|
|
124
|
+
</TabItem>
|
|
125
|
+
{firstBody &&
|
|
126
|
+
ExampleFromSchema({
|
|
127
|
+
schema: firstBody,
|
|
128
|
+
mimeType: mimeType,
|
|
129
|
+
})}
|
|
130
|
+
|
|
131
|
+
{responseExamples &&
|
|
132
|
+
ResponseExamples({ responseExamples, mimeType })}
|
|
133
|
+
|
|
134
|
+
{responseExample &&
|
|
135
|
+
ResponseExample({ responseExample, mimeType })}
|
|
136
|
+
</SchemaTabs>
|
|
137
|
+
</TabItem>
|
|
138
|
+
);
|
|
133
139
|
})}
|
|
134
140
|
</MimeTabs>
|
|
135
141
|
);
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
import React, { ReactNode } from "react";
|
|
9
9
|
|
|
10
|
-
import Markdown from "@theme/Markdown";
|
|
11
|
-
import clsx from "clsx";
|
|
12
10
|
import { translate } from "@docusaurus/Translate";
|
|
11
|
+
import { Example } from "@theme/Example";
|
|
12
|
+
import Markdown from "@theme/Markdown";
|
|
13
13
|
import { OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";
|
|
14
|
+
import clsx from "clsx";
|
|
14
15
|
|
|
15
16
|
import { guard } from "../../markdown/utils";
|
|
16
17
|
|
|
@@ -73,6 +74,7 @@ export default function SchemaItem(props: Props) {
|
|
|
73
74
|
let schemaDescription;
|
|
74
75
|
let defaultValue: string | undefined;
|
|
75
76
|
let example: string | undefined;
|
|
77
|
+
let examples: string[] | undefined;
|
|
76
78
|
let nullable;
|
|
77
79
|
let enumDescriptions: [string, string][] = [];
|
|
78
80
|
let constValue: string | undefined;
|
|
@@ -83,6 +85,7 @@ export default function SchemaItem(props: Props) {
|
|
|
83
85
|
enumDescriptions = transformEnumDescriptions(schema["x-enumDescriptions"]);
|
|
84
86
|
defaultValue = schema.default;
|
|
85
87
|
example = schema.example;
|
|
88
|
+
examples = schema.examples;
|
|
86
89
|
nullable =
|
|
87
90
|
schema.nullable ||
|
|
88
91
|
(Array.isArray(schema.type) && schema.type.includes("null")); // support JSON Schema nullable
|
|
@@ -167,40 +170,6 @@ export default function SchemaItem(props: Props) {
|
|
|
167
170
|
return undefined;
|
|
168
171
|
}
|
|
169
172
|
|
|
170
|
-
function renderExample() {
|
|
171
|
-
if (example !== undefined) {
|
|
172
|
-
if (typeof example === "string") {
|
|
173
|
-
return (
|
|
174
|
-
<div>
|
|
175
|
-
<strong>
|
|
176
|
-
{translate({
|
|
177
|
-
id: OPENAPI_SCHEMA_ITEM.EXAMPLE,
|
|
178
|
-
message: "Example:",
|
|
179
|
-
})}{" "}
|
|
180
|
-
</strong>
|
|
181
|
-
<span>
|
|
182
|
-
<code>{example}</code>
|
|
183
|
-
</span>
|
|
184
|
-
</div>
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
return (
|
|
188
|
-
<div>
|
|
189
|
-
<strong>
|
|
190
|
-
{translate({
|
|
191
|
-
id: OPENAPI_SCHEMA_ITEM.EXAMPLE,
|
|
192
|
-
message: "Example:",
|
|
193
|
-
})}{" "}
|
|
194
|
-
</strong>
|
|
195
|
-
<span>
|
|
196
|
-
<code>{JSON.stringify(example)}</code>
|
|
197
|
-
</span>
|
|
198
|
-
</div>
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
return undefined;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
173
|
function renderConstValue() {
|
|
205
174
|
if (constValue !== undefined) {
|
|
206
175
|
if (typeof constValue === "string") {
|
|
@@ -260,7 +229,8 @@ export default function SchemaItem(props: Props) {
|
|
|
260
229
|
{renderQualifierMessage}
|
|
261
230
|
{renderConstValue()}
|
|
262
231
|
{renderDefaultValue()}
|
|
263
|
-
{
|
|
232
|
+
<Example example={example} />
|
|
233
|
+
<Example examples={examples} />
|
|
264
234
|
{collapsibleSchemaContent ?? collapsibleSchemaContent}
|
|
265
235
|
</div>
|
|
266
236
|
);
|
package/src/theme/styles.scss
CHANGED
|
@@ -74,6 +74,10 @@ export const OPENAPI_STATUS_CODES = {
|
|
|
74
74
|
SCHEMA_TITLE: "theme.openapi.statusCodes.schemaTitle",
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
+
export const OPENAPI_SCHEMA = {
|
|
78
|
+
NO_SCHEMA: "theme.openapi.schema.noSchema",
|
|
79
|
+
};
|
|
80
|
+
|
|
77
81
|
export const OPENAPI_SCHEMA_ITEM = {
|
|
78
82
|
REQUIRED: "theme.openapi.schemaItem.required",
|
|
79
83
|
DEPRECATED: "theme.openapi.schemaItem.deprecated",
|
package/tsconfig.tsbuildinfo
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/index.ts","./src/plugin-content-docs.d.ts","./src/postman-code-generators.d.ts","./src/react-magic-dropzone.d.ts","./src/theme-classic.d.ts","./src/theme-openapi.d.ts","./src/types.ts","./src/markdown/createDescription.ts","./src/markdown/schema.ts","./src/markdown/utils.test.ts","./src/markdown/utils.ts","./src/theme/translationIds.ts","./src/theme/ApiExplorer/buildPostmanRequest.ts","./src/theme/ApiExplorer/index.tsx","./src/theme/ApiExplorer/persistanceMiddleware.ts","./src/theme/ApiExplorer/storage-utils.ts","./src/theme/ApiExplorer/Accept/index.tsx","./src/theme/ApiExplorer/Accept/slice.ts","./src/theme/ApiExplorer/ApiCodeBlock/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Container/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Content/Element.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Content/String.tsx","./src/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Line/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.tsx","./src/theme/ApiExplorer/Authorization/auth-types.ts","./src/theme/ApiExplorer/Authorization/index.tsx","./src/theme/ApiExplorer/Authorization/slice.ts","./src/theme/ApiExplorer/Body/index.tsx","./src/theme/ApiExplorer/Body/json2xml.d.ts","./src/theme/ApiExplorer/Body/slice.ts","./src/theme/ApiExplorer/CodeSnippets/code-snippets-types.ts","./src/theme/ApiExplorer/CodeSnippets/index.tsx","./src/theme/ApiExplorer/CodeSnippets/languages.ts","./src/theme/ApiExplorer/CodeTabs/index.tsx","./src/theme/ApiExplorer/ContentType/index.tsx","./src/theme/ApiExplorer/ContentType/slice.ts","./src/theme/ApiExplorer/Export/index.tsx","./src/theme/ApiExplorer/FloatingButton/index.tsx","./src/theme/ApiExplorer/FormFileUpload/index.tsx","./src/theme/ApiExplorer/FormItem/index.tsx","./src/theme/ApiExplorer/FormMultiSelect/index.tsx","./src/theme/ApiExplorer/FormSelect/index.tsx","./src/theme/ApiExplorer/FormTextInput/index.tsx","./src/theme/ApiExplorer/LiveEditor/index.tsx","./src/theme/ApiExplorer/MethodEndpoint/index.tsx","./src/theme/ApiExplorer/ParamOptions/index.tsx","./src/theme/ApiExplorer/ParamOptions/slice.ts","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.tsx","./src/theme/ApiExplorer/Request/index.tsx","./src/theme/ApiExplorer/Request/makeRequest.ts","./src/theme/ApiExplorer/Response/index.tsx","./src/theme/ApiExplorer/Response/slice.ts","./src/theme/ApiExplorer/SecuritySchemes/index.tsx","./src/theme/ApiExplorer/Server/index.tsx","./src/theme/ApiExplorer/Server/slice.ts","./src/theme/ApiItem/hooks.ts","./src/theme/ApiItem/index.tsx","./src/theme/ApiItem/store.ts","./src/theme/ApiItem/Layout/index.tsx","./src/theme/ApiLogo/index.tsx","./src/theme/ApiTabs/index.tsx","./src/theme/ArrayBrackets/index.tsx","./src/theme/CodeSamples/index.tsx","./src/theme/DiscriminatorTabs/index.tsx","./src/theme/Markdown/index.d.ts","./src/theme/MimeTabs/index.tsx","./src/theme/OperationTabs/index.tsx","./src/theme/ParamsDetails/index.tsx","./src/theme/ParamsItem/index.tsx","./src/theme/RequestSchema/index.tsx","./src/theme/ResponseExamples/index.tsx","./src/theme/ResponseHeaders/index.tsx","./src/theme/ResponseSchema/index.tsx","./src/theme/Schema/index.tsx","./src/theme/SchemaItem/index.tsx","./src/theme/SchemaTabs/index.tsx","./src/theme/SkeletonLoader/index.tsx","./src/theme/StatusCodes/index.tsx"],"version":"5.8.3"}
|
|
1
|
+
{"root":["./src/index.ts","./src/plugin-content-docs.d.ts","./src/postman-code-generators.d.ts","./src/react-magic-dropzone.d.ts","./src/theme-classic.d.ts","./src/theme-openapi.d.ts","./src/types.ts","./src/markdown/createDescription.ts","./src/markdown/schema.ts","./src/markdown/utils.test.ts","./src/markdown/utils.ts","./src/theme/translationIds.ts","./src/theme/ApiExplorer/buildPostmanRequest.ts","./src/theme/ApiExplorer/index.tsx","./src/theme/ApiExplorer/persistanceMiddleware.ts","./src/theme/ApiExplorer/storage-utils.ts","./src/theme/ApiExplorer/Accept/index.tsx","./src/theme/ApiExplorer/Accept/slice.ts","./src/theme/ApiExplorer/ApiCodeBlock/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Container/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Content/Element.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Content/String.tsx","./src/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Line/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.tsx","./src/theme/ApiExplorer/Authorization/auth-types.ts","./src/theme/ApiExplorer/Authorization/index.tsx","./src/theme/ApiExplorer/Authorization/slice.ts","./src/theme/ApiExplorer/Body/index.tsx","./src/theme/ApiExplorer/Body/json2xml.d.ts","./src/theme/ApiExplorer/Body/slice.ts","./src/theme/ApiExplorer/CodeSnippets/code-snippets-types.ts","./src/theme/ApiExplorer/CodeSnippets/index.tsx","./src/theme/ApiExplorer/CodeSnippets/languages.ts","./src/theme/ApiExplorer/CodeTabs/index.tsx","./src/theme/ApiExplorer/ContentType/index.tsx","./src/theme/ApiExplorer/ContentType/slice.ts","./src/theme/ApiExplorer/Export/index.tsx","./src/theme/ApiExplorer/FloatingButton/index.tsx","./src/theme/ApiExplorer/FormFileUpload/index.tsx","./src/theme/ApiExplorer/FormItem/index.tsx","./src/theme/ApiExplorer/FormMultiSelect/index.tsx","./src/theme/ApiExplorer/FormSelect/index.tsx","./src/theme/ApiExplorer/FormTextInput/index.tsx","./src/theme/ApiExplorer/LiveEditor/index.tsx","./src/theme/ApiExplorer/MethodEndpoint/index.tsx","./src/theme/ApiExplorer/ParamOptions/index.tsx","./src/theme/ApiExplorer/ParamOptions/slice.ts","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.tsx","./src/theme/ApiExplorer/Request/index.tsx","./src/theme/ApiExplorer/Request/makeRequest.ts","./src/theme/ApiExplorer/Response/index.tsx","./src/theme/ApiExplorer/Response/slice.ts","./src/theme/ApiExplorer/SecuritySchemes/index.tsx","./src/theme/ApiExplorer/Server/index.tsx","./src/theme/ApiExplorer/Server/slice.ts","./src/theme/ApiItem/hooks.ts","./src/theme/ApiItem/index.tsx","./src/theme/ApiItem/store.ts","./src/theme/ApiItem/Layout/index.tsx","./src/theme/ApiLogo/index.tsx","./src/theme/ApiTabs/index.tsx","./src/theme/ArrayBrackets/index.tsx","./src/theme/CodeSamples/index.tsx","./src/theme/DiscriminatorTabs/index.tsx","./src/theme/Example/index.tsx","./src/theme/Markdown/index.d.ts","./src/theme/MimeTabs/index.tsx","./src/theme/OperationTabs/index.tsx","./src/theme/ParamsDetails/index.tsx","./src/theme/ParamsItem/index.tsx","./src/theme/RequestSchema/index.tsx","./src/theme/ResponseExamples/index.tsx","./src/theme/ResponseHeaders/index.tsx","./src/theme/ResponseSchema/index.tsx","./src/theme/Schema/index.tsx","./src/theme/SchemaItem/index.tsx","./src/theme/SchemaTabs/index.tsx","./src/theme/SkeletonLoader/index.tsx","./src/theme/StatusCodes/index.tsx"],"version":"5.8.3"}
|