docusaurus-theme-openapi-docs 0.0.0-803 → 0.0.0-822
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/Request/_Request.scss +5 -0
- package/lib/theme/ApiExplorer/index.js +6 -0
- package/lib/theme/ParamsItem/index.d.ts +2 -1
- package/lib/theme/ParamsItem/index.js +74 -17
- package/lib/theme/SchemaItem/index.d.ts +1 -1
- package/lib/theme/SchemaItem/index.js +76 -20
- package/package.json +4 -3
- package/src/theme/ApiExplorer/Request/_Request.scss +5 -0
- package/src/theme/ApiExplorer/index.tsx +2 -0
- package/src/theme/ParamsItem/index.tsx +75 -15
- package/src/theme/SchemaItem/index.tsx +79 -17
|
@@ -114,6 +114,11 @@
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
.openapi-security__summary-container {
|
|
118
|
+
background: var(--ifm-pre-background);
|
|
119
|
+
border-radius: var(--ifm-pre-border-radius);
|
|
120
|
+
}
|
|
121
|
+
|
|
117
122
|
// Prevent auto zoom on mobile iOS devices when focusing on input elmenents
|
|
118
123
|
@media screen and (-webkit-min-device-pixel-ratio: 0) and (max-device-width: 1024px) {
|
|
119
124
|
.prism-code,
|
|
@@ -17,12 +17,18 @@ const CodeSnippets_1 = __importDefault(
|
|
|
17
17
|
);
|
|
18
18
|
const Request_1 = __importDefault(require("@theme/ApiExplorer/Request"));
|
|
19
19
|
const Response_1 = __importDefault(require("@theme/ApiExplorer/Response"));
|
|
20
|
+
const SecuritySchemes_1 = __importDefault(
|
|
21
|
+
require("@theme/ApiExplorer/SecuritySchemes")
|
|
22
|
+
);
|
|
20
23
|
const postman_collection_1 = __importDefault(require("postman-collection"));
|
|
21
24
|
function ApiExplorer({ item, infoPath }) {
|
|
22
25
|
const postman = new postman_collection_1.default.Request(item.postman);
|
|
23
26
|
return react_1.default.createElement(
|
|
24
27
|
react_1.default.Fragment,
|
|
25
28
|
null,
|
|
29
|
+
react_1.default.createElement(SecuritySchemes_1.default, {
|
|
30
|
+
infoPath: infoPath,
|
|
31
|
+
}),
|
|
26
32
|
item.method !== "event" &&
|
|
27
33
|
react_1.default.createElement(CodeSnippets_1.default, {
|
|
28
34
|
postman: postman,
|
|
@@ -17,7 +17,8 @@ export interface Props {
|
|
|
17
17
|
required: boolean;
|
|
18
18
|
deprecated: boolean;
|
|
19
19
|
schema: any;
|
|
20
|
+
enumDescriptions?: [string, string][];
|
|
20
21
|
};
|
|
21
22
|
}
|
|
22
|
-
declare function ParamsItem({ param
|
|
23
|
+
declare function ParamsItem({ param, ...rest }: Props): React.JSX.Element;
|
|
23
24
|
export default ParamsItem;
|
|
@@ -19,15 +19,45 @@ const TabItem_1 = __importDefault(require("@theme/TabItem"));
|
|
|
19
19
|
const clsx_1 = __importDefault(require("clsx"));
|
|
20
20
|
const react_markdown_1 = __importDefault(require("react-markdown"));
|
|
21
21
|
const rehype_raw_1 = __importDefault(require("rehype-raw"));
|
|
22
|
+
const remark_gfm_1 = __importDefault(require("remark-gfm"));
|
|
22
23
|
const createDescription_1 = require("../../markdown/createDescription");
|
|
23
24
|
const schema_1 = require("../../markdown/schema");
|
|
24
25
|
const utils_1 = require("../../markdown/utils");
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const getEnumDescriptionMarkdown = (enumDescriptions) => {
|
|
27
|
+
if (enumDescriptions?.length) {
|
|
28
|
+
return `| Enum Value | Description |
|
|
29
|
+
| ---- | ----- |
|
|
30
|
+
${enumDescriptions
|
|
31
|
+
.map((desc) => {
|
|
32
|
+
return `| ${desc[0]} | ${desc[1]} | `.replaceAll("\n", "<br/>");
|
|
33
|
+
})
|
|
34
|
+
.join("\n")}
|
|
35
|
+
`;
|
|
36
|
+
}
|
|
37
|
+
return "";
|
|
38
|
+
};
|
|
39
|
+
function ParamsItem({ param, ...rest }) {
|
|
40
|
+
const {
|
|
41
|
+
description,
|
|
42
|
+
example,
|
|
43
|
+
examples,
|
|
44
|
+
name,
|
|
45
|
+
required,
|
|
46
|
+
deprecated,
|
|
47
|
+
enumDescriptions,
|
|
48
|
+
} = param;
|
|
49
|
+
let schema = param.schema;
|
|
50
|
+
let defaultValue;
|
|
28
51
|
if (!schema || !schema?.type) {
|
|
29
52
|
schema = { type: "any" };
|
|
30
53
|
}
|
|
54
|
+
if (schema) {
|
|
55
|
+
if (schema.items) {
|
|
56
|
+
defaultValue = schema.items.default;
|
|
57
|
+
} else {
|
|
58
|
+
defaultValue = schema.default;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
31
61
|
const renderSchemaName = (0, utils_1.guard)(schema, (schema) =>
|
|
32
62
|
react_1.default.createElement(
|
|
33
63
|
"span",
|
|
@@ -91,21 +121,47 @@ function ParamsItem({
|
|
|
91
121
|
})
|
|
92
122
|
)
|
|
93
123
|
);
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
:
|
|
100
|
-
|
|
101
|
-
|
|
124
|
+
const renderEnumDescriptions = (0, utils_1.guard)(
|
|
125
|
+
getEnumDescriptionMarkdown(enumDescriptions),
|
|
126
|
+
(value) => {
|
|
127
|
+
return react_1.default.createElement(react_markdown_1.default, {
|
|
128
|
+
rehypePlugins: [rehype_raw_1.default],
|
|
129
|
+
remarkPlugins: [remark_gfm_1.default],
|
|
130
|
+
children: value,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
function renderDefaultValue() {
|
|
135
|
+
if (defaultValue !== undefined) {
|
|
136
|
+
if (typeof defaultValue === "string") {
|
|
137
|
+
return react_1.default.createElement(
|
|
138
|
+
"div",
|
|
139
|
+
null,
|
|
140
|
+
react_1.default.createElement("strong", null, "Default value: "),
|
|
141
|
+
react_1.default.createElement(
|
|
142
|
+
"span",
|
|
143
|
+
null,
|
|
144
|
+
react_1.default.createElement("code", null, defaultValue)
|
|
145
|
+
)
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return react_1.default.createElement(
|
|
102
149
|
"div",
|
|
103
150
|
null,
|
|
104
|
-
react_1.default.createElement(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
151
|
+
react_1.default.createElement("strong", null, "Default value: "),
|
|
152
|
+
react_1.default.createElement(
|
|
153
|
+
"span",
|
|
154
|
+
null,
|
|
155
|
+
react_1.default.createElement(
|
|
156
|
+
"code",
|
|
157
|
+
null,
|
|
158
|
+
JSON.stringify(defaultValue)
|
|
159
|
+
)
|
|
160
|
+
)
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
109
165
|
const renderExample = (0, utils_1.guard)(
|
|
110
166
|
(0, utils_1.toString)(example),
|
|
111
167
|
(example) =>
|
|
@@ -186,8 +242,9 @@ function ParamsItem({
|
|
|
186
242
|
renderDeprecated
|
|
187
243
|
),
|
|
188
244
|
renderSchema,
|
|
189
|
-
renderDefaultValue,
|
|
190
245
|
renderDescription,
|
|
246
|
+
renderEnumDescriptions,
|
|
247
|
+
renderDefaultValue(),
|
|
191
248
|
renderExample,
|
|
192
249
|
renderExamples
|
|
193
250
|
);
|
|
@@ -9,4 +9,4 @@ export interface Props {
|
|
|
9
9
|
schema: any;
|
|
10
10
|
discriminator: boolean;
|
|
11
11
|
}
|
|
12
|
-
export default function SchemaItem(
|
|
12
|
+
export default function SchemaItem(props: Props): React.JSX.Element;
|
|
@@ -16,24 +16,47 @@ const CodeBlock_1 = __importDefault(require("@theme/CodeBlock"));
|
|
|
16
16
|
const clsx_1 = __importDefault(require("clsx"));
|
|
17
17
|
const react_markdown_1 = __importDefault(require("react-markdown"));
|
|
18
18
|
const rehype_raw_1 = __importDefault(require("rehype-raw"));
|
|
19
|
+
const remark_gfm_1 = __importDefault(require("remark-gfm"));
|
|
19
20
|
const createDescription_1 = require("../../markdown/createDescription");
|
|
20
21
|
const utils_1 = require("../../markdown/utils");
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
const transformEnumDescriptions = (enumDescriptions) => {
|
|
23
|
+
if (enumDescriptions) {
|
|
24
|
+
return Object.entries(enumDescriptions);
|
|
25
|
+
}
|
|
26
|
+
return [];
|
|
27
|
+
};
|
|
28
|
+
const getEnumDescriptionMarkdown = (enumDescriptions) => {
|
|
29
|
+
if (enumDescriptions?.length) {
|
|
30
|
+
return `| Enum Value | Description |
|
|
31
|
+
| ---- | ----- |
|
|
32
|
+
${enumDescriptions
|
|
33
|
+
.map((desc) => {
|
|
34
|
+
return `| ${desc[0]} | ${desc[1]} | `.replaceAll("\n", "<br/>");
|
|
35
|
+
})
|
|
36
|
+
.join("\n")}
|
|
37
|
+
`;
|
|
38
|
+
}
|
|
39
|
+
return "";
|
|
40
|
+
};
|
|
41
|
+
function SchemaItem(props) {
|
|
42
|
+
const {
|
|
43
|
+
children: collapsibleSchemaContent,
|
|
44
|
+
collapsible,
|
|
45
|
+
name,
|
|
46
|
+
qualifierMessage,
|
|
47
|
+
required,
|
|
48
|
+
schemaName,
|
|
49
|
+
schema,
|
|
50
|
+
} = props;
|
|
30
51
|
let deprecated;
|
|
31
52
|
let schemaDescription;
|
|
32
53
|
let defaultValue;
|
|
33
54
|
let nullable;
|
|
55
|
+
let enumDescriptions = [];
|
|
34
56
|
if (schema) {
|
|
35
57
|
deprecated = schema.deprecated;
|
|
36
58
|
schemaDescription = schema.description;
|
|
59
|
+
enumDescriptions = transformEnumDescriptions(schema["x-enumDescriptions"]);
|
|
37
60
|
defaultValue = schema.default;
|
|
38
61
|
nullable = schema.nullable;
|
|
39
62
|
}
|
|
@@ -60,6 +83,16 @@ function SchemaItem({
|
|
|
60
83
|
"nullable"
|
|
61
84
|
)
|
|
62
85
|
);
|
|
86
|
+
const renderEnumDescriptions = (0, utils_1.guard)(
|
|
87
|
+
getEnumDescriptionMarkdown(enumDescriptions),
|
|
88
|
+
(value) => {
|
|
89
|
+
return react_1.default.createElement(react_markdown_1.default, {
|
|
90
|
+
remarkPlugins: [remark_gfm_1.default],
|
|
91
|
+
rehypePlugins: [rehype_raw_1.default],
|
|
92
|
+
children: value,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
);
|
|
63
96
|
const renderSchemaDescription = (0, utils_1.guard)(
|
|
64
97
|
schemaDescription,
|
|
65
98
|
(description) =>
|
|
@@ -103,15 +136,37 @@ function SchemaItem({
|
|
|
103
136
|
})
|
|
104
137
|
)
|
|
105
138
|
);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
"
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
139
|
+
function renderDefaultValue() {
|
|
140
|
+
if (defaultValue !== undefined) {
|
|
141
|
+
if (typeof defaultValue === "string") {
|
|
142
|
+
return react_1.default.createElement(
|
|
143
|
+
"div",
|
|
144
|
+
null,
|
|
145
|
+
react_1.default.createElement("strong", null, "Default value: "),
|
|
146
|
+
react_1.default.createElement(
|
|
147
|
+
"span",
|
|
148
|
+
null,
|
|
149
|
+
react_1.default.createElement("code", null, defaultValue)
|
|
150
|
+
)
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
return react_1.default.createElement(
|
|
154
|
+
"div",
|
|
155
|
+
null,
|
|
156
|
+
react_1.default.createElement("strong", null, "Default value: "),
|
|
157
|
+
react_1.default.createElement(
|
|
158
|
+
"span",
|
|
159
|
+
null,
|
|
160
|
+
react_1.default.createElement(
|
|
161
|
+
"code",
|
|
162
|
+
null,
|
|
163
|
+
JSON.stringify(defaultValue)
|
|
164
|
+
)
|
|
165
|
+
)
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
115
170
|
const schemaContent = react_1.default.createElement(
|
|
116
171
|
"div",
|
|
117
172
|
null,
|
|
@@ -141,9 +196,10 @@ function SchemaItem({
|
|
|
141
196
|
renderRequired,
|
|
142
197
|
renderDeprecated
|
|
143
198
|
),
|
|
144
|
-
renderQualifierMessage,
|
|
145
|
-
renderDefaultValue,
|
|
146
199
|
renderSchemaDescription,
|
|
200
|
+
renderEnumDescriptions,
|
|
201
|
+
renderQualifierMessage,
|
|
202
|
+
renderDefaultValue(),
|
|
147
203
|
collapsibleSchemaContent ?? collapsibleSchemaContent
|
|
148
204
|
);
|
|
149
205
|
return react_1.default.createElement(
|
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-822",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"clsx": "^1.1.1",
|
|
43
43
|
"copy-text-to-clipboard": "^3.1.0",
|
|
44
44
|
"crypto-js": "^4.1.1",
|
|
45
|
-
"docusaurus-plugin-openapi-docs": "0.0.0-
|
|
45
|
+
"docusaurus-plugin-openapi-docs": "0.0.0-822",
|
|
46
46
|
"docusaurus-plugin-sass": "^0.2.3",
|
|
47
47
|
"file-saver": "^2.0.5",
|
|
48
48
|
"lodash": "^4.17.20",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"react-modal": "^3.15.1",
|
|
58
58
|
"react-redux": "^7.2.0",
|
|
59
59
|
"rehype-raw": "^6.1.1",
|
|
60
|
+
"remark-gfm": "3.0.1",
|
|
60
61
|
"sass": "^1.58.1",
|
|
61
62
|
"sass-loader": "^13.3.2",
|
|
62
63
|
"webpack": "^5.61.0",
|
|
@@ -69,5 +70,5 @@
|
|
|
69
70
|
"engines": {
|
|
70
71
|
"node": ">=14"
|
|
71
72
|
},
|
|
72
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "45cf7902efde96e5b560f34d68113cfccda9f174"
|
|
73
74
|
}
|
|
@@ -114,6 +114,11 @@
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
.openapi-security__summary-container {
|
|
118
|
+
background: var(--ifm-pre-background);
|
|
119
|
+
border-radius: var(--ifm-pre-border-radius);
|
|
120
|
+
}
|
|
121
|
+
|
|
117
122
|
// Prevent auto zoom on mobile iOS devices when focusing on input elmenents
|
|
118
123
|
@media screen and (-webkit-min-device-pixel-ratio: 0) and (max-device-width: 1024px) {
|
|
119
124
|
.prism-code,
|
|
@@ -10,6 +10,7 @@ import React from "react";
|
|
|
10
10
|
import CodeSnippets from "@theme/ApiExplorer/CodeSnippets";
|
|
11
11
|
import Request from "@theme/ApiExplorer/Request";
|
|
12
12
|
import Response from "@theme/ApiExplorer/Response";
|
|
13
|
+
import SecuritySchemes from "@theme/ApiExplorer/SecuritySchemes";
|
|
13
14
|
import { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
|
|
14
15
|
import sdk from "postman-collection";
|
|
15
16
|
|
|
@@ -24,6 +25,7 @@ function ApiExplorer({
|
|
|
24
25
|
|
|
25
26
|
return (
|
|
26
27
|
<>
|
|
28
|
+
<SecuritySchemes infoPath={infoPath} />
|
|
27
29
|
{item.method !== "event" && (
|
|
28
30
|
<CodeSnippets
|
|
29
31
|
postman={postman}
|
|
@@ -14,6 +14,7 @@ import TabItem from "@theme/TabItem";
|
|
|
14
14
|
import clsx from "clsx";
|
|
15
15
|
import ReactMarkdown from "react-markdown";
|
|
16
16
|
import rehypeRaw from "rehype-raw";
|
|
17
|
+
import remarkGfm from "remark-gfm";
|
|
17
18
|
|
|
18
19
|
import { createDescription } from "../../markdown/createDescription";
|
|
19
20
|
import { getQualifierMessage, getSchemaName } from "../../markdown/schema";
|
|
@@ -39,15 +40,49 @@ export interface Props {
|
|
|
39
40
|
required: boolean;
|
|
40
41
|
deprecated: boolean;
|
|
41
42
|
schema: any;
|
|
43
|
+
enumDescriptions?: [string, string][];
|
|
42
44
|
};
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
const getEnumDescriptionMarkdown = (enumDescriptions?: [string, string][]) => {
|
|
48
|
+
if (enumDescriptions?.length) {
|
|
49
|
+
return `| Enum Value | Description |
|
|
50
|
+
| ---- | ----- |
|
|
51
|
+
${enumDescriptions
|
|
52
|
+
.map((desc) => {
|
|
53
|
+
return `| ${desc[0]} | ${desc[1]} | `.replaceAll("\n", "<br/>");
|
|
54
|
+
})
|
|
55
|
+
.join("\n")}
|
|
56
|
+
`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return "";
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
function ParamsItem({ param, ...rest }: Props) {
|
|
63
|
+
const {
|
|
64
|
+
description,
|
|
65
|
+
example,
|
|
66
|
+
examples,
|
|
67
|
+
name,
|
|
68
|
+
required,
|
|
69
|
+
deprecated,
|
|
70
|
+
enumDescriptions,
|
|
71
|
+
} = param;
|
|
72
|
+
|
|
73
|
+
let schema = param.schema;
|
|
74
|
+
let defaultValue: string | undefined;
|
|
75
|
+
|
|
48
76
|
if (!schema || !schema?.type) {
|
|
49
77
|
schema = { type: "any" };
|
|
50
78
|
}
|
|
79
|
+
if (schema) {
|
|
80
|
+
if (schema.items) {
|
|
81
|
+
defaultValue = schema.items.default;
|
|
82
|
+
} else {
|
|
83
|
+
defaultValue = schema.default;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
51
86
|
|
|
52
87
|
const renderSchemaName = guard(schema, (schema) => (
|
|
53
88
|
<span className="openapi-schema__type"> {getSchemaName(schema)}</span>
|
|
@@ -91,19 +126,43 @@ function ParamsItem({
|
|
|
91
126
|
</div>
|
|
92
127
|
));
|
|
93
128
|
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
129
|
+
const renderEnumDescriptions = guard(
|
|
130
|
+
getEnumDescriptionMarkdown(enumDescriptions),
|
|
131
|
+
(value) => {
|
|
132
|
+
return (
|
|
133
|
+
<ReactMarkdown
|
|
134
|
+
rehypePlugins={[rehypeRaw]}
|
|
135
|
+
remarkPlugins={[remarkGfm]}
|
|
136
|
+
children={value}
|
|
137
|
+
/>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
105
140
|
);
|
|
106
141
|
|
|
142
|
+
function renderDefaultValue() {
|
|
143
|
+
if (defaultValue !== undefined) {
|
|
144
|
+
if (typeof defaultValue === "string") {
|
|
145
|
+
return (
|
|
146
|
+
<div>
|
|
147
|
+
<strong>Default value: </strong>
|
|
148
|
+
<span>
|
|
149
|
+
<code>{defaultValue}</code>
|
|
150
|
+
</span>
|
|
151
|
+
</div>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
return (
|
|
155
|
+
<div>
|
|
156
|
+
<strong>Default value: </strong>
|
|
157
|
+
<span>
|
|
158
|
+
<code>{JSON.stringify(defaultValue)}</code>
|
|
159
|
+
</span>
|
|
160
|
+
</div>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
|
|
107
166
|
const renderExample = guard(toString(example), (example) => (
|
|
108
167
|
<div>
|
|
109
168
|
<strong>Example: </strong>
|
|
@@ -156,8 +215,9 @@ function ParamsItem({
|
|
|
156
215
|
{renderDeprecated}
|
|
157
216
|
</span>
|
|
158
217
|
{renderSchema}
|
|
159
|
-
{renderDefaultValue}
|
|
160
218
|
{renderDescription}
|
|
219
|
+
{renderEnumDescriptions}
|
|
220
|
+
{renderDefaultValue()}
|
|
161
221
|
{renderExample}
|
|
162
222
|
{renderExamples}
|
|
163
223
|
</div>
|
|
@@ -11,6 +11,7 @@ import CodeBlock from "@theme/CodeBlock";
|
|
|
11
11
|
import clsx from "clsx";
|
|
12
12
|
import ReactMarkdown from "react-markdown";
|
|
13
13
|
import rehypeRaw from "rehype-raw";
|
|
14
|
+
import remarkGfm from "remark-gfm";
|
|
14
15
|
|
|
15
16
|
import { createDescription } from "../../markdown/createDescription";
|
|
16
17
|
import { guard } from "../../markdown/utils";
|
|
@@ -27,22 +28,51 @@ export interface Props {
|
|
|
27
28
|
discriminator: boolean;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
31
|
+
const transformEnumDescriptions = (
|
|
32
|
+
enumDescriptions?: Record<string, string>
|
|
33
|
+
) => {
|
|
34
|
+
if (enumDescriptions) {
|
|
35
|
+
return Object.entries(enumDescriptions);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return [];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const getEnumDescriptionMarkdown = (enumDescriptions?: [string, string][]) => {
|
|
42
|
+
if (enumDescriptions?.length) {
|
|
43
|
+
return `| Enum Value | Description |
|
|
44
|
+
| ---- | ----- |
|
|
45
|
+
${enumDescriptions
|
|
46
|
+
.map((desc) => {
|
|
47
|
+
return `| ${desc[0]} | ${desc[1]} | `.replaceAll("\n", "<br/>");
|
|
48
|
+
})
|
|
49
|
+
.join("\n")}
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return "";
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default function SchemaItem(props: Props) {
|
|
57
|
+
const {
|
|
58
|
+
children: collapsibleSchemaContent,
|
|
59
|
+
collapsible,
|
|
60
|
+
name,
|
|
61
|
+
qualifierMessage,
|
|
62
|
+
required,
|
|
63
|
+
schemaName,
|
|
64
|
+
schema,
|
|
65
|
+
} = props;
|
|
39
66
|
let deprecated;
|
|
40
67
|
let schemaDescription;
|
|
41
|
-
let defaultValue;
|
|
68
|
+
let defaultValue: string | undefined;
|
|
42
69
|
let nullable;
|
|
70
|
+
let enumDescriptions: [string, string][] = [];
|
|
71
|
+
|
|
43
72
|
if (schema) {
|
|
44
73
|
deprecated = schema.deprecated;
|
|
45
74
|
schemaDescription = schema.description;
|
|
75
|
+
enumDescriptions = transformEnumDescriptions(schema["x-enumDescriptions"]);
|
|
46
76
|
defaultValue = schema.default;
|
|
47
77
|
nullable = schema.nullable;
|
|
48
78
|
}
|
|
@@ -60,6 +90,19 @@ export default function SchemaItem({
|
|
|
60
90
|
<span className="openapi-schema__nullable">nullable</span>
|
|
61
91
|
));
|
|
62
92
|
|
|
93
|
+
const renderEnumDescriptions = guard(
|
|
94
|
+
getEnumDescriptionMarkdown(enumDescriptions),
|
|
95
|
+
(value) => {
|
|
96
|
+
return (
|
|
97
|
+
<ReactMarkdown
|
|
98
|
+
remarkPlugins={[remarkGfm]}
|
|
99
|
+
rehypePlugins={[rehypeRaw]}
|
|
100
|
+
children={value}
|
|
101
|
+
/>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
|
|
63
106
|
const renderSchemaDescription = guard(schemaDescription, (description) => (
|
|
64
107
|
<div>
|
|
65
108
|
<ReactMarkdown
|
|
@@ -90,11 +133,29 @@ export default function SchemaItem({
|
|
|
90
133
|
</div>
|
|
91
134
|
));
|
|
92
135
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
136
|
+
function renderDefaultValue() {
|
|
137
|
+
if (defaultValue !== undefined) {
|
|
138
|
+
if (typeof defaultValue === "string") {
|
|
139
|
+
return (
|
|
140
|
+
<div>
|
|
141
|
+
<strong>Default value: </strong>
|
|
142
|
+
<span>
|
|
143
|
+
<code>{defaultValue}</code>
|
|
144
|
+
</span>
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return (
|
|
149
|
+
<div>
|
|
150
|
+
<strong>Default value: </strong>
|
|
151
|
+
<span>
|
|
152
|
+
<code>{JSON.stringify(defaultValue)}</code>
|
|
153
|
+
</span>
|
|
154
|
+
</div>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
98
159
|
|
|
99
160
|
const schemaContent = (
|
|
100
161
|
<div>
|
|
@@ -114,9 +175,10 @@ export default function SchemaItem({
|
|
|
114
175
|
{renderRequired}
|
|
115
176
|
{renderDeprecated}
|
|
116
177
|
</span>
|
|
117
|
-
{renderQualifierMessage}
|
|
118
|
-
{renderDefaultValue}
|
|
119
178
|
{renderSchemaDescription}
|
|
179
|
+
{renderEnumDescriptions}
|
|
180
|
+
{renderQualifierMessage}
|
|
181
|
+
{renderDefaultValue()}
|
|
120
182
|
{collapsibleSchemaContent ?? collapsibleSchemaContent}
|
|
121
183
|
</div>
|
|
122
184
|
);
|