docusaurus-theme-openapi-docs 0.0.0-1104 → 0.0.0-1106

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.
@@ -10,6 +10,38 @@ exports.getSchemaName = getSchemaName;
10
10
  exports.getQualifierMessage = getQualifierMessage;
11
11
  const Translate_1 = require("@docusaurus/Translate");
12
12
  const translationIds_1 = require("../theme/translationIds");
13
+ /**
14
+ * Extracts enum values from a schema, including when wrapped in allOf.
15
+ */
16
+ function getEnumFromSchema(schema) {
17
+ if (schema.enum) {
18
+ return schema.enum;
19
+ }
20
+ if (schema.allOf && Array.isArray(schema.allOf)) {
21
+ for (const item of schema.allOf) {
22
+ if (item.enum) {
23
+ return item.enum;
24
+ }
25
+ }
26
+ }
27
+ return undefined;
28
+ }
29
+ /**
30
+ * Extracts the type from a schema, including when wrapped in allOf.
31
+ */
32
+ function getTypeFromSchema(schema) {
33
+ if (schema.type) {
34
+ return schema.type;
35
+ }
36
+ if (schema.allOf && Array.isArray(schema.allOf)) {
37
+ for (const item of schema.allOf) {
38
+ if (item.type) {
39
+ return item.type;
40
+ }
41
+ }
42
+ }
43
+ return undefined;
44
+ }
13
45
  function prettyName(schema, circular) {
14
46
  // Handle enum-only schemas (valid in JSON Schema)
15
47
  // When enum is present without explicit type, treat as string
@@ -26,6 +58,12 @@ function prettyName(schema, circular) {
26
58
  return schema.allOf[0];
27
59
  }
28
60
  }
61
+ // Check if allOf contains an enum - if so, return the type from allOf
62
+ const enumFromAllOf = getEnumFromSchema(schema);
63
+ if (enumFromAllOf) {
64
+ const typeFromAllOf = getTypeFromSchema(schema);
65
+ return typeFromAllOf ?? "string";
66
+ }
29
67
  return "object";
30
68
  }
31
69
  if (schema.oneOf) {
@@ -72,9 +110,11 @@ function getQualifierMessage(schema) {
72
110
  message: "Possible values:",
73
111
  })}** `;
74
112
  let qualifierGroups = [];
75
- if (schema.items && schema.items.enum) {
76
- if (schema.items.enum) {
77
- qualifierGroups.push(`[${schema.items.enum.map((e) => `\`${e}\``).join(", ")}]`);
113
+ // Check for enum in array items (directly or inside allOf)
114
+ if (schema.items) {
115
+ const itemsEnum = getEnumFromSchema(schema.items);
116
+ if (itemsEnum) {
117
+ qualifierGroups.push(`[${itemsEnum.map((e) => `\`${e}\``).join(", ")}]`);
78
118
  }
79
119
  }
80
120
  if (schema.minLength || schema.maxLength) {
@@ -146,8 +186,10 @@ function getQualifierMessage(schema) {
146
186
  const values = Object.keys(discriminator.mapping);
147
187
  qualifierGroups.push(`[${values.map((e) => `\`${e}\``).join(", ")}]`);
148
188
  }
149
- if (schema.enum) {
150
- qualifierGroups.push(`[${schema.enum.map((e) => `\`${e}\``).join(", ")}]`);
189
+ // Check for enum directly on schema or inside allOf
190
+ const schemaEnum = getEnumFromSchema(schema);
191
+ if (schemaEnum) {
192
+ qualifierGroups.push(`[${schemaEnum.map((e) => `\`${e}\``).join(", ")}]`);
151
193
  }
152
194
  if (schema.minItems) {
153
195
  qualifierGroups.push(`\`>= ${schema.minItems}\``);
@@ -18,6 +18,7 @@ const error_message_1 = require("@hookform/error-message");
18
18
  const FormMultiSelect_1 = __importDefault(
19
19
  require("@theme/ApiExplorer/FormMultiSelect")
20
20
  );
21
+ const ParamOptions_1 = require("@theme/ApiExplorer/ParamOptions");
21
22
  const slice_1 = require("@theme/ApiExplorer/ParamOptions/slice");
22
23
  const hooks_1 = require("@theme/ApiItem/hooks");
