docusaurus-theme-openapi-docs 0.0.0-1050 → 0.0.0-1054

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.
@@ -5,6 +5,7 @@ export declare const languageSet: Language[];
5
5
  export interface Props {
6
6
  postman: sdk.Request;
7
7
  codeSamples: CodeSample[];
8
+ maskCredentials?: boolean;
8
9
  }
9
- declare function CodeSnippets({ postman, codeSamples }: Props): React.JSX.Element | null;
10
+ declare function CodeSnippets({ postman, codeSamples, maskCredentials: propMaskCredentials, }: Props): React.JSX.Element | null;
10
11
  export default CodeSnippets;
@@ -93,7 +93,11 @@ function CodeTab({ children, hidden, className }) {
93
93
  children
94
94
  );
95
95
  }
96
- function CodeSnippets({ postman, codeSamples }) {
96
+ function CodeSnippets({
97
+ postman,
98
+ codeSamples,
99
+ maskCredentials: propMaskCredentials,
100
+ }) {
97
101
  const { siteConfig } = (0, useDocusaurusContext_1.default)();
98
102
  const contentType = (0, hooks_1.useTypedSelector)(
99
103
  (state) => state.contentType.value
@@ -114,29 +118,36 @@ function CodeSnippets({ postman, codeSamples }) {
114
118
  (state) => state.params.header
115
119
  );
116
120
  const auth = (0, hooks_1.useTypedSelector)((state) => state.auth);
117
- const clonedAuth = (0, cloneDeep_1.default)(auth);
118
- let placeholder;
119
- function cleanCredentials(obj) {
120
- for (const key in obj) {
121
- if (typeof obj[key] === "object" && obj[key] !== null) {
122
- // use name as placeholder if exists
123
- const comboAuthId = Object.keys(obj).join(" and ");
124
- const authOptions =
125
- clonedAuth?.options?.[key] ?? clonedAuth?.options?.[comboAuthId];
126
- placeholder = authOptions?.[0]?.name;
127
- obj[key] = cleanCredentials(obj[key]);
128
- } else {
129
- obj[key] = `<${placeholder ?? key}>`;
130
- }
131
- }
132
- return obj;
133
- }
134
- // scrub credentials from code snippets
135
- const cleanedAuth = {
136
- ...clonedAuth,
137
- data: cleanCredentials(clonedAuth.data),
138
- };
139
- // Create a Postman request object using cleanedAuth
121
+ // Check if credential masking is enabled (default: true)
122
+ const maskCredentials = propMaskCredentials ?? true;
123
+ // Clone Auth if maskCredentials is not false
124
+ const cleanedAuth = maskCredentials
125
+ ? (() => {
126
+ const clonedAuth = (0, cloneDeep_1.default)(auth);
127
+ let placeholder;
128
+ function cleanCredentials(obj) {
129
+ for (const key in obj) {
130
+ if (typeof obj[key] === "object" && obj[key] !== null) {
131
+ // use name as placeholder if exists
132
+ const comboAuthId = Object.keys(obj).join(" and ");
133
+ const authOptions =
134
+ clonedAuth?.options?.[key] ??
135
+ clonedAuth?.options?.[comboAuthId];
136
+ placeholder = authOptions?.[0]?.name;
137
+ obj[key] = cleanCredentials(obj[key]);
138
+ } else {
139
+ obj[key] = `<${placeholder ?? key}>`;
140
+ }
141
+ }
142
+ return obj;
143
+ }
144
+ return {
145
+ ...clonedAuth,
146
+ data: cleanCredentials(clonedAuth.data),
147
+ };
148
+ })()
149
+ : auth;
150
+ // Create a Postman request object using cleanedAuth or original auth
140
151
  const cleanedPostmanRequest = (0, buildPostmanRequest_1.default)(postman, {
141
152
  queryParams,
142
153
  pathParams,
@@ -68,6 +68,7 @@ var __importDefault =
68
68
  };
69
69
  Object.defineProperty(exports, "__esModule", { value: true });
70
70
  const react_1 = __importDefault(require("react"));
71
+ const client_1 = require("@docusaurus/plugin-content-docs/client");
71
72
  const CodeSnippets_1 = __importDefault(
72
73
  require("@theme/ApiExplorer/CodeSnippets")
73
74
  );
@@ -78,6 +79,8 @@ const SecuritySchemes_1 = __importDefault(
78
79
  );
79
80
  const sdk = __importStar(require("postman-collection"));
80
81
  function ApiExplorer({ item, infoPath }) {
82
+ const metadata = (0, client_1.useDoc)();
83
+ const { mask_credentials } = metadata.frontMatter;
81
84
  const postman = new sdk.Request(
82
85
  item.postman
83
86
  ? sdk.Request.isRequest(item.postman)
@@ -95,6 +98,7 @@ function ApiExplorer({ item, infoPath }) {
95
98
  react_1.default.createElement(CodeSnippets_1.default, {
96
99
  postman: postman,
97
100
  codeSamples: item["x-codeSamples"] ?? [],
101
+ maskCredentials: mask_credentials,
98
102
  }),
99
103
  react_1.default.createElement(Request_1.default, { item: item }),
100
104
  react_1.default.createElement(Response_1.default, { item: item })
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-1050",
4
+ "version": "0.0.0-1054",
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-1050",
41
+ "docusaurus-plugin-openapi-docs": "0.0.0-1054",
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": "33f10237ae33c3b720cc8003de8502d48cbdb2fb"
84
+ "gitHead": "0e1499ea1924c58ddb345c8674ce22b9b3ec0922"
85
85
  }
@@ -29,6 +29,7 @@ export const languageSet: Language[] = generateLanguageSet();
29
29
  export interface Props {
30
30
  postman: sdk.Request;
31
31
  codeSamples: CodeSample[];
32
+ maskCredentials?: boolean;
32
33
  }
33
34
 
34
35
  function CodeTab({ children, hidden, className }: any): React.JSX.Element {
@@ -39,7 +40,11 @@ function CodeTab({ children, hidden, className }: any): React.JSX.Element {
39
40
  );
40
41
  }
41
42
 
42
- function CodeSnippets({ postman, codeSamples }: Props) {
43
+ function CodeSnippets({
44
+ postman,
45
+ codeSamples,
46
+ maskCredentials: propMaskCredentials,
47
+ }: Props) {
43
48
  const { siteConfig } = useDocusaurusContext();
44
49
 
45
50
  const contentType = useTypedSelector((state: any) => state.contentType.value);
@@ -53,33 +58,42 @@ function CodeSnippets({ postman, codeSamples }: Props) {
53
58
  const headerParams = useTypedSelector((state: any) => state.params.header);
54
59
 
55
60
  const auth = useTypedSelector((state: any) => state.auth);
56
- const clonedAuth = cloneDeep(auth);
57
- let placeholder: string;
58
61
 
59
- function cleanCredentials(obj: any) {
60
- for (const key in obj) {
61
- if (typeof obj[key] === "object" && obj[key] !== null) {
62
- // use name as placeholder if exists
63
- const comboAuthId = Object.keys(obj).join(" and ");
64
- const authOptions =
65
- clonedAuth?.options?.[key] ?? clonedAuth?.options?.[comboAuthId];
66
- placeholder = authOptions?.[0]?.name;
67
- obj[key] = cleanCredentials(obj[key]);
68
- } else {
69
- obj[key] = `<${placeholder ?? key}>`;
70
- }
71
- }
62
+ // Check if credential masking is enabled (default: true)
63
+ const maskCredentials = propMaskCredentials ?? true;
72
64
 
73
- return obj;
74
- }
65
+ // Clone Auth if maskCredentials is not false
66
+ const cleanedAuth = maskCredentials
67
+ ? (() => {
68
+ const clonedAuth = cloneDeep(auth);
69
+ let placeholder: string;
70
+
71
+ function cleanCredentials(obj: any) {
72
+ for (const key in obj) {
73
+ if (typeof obj[key] === "object" && obj[key] !== null) {
74
+ // use name as placeholder if exists
75
+ const comboAuthId = Object.keys(obj).join(" and ");
76
+ const authOptions =
77
+ clonedAuth?.options?.[key] ??
78
+ clonedAuth?.options?.[comboAuthId];
79
+ placeholder = authOptions?.[0]?.name;
80
+ obj[key] = cleanCredentials(obj[key]);
81
+ } else {
82
+ obj[key] = `<${placeholder ?? key}>`;
83
+ }
84
+ }
85
+
86
+ return obj;
87
+ }
75
88
 
76
- // scrub credentials from code snippets
77
- const cleanedAuth = {
78
- ...clonedAuth,
79
- data: cleanCredentials(clonedAuth.data),
80
- };
89
+ return {
90
+ ...clonedAuth,
91
+ data: cleanCredentials(clonedAuth.data),
92
+ };
93
+ })()
94
+ : auth;
81
95
 
82
- // Create a Postman request object using cleanedAuth
96
+ // Create a Postman request object using cleanedAuth or original auth
83
97
  const cleanedPostmanRequest = buildPostmanRequest(postman, {
84
98
  queryParams,
85
99
  pathParams,
@@ -7,6 +7,7 @@
7
7
 
8
8
  import React from "react";
9
9
 
10
+ import { useDoc } from "@docusaurus/plugin-content-docs/client";
10
11
  import CodeSnippets from "@theme/ApiExplorer/CodeSnippets";
11
12
  import Request from "@theme/ApiExplorer/Request";
12
13
  import Response from "@theme/ApiExplorer/Response";
@@ -21,6 +22,9 @@ function ApiExplorer({
21
22
  item: NonNullable<ApiItem>;
22
23
  infoPath: string;
23
24
  }) {
25
+ const metadata = useDoc();
26
+ const { mask_credentials } = metadata.frontMatter;
27
+
24
28
  const postman = new sdk.Request(
25
29
  item.postman
26
30
  ? sdk.Request.isRequest(item.postman)
@@ -36,6 +40,7 @@ function ApiExplorer({
36
40
  <CodeSnippets
37
41
  postman={postman}
38
42
  codeSamples={(item as any)["x-codeSamples"] ?? []}
43
+ maskCredentials={mask_credentials}
39
44
  />
40
45
  )}
41
46
  <Request item={item} />