docusaurus-theme-openapi-docs 0.0.0-1154 → 0.0.0-1155

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.
@@ -13,6 +13,9 @@ var __importDefault =
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  const react_1 = __importDefault(require("react"));
15
15
  const BrowserOnly_1 = __importDefault(require("@docusaurus/BrowserOnly"));
16
+ const ExecutionEnvironment_1 = __importDefault(
17
+ require("@docusaurus/ExecutionEnvironment")
18
+ );
16
19
  const hooks_1 = require("@theme/ApiItem/hooks");
17
20
  function colorForMethod(method) {
18
21
  switch (method.toLowerCase()) {
@@ -35,6 +38,31 @@ function colorForMethod(method) {
35
38
  }
36
39
  }
37
40
  function MethodEndpoint({ method, path, context }) {
41
+ // During SSR, render without Redux store access to avoid "Cannot read properties
42
+ // of null (reading 'store')" errors caused by useSelector running outside a Provider.
43
+ if (!ExecutionEnvironment_1.default.canUseDOM) {
44
+ return react_1.default.createElement(
45
+ react_1.default.Fragment,
46
+ null,
47
+ react_1.default.createElement(
48
+ "pre",
49
+ { className: "openapi__method-endpoint" },
50
+ react_1.default.createElement(
51
+ "span",
52
+ { className: "badge badge--" + colorForMethod(method) },
53
+ method === "event" ? "Webhook" : method.toUpperCase()
54
+ ),
55
+ " ",
56
+ method !== "event" &&
57
+ react_1.default.createElement(
58
+ "h2",
59
+ { className: "openapi__method-endpoint-path" },
60
+ `${path.replace(/{([a-z0-9-_]+)}/gi, ":$1")}`
61
+ )
62
+ ),
63
+ react_1.default.createElement("div", { className: "openapi__divider" })
64
+ );
65
+ }
38
66
  let serverValue = (0, hooks_1.useTypedSelector)(
39
67
  (state) => state.server.value
40
68
  );
@@ -226,6 +226,12 @@ const Summary = ({ name, schemaName, schema, required }) => {
226
226
  };
227
227
  const AnyOneOf = ({ schema, schemaType, schemaPath }) => {
228
228
  const key = schema.oneOf ? "oneOf" : "anyOf";
229
+ const schemaArray = schema[key];
230
+ // Empty oneOf/anyOf arrays are valid in OpenAPI specs but would cause the
231
+ // Tabs component to throw "requires at least one TabItem". Return null instead.
232
+ if (!schemaArray || !Array.isArray(schemaArray) || schemaArray.length === 0) {
233
+ return null;
234
+ }
229
235
  const type = schema.oneOf
230
236
  ? (0, Translate_1.translate)({
231
237
  id: translationIds_1.OPENAPI_SCHEMA_ITEM.ONE_OF,
@@ -7,4 +7,4 @@ export interface SchemaTabsProps extends TabProps {
7
7
  */
8
8
  onChange?: (index: number) => void;
9
9
  }
10
- export default function SchemaTabs(props: SchemaTabsProps): React.JSX.Element;
10
+ export default function SchemaTabs(props: SchemaTabsProps): React.JSX.Element | null;
@@ -252,6 +252,26 @@ function TabsComponent(props) {
252
252
  }
253
253
  function SchemaTabs(props) {
254
254
  const isBrowser = (0, useIsBrowser_1.default)();
255
+ const children = Array.isArray(props.children)
256
+ ? props.children.filter(Boolean)
257
+ : props.children
258
+ ? [props.children]
259
+ : [];
260
+ if (children.length === 0) {
261
+ return null;
262
+ }
263
+ let sanitizedChildren;
264
+ try {
265
+ sanitizedChildren = (0, internal_1.sanitizeTabsChildren)(children);
266
+ } catch {
267
+ return null;
268
+ }
269
+ if (
270
+ !sanitizedChildren ||
271
+ (Array.isArray(sanitizedChildren) && sanitizedChildren.length === 0)
272
+ ) {
273
+ return null;
274
+ }
255
275
  return react_1.default.createElement(
256
276
  TabsComponent,
257
277
  // Remount tabs after hydration
@@ -262,6 +282,6 @@ function SchemaTabs(props) {
262
282
  key: String(isBrowser),
263
283
  ...props,
264
284
  },
265
- (0, internal_1.sanitizeTabsChildren)(props.children)
285
+ sanitizedChildren
266
286
  );
267
287
  }
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-1154",
4
+ "version": "0.0.0-1155",
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-1154",
41
+ "docusaurus-plugin-openapi-docs": "0.0.0-1155",
42
42
  "docusaurus-plugin-sass": "^0.2.6",
43
43
  "eslint-plugin-prettier": "^5.5.1"
44
44
  },
@@ -82,5 +82,5 @@
82
82
  "engines": {
83
83
  "node": ">=14"
84
84
  },
85
- "gitHead": "0debbc67d743f553056175f125d0df187f4e4939"
85
+ "gitHead": "388036c8328b54f841365688b671422a418098bb"
86
86
  }
@@ -8,6 +8,7 @@
8
8
  import React from "react";
9
9
 
10
10
  import BrowserOnly from "@docusaurus/BrowserOnly";
11
+ import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
11
12
  import { useTypedSelector } from "@theme/ApiItem/hooks";
12
13
 
13
14
  function colorForMethod(method: string) {
@@ -38,6 +39,26 @@ export interface Props {
38
39
  }
39
40
 
40
41
  function MethodEndpoint({ method, path, context }: Props) {
42
+ // During SSR, render without Redux store access to avoid "Cannot read properties
43
+ // of null (reading 'store')" errors caused by useSelector running outside a Provider.
44
+ if (!ExecutionEnvironment.canUseDOM) {
45
+ return (
46
+ <>
47
+ <pre className="openapi__method-endpoint">
48
+ <span className={"badge badge--" + colorForMethod(method)}>
49
+ {method === "event" ? "Webhook" : method.toUpperCase()}
50
+ </span>{" "}
51
+ {method !== "event" && (
52
+ <h2 className="openapi__method-endpoint-path">
53
+ {`${path.replace(/{([a-z0-9-_]+)}/gi, ":$1")}`}
54
+ </h2>
55
+ )}
56
+ </pre>
57
+ <div className="openapi__divider" />
58
+ </>
59
+ );
60
+ }
61
+
41
62
  let serverValue = useTypedSelector((state: any) => state.server.value);
42
63
  let serverUrlWithVariables = "";
43
64
 
@@ -214,6 +214,14 @@ const AnyOneOf: React.FC<SchemaProps> = ({
214
214
  schemaPath,
215
215
  }) => {
216
216
  const key = schema.oneOf ? "oneOf" : "anyOf";
217
+ const schemaArray = schema[key];
218
+
219
+ // Empty oneOf/anyOf arrays are valid in OpenAPI specs but would cause the
220
+ // Tabs component to throw "requires at least one TabItem". Return null instead.
221
+ if (!schemaArray || !Array.isArray(schemaArray) || schemaArray.length === 0) {
222
+ return null;
223
+ }
224
+
217
225
  const type = schema.oneOf
218
226
  ? translate({ id: OPENAPI_SCHEMA_ITEM.ONE_OF, message: "oneOf" })
219
227
  : translate({ id: OPENAPI_SCHEMA_ITEM.ANY_OF, message: "anyOf" });
@@ -223,8 +223,35 @@ function TabsComponent(props: SchemaTabsProps): React.JSX.Element {
223
223
  </div>
224
224
  );
225
225
  }
226
- export default function SchemaTabs(props: SchemaTabsProps): React.JSX.Element {
226
+ export default function SchemaTabs(
227
+ props: SchemaTabsProps
228
+ ): React.JSX.Element | null {
227
229
  const isBrowser = useIsBrowser();
230
+
231
+ const children = Array.isArray(props.children)
232
+ ? props.children.filter(Boolean)
233
+ : props.children
234
+ ? [props.children]
235
+ : [];
236
+
237
+ if (children.length === 0) {
238
+ return null;
239
+ }
240
+
241
+ let sanitizedChildren;
242
+ try {
243
+ sanitizedChildren = sanitizeTabsChildren(children);
244
+ } catch {
245
+ return null;
246
+ }
247
+
248
+ if (
249
+ !sanitizedChildren ||
250
+ (Array.isArray(sanitizedChildren) && sanitizedChildren.length === 0)
251
+ ) {
252
+ return null;
253
+ }
254
+
228
255
  return (
229
256
  <TabsComponent
230
257
  // Remount tabs after hydration
@@ -232,7 +259,7 @@ export default function SchemaTabs(props: SchemaTabsProps): React.JSX.Element {
232
259
  key={String(isBrowser)}
233
260
  {...props}
234
261
  >
235
- {sanitizeTabsChildren(props.children)}
262
+ {sanitizedChildren}
236
263
  </TabsComponent>
237
264
  );
238
265
  }