23
24
  const translationIds_1 = require("@theme/translationIds");
@@ -29,7 +30,7 @@ function ParamMultiSelectFormItem({ param }) {
29
30
  } = (0, react_hook_form_1.useFormContext)();
30
31
  const showErrorMessage = errors?.paramMultiSelect;
31
32
  const dispatch = (0, hooks_1.useTypedDispatch)();
32
- const options = param.schema?.items?.enum ?? [];
33
+ const options = (0, ParamOptions_1.getSchemaEnum)(param.schema?.items) ?? [];
33
34
  const pathParams = (0, hooks_1.useTypedSelector)(
34
35
  (state) => state.params.path
35
36
  );
@@ -16,6 +16,7 @@ const react_1 = __importDefault(require("react"));
16
16
  const Translate_1 = require("@docusaurus/Translate");
17
17
  const error_message_1 = require("@hookform/error-message");
18
18
  const FormSelect_1 = __importDefault(require("@theme/ApiExplorer/FormSelect"));
19
+ const ParamOptions_1 = require("@theme/ApiExplorer/ParamOptions");
19
20
  const slice_1 = require("@theme/ApiExplorer/ParamOptions/slice");
20
21
  const hooks_1 = require("@theme/ApiItem/hooks");
21
22
  const translationIds_1 = require("@theme/translationIds");
@@ -27,7 +28,7 @@ function ParamSelectFormItem({ param }) {
27
28
  } = (0, react_hook_form_1.useFormContext)();
28
29
  const showErrorMessage = errors?.paramSelect;
29
30
  const dispatch = (0, hooks_1.useTypedDispatch)();
30
- const options = param.schema?.enum ?? [];
31
+ const options = (0, ParamOptions_1.getSchemaEnum)(param.schema) ?? [];
31
32
  return react_1.default.createElement(
32
33
  react_1.default.Fragment,
33
34
  null,
@@ -3,5 +3,10 @@ import { Param } from "./slice";
3
3
  export interface ParamProps {
4
4
  param: Param;
5
5
  }
6
+ /**
7
+ * Extracts enum values from a schema, including when wrapped in allOf.
8
+ * This handles cases where an enum is referenced via allOf for composition.
9
+ */
10
+ export declare function getSchemaEnum(schema: any): any[] | undefined;
6
11
  declare function ParamOptions(): React.JSX.Element;
7
12
  export default ParamOptions;
@@ -67,6 +67,7 @@ var __importDefault =
67
67
  return mod && mod.__esModule ? mod : { default: mod };
68
68
  };
69
69
  Object.defineProperty(exports, "__esModule", { value: true });
70
+ exports.getSchemaEnum = getSchemaEnum;
70
71
  const react_1 = __importStar(require("react"));
71
72
  const Translate_1 = require("@docusaurus/Translate");
72
73
  const FormItem_1 = __importDefault(require("@theme/ApiExplorer/FormItem"));
@@ -87,8 +88,29 @@ const ParamTextFormItem_1 = __importDefault(
87
88
  );
88
89
  const hooks_1 = require("@theme/ApiItem/hooks");
89
90
  const translationIds_1 = require("@theme/translationIds");
