docusaurus-theme-openapi-docs 3.0.0-beta.6 → 3.0.0-beta.7
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/utils.js +4 -4
- package/lib/markdown/utils.test.js +4 -4
- package/lib/theme/ParamsItem/index.d.ts +2 -1
- package/lib/theme/ParamsItem/index.js +18 -4
- package/lib/theme/SchemaItem/index.js +1 -1
- package/package.json +3 -3
- package/src/markdown/utils.test.ts +5 -4
- package/src/markdown/utils.ts +4 -4
- package/src/theme/ParamsItem/index.tsx +19 -3
- package/src/theme/SchemaItem/index.tsx +1 -1
package/lib/markdown/utils.js
CHANGED
|
@@ -17,11 +17,11 @@ function create(tag, props) {
|
|
|
17
17
|
}
|
|
18
18
|
exports.create = create;
|
|
19
19
|
function guard(value, cb) {
|
|
20
|
-
if (value
|
|
21
|
-
|
|
20
|
+
if (!!value || value === 0) {
|
|
21
|
+
const children = cb(value);
|
|
22
|
+
return render(children);
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
return render(children);
|
|
24
|
+
return "";
|
|
25
25
|
}
|
|
26
26
|
exports.guard = guard;
|
|
27
27
|
function render(children) {
|
|
@@ -20,6 +20,10 @@ describe("guard", () => {
|
|
|
20
20
|
});
|
|
21
21
|
expect(actual).toBe("");
|
|
22
22
|
});
|
|
23
|
+
it("should guard false booleans", () => {
|
|
24
|
+
const actual = (0, utils_1.guard)(false, (value) => `${value}`);
|
|
25
|
+
expect(actual).toBe("");
|
|
26
|
+
});
|
|
23
27
|
it("should not guard strings", () => {
|
|
24
28
|
const actual = (0, utils_1.guard)("hello", (value) => value);
|
|
25
29
|
expect(actual).toBe("hello");
|
|
@@ -32,10 +36,6 @@ describe("guard", () => {
|
|
|
32
36
|
const actual = (0, utils_1.guard)(0, (value) => `${value}`);
|
|
33
37
|
expect(actual).toBe("0");
|
|
34
38
|
});
|
|
35
|
-
it("should not guard false booleans", () => {
|
|
36
|
-
const actual = (0, utils_1.guard)(false, (value) => `${value}`);
|
|
37
|
-
expect(actual).toBe("false");
|
|
38
|
-
});
|
|
39
39
|
it("should not guard true booleans", () => {
|
|
40
40
|
const actual = (0, utils_1.guard)(true, (value) => `${value}`);
|
|
41
41
|
expect(actual).toBe("true");
|
|
@@ -15,8 +15,9 @@ export interface Props {
|
|
|
15
15
|
examples: Map<ExampleObject>;
|
|
16
16
|
name: string;
|
|
17
17
|
required: boolean;
|
|
18
|
+
deprecated: boolean;
|
|
18
19
|
schema: any;
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
|
-
declare function ParamsItem({ param: { description, example, examples, name, required, schema }, }: Props): React.JSX.Element;
|
|
22
|
+
declare function ParamsItem({ param: { description, example, examples, name, required, schema, deprecated }, }: Props): React.JSX.Element;
|
|
22
23
|
export default ParamsItem;
|
|
@@ -15,13 +15,15 @@ const react_1 = __importDefault(require("react"));
|
|
|
15
15
|
const CodeBlock_1 = __importDefault(require("@theme/CodeBlock"));
|
|
16
16
|
const SchemaTabs_1 = __importDefault(require("@theme/SchemaTabs"));
|
|
17
17
|
const TabItem_1 = __importDefault(require("@theme/TabItem"));
|
|
18
|
+
/* eslint-disable import/no-extraneous-dependencies*/
|
|
19
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
18
20
|
const react_markdown_1 = __importDefault(require("react-markdown"));
|
|
19
21
|
const rehype_raw_1 = __importDefault(require("rehype-raw"));
|
|
20
22
|
const createDescription_1 = require("../../markdown/createDescription");
|
|
21
23
|
const schema_1 = require("../../markdown/schema");
|
|
22
24
|
const utils_1 = require("../../markdown/utils");
|
|
23
25
|
function ParamsItem({
|
|
24
|
-
param: { description, example, examples, name, required, schema },
|
|
26
|
+
param: { description, example, examples, name, required, schema, deprecated },
|
|
25
27
|
}) {
|
|
26
28
|
if (!schema || !schema?.type) {
|
|
27
29
|
schema = { type: "any" };
|
|
@@ -41,6 +43,13 @@ function ParamsItem({
|
|
|
41
43
|
"required"
|
|
42
44
|
)
|
|
43
45
|
);
|
|
46
|
+
const renderDeprecated = (0, utils_1.guard)(deprecated, () =>
|
|
47
|
+
react_1.default.createElement(
|
|
48
|
+
"span",
|
|
49
|
+
{ className: "openapi-schema__deprecated" },
|
|
50
|
+
"deprecated"
|
|
51
|
+
)
|
|
52
|
+
);
|
|
44
53
|
const renderSchema = (0, utils_1.guard)(
|
|
45
54
|
(0, schema_1.getQualifierMessage)(schema),
|
|
46
55
|
(message) =>
|
|
@@ -161,15 +170,20 @@ function ParamsItem({
|
|
|
161
170
|
{ className: "openapi-schema__container" },
|
|
162
171
|
react_1.default.createElement(
|
|
163
172
|
"strong",
|
|
164
|
-
{
|
|
173
|
+
{
|
|
174
|
+
className: (0, clsx_1.default)("openapi-schema__property", {
|
|
175
|
+
"openapi-schema__strikethrough": deprecated,
|
|
176
|
+
}),
|
|
177
|
+
},
|
|
165
178
|
name
|
|
166
179
|
),
|
|
167
180
|
renderSchemaName,
|
|
168
|
-
required &&
|
|
181
|
+
(required || deprecated) &&
|
|
169
182
|
react_1.default.createElement("span", {
|
|
170
183
|
className: "openapi-schema__divider",
|
|
171
184
|
}),
|
|
172
|
-
renderSchemaRequired
|
|
185
|
+
renderSchemaRequired,
|
|
186
|
+
renderDeprecated
|
|
173
187
|
),
|
|
174
188
|
renderSchema,
|
|
175
189
|
renderDefaultValue,
|
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": "3.0.0-beta.
|
|
4
|
+
"version": "3.0.0-beta.7",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"clsx": "^1.1.1",
|
|
45
45
|
"copy-text-to-clipboard": "^3.1.0",
|
|
46
46
|
"crypto-js": "^4.1.1",
|
|
47
|
-
"docusaurus-plugin-openapi-docs": "^3.0.0-beta.
|
|
47
|
+
"docusaurus-plugin-openapi-docs": "^3.0.0-beta.7",
|
|
48
48
|
"docusaurus-plugin-sass": "^0.2.3",
|
|
49
49
|
"file-saver": "^2.0.5",
|
|
50
50
|
"lodash": "^4.17.20",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"engines": {
|
|
70
70
|
"node": ">=14"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "effd6b9afc0c416618002189e3823dcfc4356f30"
|
|
73
73
|
}
|
|
@@ -22,6 +22,11 @@ describe("guard", () => {
|
|
|
22
22
|
expect(actual).toBe("");
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
+
it("should guard false booleans", () => {
|
|
26
|
+
const actual = guard(false, (value) => `${value}`);
|
|
27
|
+
expect(actual).toBe("");
|
|
28
|
+
});
|
|
29
|
+
|
|
25
30
|
it("should not guard strings", () => {
|
|
26
31
|
const actual = guard("hello", (value) => value);
|
|
27
32
|
expect(actual).toBe("hello");
|
|
@@ -37,10 +42,6 @@ describe("guard", () => {
|
|
|
37
42
|
expect(actual).toBe("0");
|
|
38
43
|
});
|
|
39
44
|
|
|
40
|
-
it("should not guard false booleans", () => {
|
|
41
|
-
const actual = guard(false, (value) => `${value}`);
|
|
42
|
-
expect(actual).toBe("false");
|
|
43
|
-
});
|
|
44
45
|
it("should not guard true booleans", () => {
|
|
45
46
|
const actual = guard(true, (value) => `${value}`);
|
|
46
47
|
expect(actual).toBe("true");
|
package/src/markdown/utils.ts
CHANGED
|
@@ -26,11 +26,11 @@ export function guard<T>(
|
|
|
26
26
|
value: T | undefined | string,
|
|
27
27
|
cb: (value: T) => Children
|
|
28
28
|
): string {
|
|
29
|
-
if (value
|
|
30
|
-
|
|
29
|
+
if (!!value || value === 0) {
|
|
30
|
+
const children = cb(value as T);
|
|
31
|
+
return render(children);
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
-
return render(children);
|
|
33
|
+
return "";
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export function render(children: Children): string {
|
|
@@ -10,6 +10,8 @@ import React from "react";
|
|
|
10
10
|
import CodeBlock from "@theme/CodeBlock";
|
|
11
11
|
import SchemaTabs from "@theme/SchemaTabs";
|
|
12
12
|
import TabItem from "@theme/TabItem";
|
|
13
|
+
/* eslint-disable import/no-extraneous-dependencies*/
|
|
14
|
+
import clsx from "clsx";
|
|
13
15
|
import ReactMarkdown from "react-markdown";
|
|
14
16
|
import rehypeRaw from "rehype-raw";
|
|
15
17
|
|
|
@@ -35,12 +37,13 @@ export interface Props {
|
|
|
35
37
|
examples: Map<ExampleObject>;
|
|
36
38
|
name: string;
|
|
37
39
|
required: boolean;
|
|
40
|
+
deprecated: boolean;
|
|
38
41
|
schema: any;
|
|
39
42
|
};
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
function ParamsItem({
|
|
43
|
-
param: { description, example, examples, name, required, schema },
|
|
46
|
+
param: { description, example, examples, name, required, schema, deprecated },
|
|
44
47
|
}: Props) {
|
|
45
48
|
if (!schema || !schema?.type) {
|
|
46
49
|
schema = { type: "any" };
|
|
@@ -54,6 +57,10 @@ function ParamsItem({
|
|
|
54
57
|
<span className="openapi-schema__required">required</span>
|
|
55
58
|
));
|
|
56
59
|
|
|
60
|
+
const renderDeprecated = guard(deprecated, () => (
|
|
61
|
+
<span className="openapi-schema__deprecated">deprecated</span>
|
|
62
|
+
));
|
|
63
|
+
|
|
57
64
|
const renderSchema = guard(getQualifierMessage(schema), (message) => (
|
|
58
65
|
<div>
|
|
59
66
|
<ReactMarkdown
|
|
@@ -134,10 +141,19 @@ function ParamsItem({
|
|
|
134
141
|
return (
|
|
135
142
|
<div className="openapi-params__list-item">
|
|
136
143
|
<span className="openapi-schema__container">
|
|
137
|
-
<strong
|
|
144
|
+
<strong
|
|
145
|
+
className={clsx("openapi-schema__property", {
|
|
146
|
+
"openapi-schema__strikethrough": deprecated,
|
|
147
|
+
})}
|
|
148
|
+
>
|
|
149
|
+
{name}
|
|
150
|
+
</strong>
|
|
138
151
|
{renderSchemaName}
|
|
139
|
-
{required &&
|
|
152
|
+
{(required || deprecated) && (
|
|
153
|
+
<span className="openapi-schema__divider"></span>
|
|
154
|
+
)}
|
|
140
155
|
{renderSchemaRequired}
|
|
156
|
+
{renderDeprecated}
|
|
141
157
|
</span>
|
|
142
158
|
{renderSchema}
|
|
143
159
|
{renderDefaultValue}
|