docusaurus-theme-openapi-docs 2.1.0 → 2.1.2

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.
@@ -17,11 +17,11 @@ function create(tag, props) {
17
17
  }
18
18
  exports.create = create;
19
19
  function guard(value, cb) {
20
- if (value === undefined || value === "") {
21
- return "";
20
+ if (!!value || value === 0) {
21
+ const children = cb(value);
22
+ return render(children);
22
23
  }
23
- const children = cb(value);
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");
@@ -67,11 +67,13 @@ function TabList({
67
67
  useEffect(() => {
68
68
  const resizeObserver = new ResizeObserver((entries) => {
69
69
  for (let entry of entries) {
70
- if (entry.target.offsetWidth < entry.target.scrollWidth) {
71
- setShowTabArrows(true);
72
- } else {
73
- setShowTabArrows(false);
74
- }
70
+ requestAnimationFrame(() => {
71
+ if (entry.target.offsetWidth < entry.target.scrollWidth) {
72
+ setShowTabArrows(true);
73
+ } else {
74
+ setShowTabArrows(false);
75
+ }
76
+ });
75
77
  }
76
78
  });
77
79
 
@@ -57,11 +57,13 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
57
57
  useEffect(() => {
58
58
  const resizeObserver = new ResizeObserver((entries) => {
59
59
  for (let entry of entries) {
60
- if (entry.target.offsetWidth < entry.target.scrollWidth) {
61
- setShowTabArrows(true);
62
- } else {
63
- setShowTabArrows(false);
64
- }
60
+ requestAnimationFrame(() => {
61
+ if (entry.target.offsetWidth < entry.target.scrollWidth) {
62
+ setShowTabArrows(true);
63
+ } else {
64
+ setShowTabArrows(false);
65
+ }
66
+ });
65
67
  }
66
68
  });
67
69
 
@@ -94,11 +94,13 @@ function TabList({
94
94
  useEffect(() => {
95
95
  const resizeObserver = new ResizeObserver((entries) => {
96
96
  for (let entry of entries) {
97
- if (entry.target.offsetWidth < entry.target.scrollWidth) {
98
- setShowTabArrows(true);
99
- } else {
100
- setShowTabArrows(false);
101
- }
97
+ requestAnimationFrame(() => {
98
+ if (entry.target.offsetWidth < entry.target.scrollWidth) {
99
+ setShowTabArrows(true);
100
+ } else {
101
+ setShowTabArrows(false);
102
+ }
103
+ });
102
104
  }
103
105
  });
104
106
 
@@ -60,11 +60,13 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
60
60
  useEffect(() => {
61
61
  const resizeObserver = new ResizeObserver((entries) => {
62
62
  for (let entry of entries) {
63
- if (entry.target.offsetWidth < entry.target.scrollWidth) {
64
- setShowTabArrows(true);
65
- } else {
66
- setShowTabArrows(false);
67
- }
63
+ requestAnimationFrame(() => {
64
+ if (entry.target.offsetWidth < entry.target.scrollWidth) {
65
+ setShowTabArrows(true);
66
+ } else {
67
+ setShowTabArrows(false);
68
+ }
69
+ });
68
70
  }
69
71
  });
70
72
 
@@ -11,6 +11,7 @@ import CodeBlock from "@theme/CodeBlock";
11
11
  import SchemaTabs from "@theme/SchemaTabs";
12
12
  import TabItem from "@theme/TabItem";
13
13
  /* eslint-disable import/no-extraneous-dependencies*/
14
+ import clsx from "clsx";
14
15
  import { createDescription } from "docusaurus-theme-openapi-docs/lib/markdown/createDescription";
15
16
  /* eslint-disable import/no-extraneous-dependencies*/
16
17
  import {
@@ -26,7 +27,7 @@ import ReactMarkdown from "react-markdown";
26
27
  import rehypeRaw from "rehype-raw";
27
28
 
28
29
  function ParamsItem({
29
- param: { description, example, examples, name, required, schema },
30
+ param: { description, example, examples, name, required, schema, deprecated },
30
31
  }) {
31
32
  if (!schema || !schema?.type) {
32
33
  schema = { type: "any" };
@@ -40,6 +41,10 @@ function ParamsItem({
40
41
  <span className="openapi-schema__required">required</span>
41
42
  ));
42
43
 
44
+ const renderDeprecated = guard(deprecated, () => (
45
+ <span className="openapi-schema__deprecated">deprecated</span>
46
+ ));
47
+
43
48
  const renderSchema = guard(getQualifierMessage(schema), (message) => (
44
49
  <div>
45
50
  <ReactMarkdown
@@ -119,10 +124,19 @@ function ParamsItem({
119
124
  return (
120
125
  <div className="openapi-params__list-item">
121
126
  <span className="openapi-schema__container">
122
- <strong className="openapi-schema__property">{name}</strong>
127
+ <strong
128
+ className={clsx("openapi-schema__property", {
129
+ "openapi-schema__strikethrough": deprecated,
130
+ })}
131
+ >
132
+ {name}
133
+ </strong>
123
134
  {renderSchemaName}
124
- {required && <span className="openapi-schema__divider"></span>}
135
+ {(required || deprecated) && (
136
+ <span className="openapi-schema__divider"></span>
137
+ )}
125
138
  {renderSchemaRequired}
139
+ {renderDeprecated}
126
140
  </span>
127
141
  {renderSchema}
128
142
  {renderDefaultValue}
@@ -100,7 +100,7 @@ function SchemaItem({
100
100
  <span className="openapi-schema__divider"></span>
101
101
  )}
102
102
  {renderNullable}
103
- {!deprecated && renderRequired}
103
+ {renderRequired}
104
104
  {renderDeprecated}
105
105
  </span>
106
106
  {renderQualifierMessage}
@@ -57,11 +57,13 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
57
57
  useEffect(() => {
58
58
  const resizeObserver = new ResizeObserver((entries) => {
59
59
  for (let entry of entries) {
60
- if (entry.target.offsetWidth < entry.target.scrollWidth) {
61
- setShowTabArrows(true);
62
- } else {
63
- setShowTabArrows(false);
64
- }
60
+ requestAnimationFrame(() => {
61
+ if (entry.target.offsetWidth < entry.target.scrollWidth) {
62
+ setShowTabArrows(true);
63
+ } else {
64
+ setShowTabArrows(false);
65
+ }
66
+ });
65
67
  }
66
68
  });
67
69
 
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": "2.1.0",
4
+ "version": "2.1.2",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -43,7 +43,7 @@
43
43
  "clsx": "^1.1.1",
44
44
  "copy-text-to-clipboard": "^3.1.0",
45
45
  "crypto-js": "^4.1.1",
46
- "docusaurus-plugin-openapi-docs": "^2.1.0",
46
+ "docusaurus-plugin-openapi-docs": "^2.1.2",
47
47
  "docusaurus-plugin-sass": "^0.2.3",
48
48
  "file-saver": "^2.0.5",
49
49
  "lodash": "^4.17.20",
@@ -68,5 +68,5 @@
68
68
  "engines": {
69
69
  "node": ">=14"
70
70
  },
71
- "gitHead": "9064dd22c8e18125f838fd88caba6364e5484b68"
71
+ "gitHead": "4bb7040ce39ebe38b2a2837ab0c6a8c477a9a546"
72
72
  }
@@ -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");
@@ -24,11 +24,11 @@ export function guard<T>(
24
24
  value: T | undefined | string,
25
25
  cb: (value: T) => Children
26
26
  ): string {
27
- if (value === undefined || value === "") {
28
- return "";
27
+ if (!!value || value === 0) {
28
+ const children = cb(value as T);
29
+ return render(children);
29
30
  }
30
- const children = cb(value as T);
31
- return render(children);
31
+ return "";
32
32
  }
33
33
 
34
34
  export function render(children: Children): string {
@@ -67,11 +67,13 @@ function TabList({
67
67
  useEffect(() => {
68
68
  const resizeObserver = new ResizeObserver((entries) => {
69
69
  for (let entry of entries) {
70
- if (entry.target.offsetWidth < entry.target.scrollWidth) {
71
- setShowTabArrows(true);
72
- } else {
73
- setShowTabArrows(false);
74
- }
70
+ requestAnimationFrame(() => {
71
+ if (entry.target.offsetWidth < entry.target.scrollWidth) {
72
+ setShowTabArrows(true);
73
+ } else {
74
+ setShowTabArrows(false);
75
+ }
76
+ });
75
77
  }
76
78
  });
77
79
 
@@ -57,11 +57,13 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
57
57
  useEffect(() => {
58
58
  const resizeObserver = new ResizeObserver((entries) => {
59
59
  for (let entry of entries) {
60
- if (entry.target.offsetWidth < entry.target.scrollWidth) {
61
- setShowTabArrows(true);
62
- } else {
63
- setShowTabArrows(false);
64
- }
60
+ requestAnimationFrame(() => {
61
+ if (entry.target.offsetWidth < entry.target.scrollWidth) {
62
+ setShowTabArrows(true);
63
+ } else {
64
+ setShowTabArrows(false);
65
+ }
66
+ });
65
67
  }
66
68
  });
67
69
 
@@ -94,11 +94,13 @@ function TabList({
94
94
  useEffect(() => {
95
95
  const resizeObserver = new ResizeObserver((entries) => {
96
96
  for (let entry of entries) {
97
- if (entry.target.offsetWidth < entry.target.scrollWidth) {
98
- setShowTabArrows(true);
99
- } else {
100
- setShowTabArrows(false);
101
- }
97
+ requestAnimationFrame(() => {
98
+ if (entry.target.offsetWidth < entry.target.scrollWidth) {
99
+ setShowTabArrows(true);
100
+ } else {
101
+ setShowTabArrows(false);
102
+ }
103
+ });
102
104
  }
103
105
  });
104
106
 
@@ -60,11 +60,13 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
60
60
  useEffect(() => {
61
61
  const resizeObserver = new ResizeObserver((entries) => {
62
62
  for (let entry of entries) {
63
- if (entry.target.offsetWidth < entry.target.scrollWidth) {
64
- setShowTabArrows(true);
65
- } else {
66
- setShowTabArrows(false);
67
- }
63
+ requestAnimationFrame(() => {
64
+ if (entry.target.offsetWidth < entry.target.scrollWidth) {
65
+ setShowTabArrows(true);
66
+ } else {
67
+ setShowTabArrows(false);
68
+ }
69
+ });
68
70
  }
69
71
  });
70
72
 
@@ -11,6 +11,7 @@ import CodeBlock from "@theme/CodeBlock";
11
11
  import SchemaTabs from "@theme/SchemaTabs";
12
12
  import TabItem from "@theme/TabItem";
13
13
  /* eslint-disable import/no-extraneous-dependencies*/
14
+ import clsx from "clsx";
14
15
  import { createDescription } from "docusaurus-theme-openapi-docs/lib/markdown/createDescription";
15
16
  /* eslint-disable import/no-extraneous-dependencies*/
16
17
  import {
@@ -26,7 +27,7 @@ import ReactMarkdown from "react-markdown";
26
27
  import rehypeRaw from "rehype-raw";
27
28
 
28
29
  function ParamsItem({
29
- param: { description, example, examples, name, required, schema },
30
+ param: { description, example, examples, name, required, schema, deprecated },
30
31
  }) {
31
32
  if (!schema || !schema?.type) {
32
33
  schema = { type: "any" };
@@ -40,6 +41,10 @@ function ParamsItem({
40
41
  <span className="openapi-schema__required">required</span>
41
42
  ));
42
43
 
44
+ const renderDeprecated = guard(deprecated, () => (
45
+ <span className="openapi-schema__deprecated">deprecated</span>
46
+ ));
47
+
43
48
  const renderSchema = guard(getQualifierMessage(schema), (message) => (
44
49
  <div>
45
50
  <ReactMarkdown
@@ -119,10 +124,19 @@ function ParamsItem({
119
124
  return (
120
125
  <div className="openapi-params__list-item">
121
126
  <span className="openapi-schema__container">
122
- <strong className="openapi-schema__property">{name}</strong>
127
+ <strong
128
+ className={clsx("openapi-schema__property", {
129
+ "openapi-schema__strikethrough": deprecated,
130
+ })}
131
+ >
132
+ {name}
133
+ </strong>
123
134
  {renderSchemaName}
124
- {required && <span className="openapi-schema__divider"></span>}
135
+ {(required || deprecated) && (
136
+ <span className="openapi-schema__divider"></span>
137
+ )}
125
138
  {renderSchemaRequired}
139
+ {renderDeprecated}
126
140
  </span>
127
141
  {renderSchema}
128
142
  {renderDefaultValue}
@@ -100,7 +100,7 @@ function SchemaItem({
100
100
  <span className="openapi-schema__divider"></span>
101
101
  )}
102
102
  {renderNullable}
103
- {!deprecated && renderRequired}
103
+ {renderRequired}
104
104
  {renderDeprecated}
105
105
  </span>
106
106
  {renderQualifierMessage}
@@ -57,11 +57,13 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
57
57
  useEffect(() => {
58
58
  const resizeObserver = new ResizeObserver((entries) => {
59
59
  for (let entry of entries) {
60
- if (entry.target.offsetWidth < entry.target.scrollWidth) {
61
- setShowTabArrows(true);
62
- } else {
63
- setShowTabArrows(false);
64
- }
60
+ requestAnimationFrame(() => {
61
+ if (entry.target.offsetWidth < entry.target.scrollWidth) {
62
+ setShowTabArrows(true);
63
+ } else {
64
+ setShowTabArrows(false);
65
+ }
66
+ });
65
67
  }
66
68
  });
67
69