91
+ /**
92
+ * Extracts enum values from a schema, including when wrapped in allOf.
93
+ * This handles cases where an enum is referenced via allOf for composition.
94
+ */
95
+ function getSchemaEnum(schema) {
96
+ // Direct enum on schema
97
+ if (schema?.enum) {
98
+ return schema.enum;
99
+ }
100
+ // Enum inside allOf - check each item
101
+ if (schema?.allOf && Array.isArray(schema.allOf)) {
102
+ for (const item of schema.allOf) {
103
+ if (item.enum) {
104
+ return item.enum;
105
+ }
106
+ }
107
+ }
108
+ return undefined;
109
+ }
90
110
  function ParamOption({ param }) {
91
- if (param.schema?.type === "array" && param.schema.items?.enum) {
111
+ const schemaEnum = getSchemaEnum(param.schema);
112
+ const itemsEnum = getSchemaEnum(param.schema?.items);
113
+ if (param.schema?.type === "array" && itemsEnum) {
92
114
  return react_1.default.createElement(ParamMultiSelectFormItem_1.default, {
93
115
  param: param,
94
116
  });
@@ -98,7 +120,7 @@ function ParamOption({ param }) {
98
120
  param: param,
99
121
  });
100
122
  }
101
- if (param.schema?.enum) {
123
+ if (schemaEnum) {
102
124
  return react_1.default.createElement(ParamSelectFormItem_1.default, {
103
125
  param: param,
104
126
  });
@@ -103,6 +103,7 @@ function Request({ item }) {
103
103
  const { siteConfig } = (0, useDocusaurusContext_1.default)();
104
104
  const themeConfig = siteConfig.themeConfig;
105
105
  const requestTimeout = themeConfig.api?.requestTimeout;
106
+ const requestCredentials = themeConfig.api?.requestCredentials;
106
107
  // Frontmatter proxy (per-spec) takes precedence over theme config proxy (site-wide)
107
108
  const proxy = frontMatterProxy ?? themeConfig.api?.proxy;
108
109
  const pathParams = (0, hooks_1.useTypedSelector)(
@@ -233,7 +234,8 @@ function Request({ item }) {
233
234
  postmanRequest,
234
235
  proxy,
235
236
  body,
236
- requestTimeout
237
+ requestTimeout,
238
+ requestCredentials
237
239
  );
238
240
  if (res.headers.get("content-type")?.includes("text/event-stream")) {
239
241
  await handleEventStream(res);
@@ -6,5 +6,5 @@ export declare class RequestError extends Error {
6
6
  originalError?: Error;
7
7
  constructor(type: RequestErrorType, message: string, originalError?: Error);
8
8
  }
9
- declare function makeRequest(request: sdk.Request, proxy: string | undefined, _body: Body, timeout?: number): Promise<Response>;
9
+ declare function makeRequest(request: sdk.Request, proxy: string | undefined, _body: Body, timeout?: number, credentials?: RequestCredentials): Promise<Response>;
10
10
  export default makeRequest;
@@ -89,7 +89,8 @@ async function makeRequest(
89
89
  request,
90
90
  proxy,
91
91
  _body,
92
- timeout = DEFAULT_REQUEST_TIMEOUT
92
+ timeout = DEFAULT_REQUEST_TIMEOUT,
93
+ credentials
93
94
  ) {
94
95
  const headers = request.toJSON().header;
95
96
  let myHeaders = new Headers();
@@ -221,6 +222,7 @@ async function makeRequest(
221
222
  method: request.method,
222
223
  headers: myHeaders,
223
224
  body: myBody,
225
+ ...(credentials && { credentials }),
224
226
  };
225
227
  let finalUrl = request.url.toString();
226
228
  if (proxy) {
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-1104",
4
+ "version": "0.0.0-1106",
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-1104",
41
+ "docusaurus-plugin-openapi-docs": "0.0.0-1106",
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": "3d15c677e5510b6b7a94d0f32004ca1dac6e8aa7"
84
+ "gitHead": "f0ef2d969b4244b515264100ae5122bf3e08f9dc"
85
85
  }
@@ -10,6 +10,44 @@ import { translate } from "@docusaurus/Translate";
10
10
  import { OPENAPI_SCHEMA_ITEM } from "../theme/translationIds";
11
11
  import { SchemaObject } from "../types";
12
12
 
13
+ /**
14
+ * Extracts enum values from a schema, including when wrapped in allOf.
15
+ */
16
+ function getEnumFromSchema(schema: SchemaObject): any[] | undefined {
17
+ if (schema.enum) {
18
+ return schema.enum;
19
+ }
20
+
21
+ if (schema.allOf && Array.isArray(schema.allOf)) {
22
+ for (const item of schema.allOf) {
23
+ if (item.enum) {
24
+ return item.enum;
25
+ }
26
+ }
27
+ }
28
+
29
+ return undefined;
30
+ }
31
+
32
+ /**
33
+ * Extracts the type from a schema, including when wrapped in allOf.
34
+ */
35
+ function getTypeFromSchema(schema: SchemaObject): string | undefined {
36
+ if (schema.type) {
37
+ return schema.type as string;
38
+ }
39
+
40
+ if (schema.allOf && Array.isArray(schema.allOf)) {
41
+ for (const item of schema.allOf) {
42
+ if (item.type) {
43
+ return item.type as string;
44
+ }
45
+ }
46
+ }
47
+
48
+ return undefined;
49
+ }
50
+
13
51
  function prettyName(schema: SchemaObject, circular?: boolean) {
14
52
  // Handle enum-only schemas (valid in JSON Schema)
15
53
  // When enum is present without explicit type, treat as string
@@ -28,6 +66,12 @@ function prettyName(schema: SchemaObject, circular?: boolean) {
28
66
  return schema.allOf[0];
29
67
  }
30
68
  }
69
+ // Check if allOf contains an enum - if so, return the type from allOf
70
+ const enumFromAllOf = getEnumFromSchema(schema);
71
+ if (enumFromAllOf) {
72
+ const typeFromAllOf = getTypeFromSchema(schema);
73
+ return typeFromAllOf ?? "string";
74
+ }
31
75
  return "object";
32
76
  }
33
77
 
@@ -92,10 +136,12 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
92
136
 
93
137
  let qualifierGroups = [];
94
138
 
95
- if (schema.items && schema.items.enum) {
96
- if (schema.items.enum) {
139
+ // Check for enum in array items (directly or inside allOf)
140
+ if (schema.items) {
141
+ const itemsEnum = getEnumFromSchema(schema.items as SchemaObject);
142
+ if (itemsEnum) {
97
143
  qualifierGroups.push(
98
- `[${schema.items.enum.map((e) => `\`${e}\``).join(", ")}]`
144
+ `[${itemsEnum.map((e) => `\`${e}\``).join(", ")}]`
99
145
  );
100
146
  }
101
147
  }
@@ -177,8 +223,10 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
177
223
  qualifierGroups.push(`[${values.map((e) => `\`${e}\``).join(", ")}]`);
178
224
  }
179
225
 
180
- if (schema.enum) {
181
- qualifierGroups.push(`[${schema.enum.map((e) => `\`${e}\``).join(", ")}]`);
226
+ // Check for enum directly on schema or inside allOf
227
+ const schemaEnum = getEnumFromSchema(schema);
228
+ if (schemaEnum) {
229
+ qualifierGroups.push(`[${schemaEnum.map((e) => `\`${e}\``).join(", ")}]`);
182
230
  }
183
231
 
184
232
  if (schema.minItems) {
@@ -10,6 +10,7 @@ import React from "react";
10
10
  import { translate } from "@docusaurus/Translate";
11
11
  import { ErrorMessage } from "@hookform/error-message";
12
12
  import FormMultiSelect from "@theme/ApiExplorer/FormMultiSelect";
13
+ import { getSchemaEnum } from "@theme/ApiExplorer/ParamOptions";
13
14
  import { Param, setParam } from "@theme/ApiExplorer/ParamOptions/slice";
14
15
  import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
15
16
  import { OPENAPI_FORM } from "@theme/translationIds";
@@ -29,7 +30,7 @@ export default function ParamMultiSelectFormItem({ param }: ParamProps) {
29
30
 
30
31
  const dispatch = useTypedDispatch();
31
32
 
32
- const options = param.schema?.items?.enum ?? [];
33
+ const options = getSchemaEnum(param.schema?.items) ?? [];
33
34
 
34
35
  const pathParams = useTypedSelector((state: any) => state.params.path);
35
36
  const queryParams = useTypedSelector((state: any) => state.params.query);
@@ -10,6 +10,7 @@ import React from "react";
10
10
  import { translate } from "@docusaurus/Translate";
11
11
  import { ErrorMessage } from "@hookform/error-message";
12
12
  import FormSelect from "@theme/ApiExplorer/FormSelect";
13
+ import { getSchemaEnum } from "@theme/ApiExplorer/ParamOptions";
13
14
  import { Param, setParam } from "@theme/ApiExplorer/ParamOptions/slice";
14
15
  import { useTypedDispatch } from "@theme/ApiItem/hooks";
15
16
  import { OPENAPI_FORM } from "@theme/translationIds";
@@ -29,7 +30,7 @@ export default function ParamSelectFormItem({ param }: ParamProps) {
29
30
 
30
31
  const dispatch = useTypedDispatch();
31
32
 
32
- const options = param.schema?.enum ?? [];
33
+ const options = getSchemaEnum(param.schema) ?? [];
33
34
 
34
35
  return (
35
36
  <>
@@ -23,8 +23,33 @@ export interface ParamProps {
23
23
  param: Param;
24
24
  }
25
25
 
26
+ /**
27
+ * Extracts enum values from a schema, including when wrapped in allOf.
28
+ * This handles cases where an enum is referenced via allOf for composition.
29
+ */
30
+ export function getSchemaEnum(schema: any): any[] | undefined {
31
+ // Direct enum on schema
32
+ if (schema?.enum) {
33
+ return schema.enum;
34
+ }
35
+
36
+ // Enum inside allOf - check each item
37
+ if (schema?.allOf && Array.isArray(schema.allOf)) {
38
+ for (const item of schema.allOf) {
39
+ if (item.enum) {
40
+ return item.enum;
41
+ }
42
+ }
43
+ }
44
+
45
+ return undefined;
46
+ }
47
+
26
48
  function ParamOption({ param }: ParamProps) {
27
- if (param.schema?.type === "array" && param.schema.items?.enum) {
49
+ const schemaEnum = getSchemaEnum(param.schema);
50
+ const itemsEnum = getSchemaEnum(param.schema?.items);
51
+
52
+ if (param.schema?.type === "array" && itemsEnum) {
28
53
  return <ParamMultiSelectFormItem param={param} />;
29
54
  }
30
55
 
@@ -32,7 +57,7 @@ function ParamOption({ param }: ParamProps) {
32
57
  return <ParamArrayFormItem param={param} />;
33
58
  }
34
59
 
35
- if (param.schema?.enum) {
60
+ if (schemaEnum) {
36
61
  return <ParamSelectFormItem param={param} />;
37
62
  }
38
63
 
@@ -43,6 +43,7 @@ function Request({ item }: { item: ApiItem }) {
43
43
  const { siteConfig } = useDocusaurusContext();
44
44
  const themeConfig = siteConfig.themeConfig as ThemeConfig;
45
45
  const requestTimeout = themeConfig.api?.requestTimeout;
46
+ const requestCredentials = themeConfig.api?.requestCredentials;
46
47
  // Frontmatter proxy (per-spec) takes precedence over theme config proxy (site-wide)
47
48
  const proxy = frontMatterProxy ?? themeConfig.api?.proxy;
48
49
 
@@ -171,7 +172,8 @@ function Request({ item }: { item: ApiItem }) {
171
172
  postmanRequest,
172
173
  proxy,
173
174
  body,
174
- requestTimeout
175
+ requestTimeout,
176
+ requestCredentials
175
177
  );
176
178
  if (res.headers.get("content-type")?.includes("text/event-stream")) {
177
179
  await handleEventStream(res);
@@ -114,7 +114,8 @@ async function makeRequest(
114
114
  request: sdk.Request,
115
115
  proxy: string | undefined,
116
116
  _body: Body,
117
- timeout: number = DEFAULT_REQUEST_TIMEOUT
117
+ timeout: number = DEFAULT_REQUEST_TIMEOUT,
118
+ credentials?: RequestCredentials
118
119
  ) {
119
120
  const headers = request.toJSON().header;
120
121
 
@@ -252,6 +253,7 @@ async function makeRequest(
252
253
  method: request.method,
253
254
  headers: myHeaders,
254
255
  body: myBody,
256
+ ...(credentials && { credentials }),
255
257
  };
256
258
 
257
259
  let finalUrl = request.url.toString();
package/src/types.d.ts CHANGED
@@ -27,6 +27,13 @@ export interface ThemeConfig {
27
27
  authPersistence?: false | "sessionStorage" | "localStorage";
28
28
  /** Request timeout in milliseconds. Defaults to 30000 (30 seconds). */
29
29
  requestTimeout?: number;
30
+ /**
31
+ * Controls whether cookies and credentials are sent with API requests.
32
+ * - `"omit"`: Never send cookies (useful when docs are on same domain as app)
33
+ * - `"same-origin"`: Send cookies for same-origin requests (default browser behavior)
34
+ * - `"include"`: Always send cookies, even for cross-origin requests
35
+ */
36
+ requestCredentials?: "omit" | "same-origin" | "include";
30
37
  };
31
38
  }
32
39