docusaurus-theme-openapi-docs 0.0.0-1083 → 0.0.0-1085
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/Authorization/slice.js +3 -1
- package/lib/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.d.ts +7 -0
- package/lib/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.js +126 -0
- package/lib/theme/ApiExplorer/Body/FormBodyItem/index.d.ts +9 -0
- package/lib/theme/ApiExplorer/Body/FormBodyItem/index.js +110 -0
- package/lib/theme/ApiExplorer/Body/index.js +42 -97
- package/lib/theme/ApiExplorer/Body/slice.d.ts +27 -2
- package/lib/theme/ApiExplorer/Body/slice.js +22 -2
- package/lib/theme/ApiExplorer/LiveEditor/index.js +2 -3
- package/lib/theme/ApiExplorer/buildPostmanRequest.js +23 -7
- package/lib/theme/ApiExplorer/{persistanceMiddleware.d.ts → persistenceMiddleware.d.ts} +3 -3
- package/lib/theme/ApiExplorer/{persistanceMiddleware.js → persistenceMiddleware.js} +16 -9
- package/lib/theme/ApiExplorer/storage-utils.d.ts +2 -2
- package/lib/theme/ApiExplorer/storage-utils.js +3 -3
- package/lib/theme/ApiItem/index.js +12 -8
- package/lib/types.d.ts +7 -1
- package/package.json +3 -3
- package/src/theme/ApiExplorer/Authorization/slice.ts +1 -1
- package/src/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.tsx +77 -0
- package/src/theme/ApiExplorer/Body/FormBodyItem/index.tsx +120 -0
- package/src/theme/ApiExplorer/Body/index.tsx +39 -104
- package/src/theme/ApiExplorer/Body/slice.ts +40 -1
- package/src/theme/ApiExplorer/LiveEditor/index.tsx +2 -3
- package/src/theme/ApiExplorer/buildPostmanRequest.ts +23 -7
- package/src/theme/ApiExplorer/{persistanceMiddleware.ts → persistenceMiddleware.ts} +20 -12
- package/src/theme/ApiExplorer/storage-utils.ts +4 -4
- package/src/theme/ApiItem/index.tsx +12 -7
- package/src/types.ts +7 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -313,7 +313,11 @@ function setBody(clonedPostman: sdk.Request, body: Body) {
|
|
|
313
313
|
switch (clonedPostman.body.mode) {
|
|
314
314
|
case "raw": {
|
|
315
315
|
// check file even though it should already be set from above
|
|
316
|
-
if (
|
|
316
|
+
if (
|
|
317
|
+
body.type !== "raw" ||
|
|
318
|
+
body.content?.type === "file" ||
|
|
319
|
+
body.content?.type === "file[]"
|
|
320
|
+
) {
|
|
317
321
|
clonedPostman.body = undefined;
|
|
318
322
|
return;
|
|
319
323
|
}
|
|
@@ -328,15 +332,23 @@ function setBody(clonedPostman: sdk.Request, body: Body) {
|
|
|
328
332
|
clonedPostman.body.raw = `${body.content?.value}`;
|
|
329
333
|
return;
|
|
330
334
|
}
|
|
331
|
-
const params =
|
|
335
|
+
const params: sdk.FormParam[] = [];
|
|
336
|
+
Object.entries(body.content)
|
|
332
337
|
.filter((entry): entry is [string, NonNullable<Content>] => !!entry[1])
|
|
333
|
-
.
|
|
338
|
+
.forEach(([key, content]) => {
|
|
334
339
|
if (content.type === "file") {
|
|
335
|
-
|
|
340
|
+
params.push(new sdk.FormParam({ key: key, ...content }));
|
|
341
|
+
} else if (content.type === "file[]") {
|
|
342
|
+
content.value.forEach((file) =>
|
|
343
|
+
params.push(new sdk.FormParam({ key, value: file }))
|
|
344
|
+
);
|
|
345
|
+
} else {
|
|
346
|
+
params.push(new sdk.FormParam({ key: key, value: content.value }));
|
|
336
347
|
}
|
|
337
|
-
return new sdk.FormParam({ key: key, value: content.value });
|
|
338
348
|
});
|
|
339
|
-
|
|
349
|
+
params.forEach((param) => {
|
|
350
|
+
clonedPostman.body?.formdata?.add(param);
|
|
351
|
+
});
|
|
340
352
|
return;
|
|
341
353
|
}
|
|
342
354
|
case "urlencoded": {
|
|
@@ -350,7 +362,11 @@ function setBody(clonedPostman: sdk.Request, body: Body) {
|
|
|
350
362
|
const params = Object.entries(body.content)
|
|
351
363
|
.filter((entry): entry is [string, NonNullable<Content>] => !!entry[1])
|
|
352
364
|
.map(([key, content]) => {
|
|
353
|
-
if (
|
|
365
|
+
if (
|
|
366
|
+
content.type !== "file" &&
|
|
367
|
+
content.type !== "file[]" &&
|
|
368
|
+
content.value
|
|
369
|
+
) {
|
|
354
370
|
return new sdk.QueryParam({ key: key, value: content.value });
|
|
355
371
|
}
|
|
356
372
|
return undefined;
|
|
@@ -5,19 +5,19 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import { Middleware } from "@reduxjs/toolkit";
|
|
8
|
+
import type { Middleware } from "@reduxjs/toolkit";
|
|
9
9
|
import {
|
|
10
10
|
setAuthData,
|
|
11
11
|
setSelectedAuth,
|
|
12
12
|
} from "@theme/ApiExplorer/Authorization/slice";
|
|
13
|
-
import { AppDispatch, RootState } from "@theme/ApiItem/store";
|
|
14
|
-
|
|
15
|
-
import { ThemeConfig } from "docusaurus-theme-openapi-docs/src/types";
|
|
13
|
+
import type { AppDispatch, RootState } from "@theme/ApiItem/store";
|
|
14
|
+
import type { ServerObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
|
|
15
|
+
import type { ThemeConfig } from "docusaurus-theme-openapi-docs/src/types";
|
|
16
16
|
|
|
17
17
|
import { createStorage, hashArray } from "./storage-utils";
|
|
18
18
|
|
|
19
|
-
export function
|
|
20
|
-
const
|
|
19
|
+
export function createPersistenceMiddleware(options: ThemeConfig["api"]) {
|
|
20
|
+
const persistenceMiddleware: Middleware<{}, RootState, AppDispatch> =
|
|
21
21
|
(storeAPI) =>
|
|
22
22
|
(next) =>
|
|
23
23
|
(action: ReturnType<typeof setAuthData | typeof setSelectedAuth> | any) => {
|
|
@@ -25,7 +25,9 @@ export function createPersistanceMiddleware(options: ThemeConfig["api"]) {
|
|
|
25
25
|
|
|
26
26
|
const state = storeAPI.getState();
|
|
27
27
|
|
|
28
|
-
const storage = createStorage(
|
|
28
|
+
const storage = createStorage(
|
|
29
|
+
options?.authPersistence ?? "sessionStorage"
|
|
30
|
+
);
|
|
29
31
|
|
|
30
32
|
if (action.type === setAuthData.type) {
|
|
31
33
|
for (const [key, value] of Object.entries(state.auth.data)) {
|
|
@@ -60,14 +62,20 @@ export function createPersistanceMiddleware(options: ThemeConfig["api"]) {
|
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
if (action.type === "server/setServerVariable") {
|
|
63
|
-
const server = storage.getItem("server")
|
|
65
|
+
const server = storage.getItem("server");
|
|
66
|
+
if (!server) {
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
64
69
|
const variables = JSON.parse(action.payload);
|
|
65
|
-
|
|
66
|
-
serverObject
|
|
67
|
-
|
|
70
|
+
|
|
71
|
+
const serverObject = (JSON.parse(server) as ServerObject) ?? {};
|
|
72
|
+
if (serverObject.variables?.[variables.key]) {
|
|
73
|
+
serverObject.variables[variables.key].default = variables.value;
|
|
74
|
+
storage.setItem("server", JSON.stringify(serverObject));
|
|
75
|
+
}
|
|
68
76
|
}
|
|
69
77
|
|
|
70
78
|
return result;
|
|
71
79
|
};
|
|
72
|
-
return
|
|
80
|
+
return persistenceMiddleware;
|
|
73
81
|
}
|
|
@@ -17,10 +17,10 @@ export function hashArray(arr: string[]) {
|
|
|
17
17
|
return hash(res);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
type
|
|
20
|
+
type Persistence = false | "localStorage" | "sessionStorage" | undefined;
|
|
21
21
|
|
|
22
|
-
export function createStorage(
|
|
23
|
-
if (
|
|
22
|
+
export function createStorage(persistence: Persistence): Storage {
|
|
23
|
+
if (persistence === false) {
|
|
24
24
|
return {
|
|
25
25
|
getItem: () => null,
|
|
26
26
|
setItem: () => {},
|
|
@@ -31,7 +31,7 @@ export function createStorage(persistance: Persistance): Storage {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
if (
|
|
34
|
+
if (persistence === "sessionStorage") {
|
|
35
35
|
return sessionStorage;
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -14,7 +14,8 @@ import { HtmlClassNameProvider } from "@docusaurus/theme-common";
|
|
|
14
14
|
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
15
15
|
import useIsBrowser from "@docusaurus/useIsBrowser";
|
|
16
16
|
import { createAuth } from "@theme/ApiExplorer/Authorization/slice";
|
|
17
|
-
import {
|
|
17
|
+
import { createPersistenceMiddleware } from "@theme/ApiExplorer/persistenceMiddleware";
|
|
18
|
+
import { createStorage } from "@theme/ApiExplorer/storage-utils";
|
|
18
19
|
import DocItemLayout from "@theme/ApiItem/Layout";
|
|
19
20
|
import CodeBlock from "@theme/CodeBlock";
|
|
20
21
|
import type { Props } from "@theme/DocItem";
|
|
@@ -90,11 +91,11 @@ export default function ApiItem(props: Props): JSX.Element {
|
|
|
90
91
|
|
|
91
92
|
// Define store2
|
|
92
93
|
let store2: any = {};
|
|
93
|
-
const
|
|
94
|
+
const persistenceMiddleware = createPersistenceMiddleware(options);
|
|
94
95
|
|
|
95
96
|
// Init store for SSR
|
|
96
97
|
if (!isBrowser) {
|
|
97
|
-
store2 = createStoreWithoutState({}, [
|
|
98
|
+
store2 = createStoreWithoutState({}, [persistenceMiddleware]);
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
// Init store for CSR to hydrate components
|
|
@@ -129,11 +130,15 @@ export default function ApiItem(props: Props): JSX.Element {
|
|
|
129
130
|
securitySchemes: api?.securitySchemes,
|
|
130
131
|
options,
|
|
131
132
|
});
|
|
133
|
+
|
|
134
|
+
const storage = createStorage(options?.authPersistence ?? "sessionStorage");
|
|
132
135
|
// TODO: determine way to rehydrate without flashing
|
|
133
136
|
// const acceptValue = window?.sessionStorage.getItem("accept");
|
|
134
137
|
// const contentTypeValue = window?.sessionStorage.getItem("contentType");
|
|
135
|
-
const server =
|
|
136
|
-
const serverObject =
|
|
138
|
+
const server = storage.getItem("server");
|
|
139
|
+
const serverObject = server
|
|
140
|
+
? (JSON.parse(server) as ServerObject)
|
|
141
|
+
: undefined;
|
|
137
142
|
|
|
138
143
|
store2 = createStoreWithState(
|
|
139
144
|
{
|
|
@@ -146,7 +151,7 @@ export default function ApiItem(props: Props): JSX.Element {
|
|
|
146
151
|
options: contentTypeArray,
|
|
147
152
|
},
|
|
148
153
|
server: {
|
|
149
|
-
value: serverObject
|
|
154
|
+
value: serverObject?.url ? serverObject : undefined,
|
|
150
155
|
options: servers,
|
|
151
156
|
},
|
|
152
157
|
response: { value: undefined },
|
|
@@ -154,7 +159,7 @@ export default function ApiItem(props: Props): JSX.Element {
|
|
|
154
159
|
params,
|
|
155
160
|
auth,
|
|
156
161
|
},
|
|
157
|
-
[
|
|
162
|
+
[persistenceMiddleware]
|
|
158
163
|
);
|
|
159
164
|
}
|
|
160
165
|
|
package/src/types.ts
CHANGED
|
@@ -11,7 +11,13 @@ import type { JSONSchema4, JSONSchema6, JSONSchema7 } from "json-schema";
|
|
|
11
11
|
export interface ThemeConfig {
|
|
12
12
|
api?: {
|
|
13
13
|
proxy?: string;
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Controls how authentication credentials are persisted in the API explorer.
|
|
16
|
+
* - `false`: No persistence (in-memory only)
|
|
17
|
+
* - `"sessionStorage"`: Persist for the browser session (default)
|
|
18
|
+
* - `"localStorage"`: Persist across browser sessions
|
|
19
|
+
*/
|
|
20
|
+
authPersistence?: false | "sessionStorage" | "localStorage";
|
|
15
21
|
/** Request timeout in milliseconds. Defaults to 30000 (30 seconds). */
|
|
16
22
|
requestTimeout?: number;
|
|
17
23
|
};
|
package/tsconfig.tsbuildinfo
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/index.ts","./src/plugin-content-docs.d.ts","./src/postman-code-generators.d.ts","./src/react-magic-dropzone.d.ts","./src/theme-classic.d.ts","./src/theme-openapi.d.ts","./src/types.ts","./src/markdown/createDescription.ts","./src/markdown/schema.ts","./src/markdown/utils.test.ts","./src/markdown/utils.ts","./src/theme/translationIds.ts","./src/theme/ApiExplorer/buildPostmanRequest.ts","./src/theme/ApiExplorer/index.tsx","./src/theme/ApiExplorer/
|
|
1
|
+
{"root":["./src/index.ts","./src/plugin-content-docs.d.ts","./src/postman-code-generators.d.ts","./src/react-magic-dropzone.d.ts","./src/theme-classic.d.ts","./src/theme-openapi.d.ts","./src/types.ts","./src/markdown/createDescription.ts","./src/markdown/schema.ts","./src/markdown/utils.test.ts","./src/markdown/utils.ts","./src/theme/translationIds.ts","./src/theme/ApiExplorer/buildPostmanRequest.ts","./src/theme/ApiExplorer/index.tsx","./src/theme/ApiExplorer/persistenceMiddleware.ts","./src/theme/ApiExplorer/storage-utils.ts","./src/theme/ApiExplorer/Accept/index.tsx","./src/theme/ApiExplorer/Accept/slice.ts","./src/theme/ApiExplorer/ApiCodeBlock/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Container/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Content/Element.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Content/String.tsx","./src/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Line/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.tsx","./src/theme/ApiExplorer/Authorization/auth-types.ts","./src/theme/ApiExplorer/Authorization/index.tsx","./src/theme/ApiExplorer/Authorization/slice.ts","./src/theme/ApiExplorer/Body/index.tsx","./src/theme/ApiExplorer/Body/json2xml.d.ts","./src/theme/ApiExplorer/Body/slice.ts","./src/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.tsx","./src/theme/ApiExplorer/Body/FormBodyItem/index.tsx","./src/theme/ApiExplorer/CodeSnippets/code-snippets-types.ts","./src/theme/ApiExplorer/CodeSnippets/index.tsx","./src/theme/ApiExplorer/CodeSnippets/languages.ts","./src/theme/ApiExplorer/CodeTabs/index.tsx","./src/theme/ApiExplorer/ContentType/index.tsx","./src/theme/ApiExplorer/ContentType/slice.ts","./src/theme/ApiExplorer/Export/index.tsx","./src/theme/ApiExplorer/FloatingButton/index.tsx","./src/theme/ApiExplorer/FormFileUpload/index.tsx","./src/theme/ApiExplorer/FormItem/index.tsx","./src/theme/ApiExplorer/FormMultiSelect/index.tsx","./src/theme/ApiExplorer/FormSelect/index.tsx","./src/theme/ApiExplorer/FormTextInput/index.tsx","./src/theme/ApiExplorer/LiveEditor/index.tsx","./src/theme/ApiExplorer/MethodEndpoint/index.tsx","./src/theme/ApiExplorer/ParamOptions/index.tsx","./src/theme/ApiExplorer/ParamOptions/slice.ts","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.tsx","./src/theme/ApiExplorer/Request/index.tsx","./src/theme/ApiExplorer/Request/makeRequest.ts","./src/theme/ApiExplorer/Response/index.tsx","./src/theme/ApiExplorer/Response/slice.ts","./src/theme/ApiExplorer/SecuritySchemes/index.tsx","./src/theme/ApiExplorer/Server/index.tsx","./src/theme/ApiExplorer/Server/slice.ts","./src/theme/ApiItem/hooks.ts","./src/theme/ApiItem/index.tsx","./src/theme/ApiItem/store.ts","./src/theme/ApiItem/Layout/index.tsx","./src/theme/ApiLogo/index.tsx","./src/theme/ApiTabs/index.tsx","./src/theme/ArrayBrackets/index.tsx","./src/theme/CodeSamples/index.tsx","./src/theme/DiscriminatorTabs/index.tsx","./src/theme/Example/index.tsx","./src/theme/Markdown/index.d.ts","./src/theme/MimeTabs/index.tsx","./src/theme/OperationTabs/index.tsx","./src/theme/ParamsDetails/index.tsx","./src/theme/ParamsItem/index.tsx","./src/theme/RequestSchema/index.tsx","./src/theme/ResponseExamples/index.tsx","./src/theme/ResponseHeaders/index.tsx","./src/theme/ResponseSchema/index.tsx","./src/theme/Schema/index.tsx","./src/theme/SchemaItem/index.tsx","./src/theme/SchemaTabs/index.tsx","./src/theme/SkeletonLoader/index.tsx","./src/theme/StatusCodes/index.tsx"],"version":"5.8.3"}
|