docusaurus-theme-openapi-docs 0.0.0-546 → 0.0.0-550

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.
@@ -12,6 +12,7 @@ var _CodeTabs = _interopRequireDefault(require("@theme/ApiDemoPanel/CodeTabs"));
12
12
  var _hooks = require("@theme/ApiItem/hooks");
13
13
  var _CodeBlock = _interopRequireDefault(require("@theme/CodeBlock"));
14
14
  var _clsx = _interopRequireDefault(require("clsx"));
15
+ var _merge = _interopRequireDefault(require("lodash/merge"));
15
16
  var _stylesModule = _interopRequireDefault(require("./styles.module.css"));
16
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
18
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -88,6 +89,15 @@ const languageSet = [{
88
89
  trimRequestBody: true
89
90
  },
90
91
  variant: "cURL"
92
+ }, {
93
+ highlight: "java",
94
+ language: "java",
95
+ logoClass: "java",
96
+ options: {
97
+ followRedirect: true,
98
+ trimRequestBody: true
99
+ },
100
+ variant: "OkHttp"
91
101
  }];
92
102
  exports.languageSet = languageSet;
93
103
  function CodeTab({
@@ -122,15 +132,30 @@ function Curl({
122
132
  const headerParams = (0, _hooks.useTypedSelector)(state => state.params.header);
123
133
  const auth = (0, _hooks.useTypedSelector)(state => state.auth);
124
134
 
125
- // TODO
135
+ // User-defined languages array
136
+ // Can override languageSet, change order of langs, override options and variants
126
137
  const langs = [...((_ref = siteConfig === null || siteConfig === void 0 ? void 0 : (_siteConfig$themeConf = siteConfig.themeConfig) === null || _siteConfig$themeConf === void 0 ? void 0 : _siteConfig$themeConf.languageTabs) !== null && _ref !== void 0 ? _ref : languageSet), ...codeSamples];
127
- const defaultLang = languageSet.filter(lang => lang.language === localStorage.getItem("docusaurus.tab.code-samples"));
138
+
139
+ // Filter languageSet by user-defined langs
140
+ const filteredLanguageSet = languageSet.filter(ls => {
141
+ return langs.some(lang => {
142
+ return lang.language === ls.language;
143
+ });
144
+ });
145
+
146
+ // Merge user-defined langs into languageSet
147
+ const mergedLangs = (0, _merge.default)(filteredLanguageSet, langs);
148
+
149
+ // Read defaultLang from localStorage
150
+ const defaultLang = mergedLangs.filter(lang => lang.language === localStorage.getItem("docusaurus.tab.code-samples"));
128
151
  const [language, setLanguage] = (0, _react.useState)(() => {
129
152
  var _defaultLang$;
130
- if (langs.length === 1) {
131
- return langs[0];
153
+ // Return first index if only 1 user-defined language exists
154
+ if (mergedLangs.length === 1) {
155
+ return mergedLangs[0];
132
156
  }
133
- return (_defaultLang$ = defaultLang[0]) !== null && _defaultLang$ !== void 0 ? _defaultLang$ : langs[0];
157
+ // Fall back to language in localStorage or first user-defined language
158
+ return (_defaultLang$ = defaultLang[0]) !== null && _defaultLang$ !== void 0 ? _defaultLang$ : mergedLangs[0];
134
159
  });
135
160
  const [codeText, setCodeText] = (0, _react.useState)("");
136
161
  (0, _react.useEffect)(() => {
@@ -155,7 +180,7 @@ function Curl({
155
180
  } else if (language && !!language.source) {
156
181
  setCodeText(language.source);
157
182
  } else if (language && !language.options) {
158
- const langSource = languageSet.filter(lang => lang.language === language.language);
183
+ const langSource = mergedLangs.filter(lang => lang.language === language.language);
159
184
 
160
185
  // Merges user-defined language with default languageSet
161
186
  // This allows users to define only the minimal properties necessary in languageTabs
@@ -184,13 +209,13 @@ function Curl({
184
209
  } else {
185
210
  setCodeText("");
186
211
  }
187
- }, [accept, body, contentType, cookieParams, headerParams, language, pathParams, postman, queryParams, server, auth]);
212
+ }, [accept, body, contentType, cookieParams, headerParams, language, pathParams, postman, queryParams, server, auth, mergedLangs]);
188
213
  if (language === undefined) {
189
214
  return null;
190
215
  }
191
216
  return <>
192
217
  <_CodeTabs.default groupId="code-samples" action={setLanguage}>
193
- {langs.map(lang => {
218
+ {mergedLangs.map(lang => {
194
219
  return <CodeTab value={lang.language} label={""} key={lang.variant ? `${lang.language}-${lang.variant}` : lang.language} attributes={{
195
220
  className: `code__tab--${lang.logoClass}`
196
221
  }}>
@@ -8,6 +8,8 @@
8
8
  import React from "react";
9
9
 
10
10
  import CodeBlock from "@theme/CodeBlock";
11
+ import SchemaTabs from "@theme/SchemaTabs";
12
+ import TabItem from "@theme/TabItem";
11
13
  /* eslint-disable import/no-extraneous-dependencies*/
12
14
  import { createDescription } from "docusaurus-theme-openapi-docs/lib/markdown/createDescription";
13
15
  /* eslint-disable import/no-extraneous-dependencies*/
@@ -77,16 +79,34 @@ function ParamsItem({
77
79
  );
78
80
 
79
81
  const renderExample = guard(example, (example) => (
80
- <div>{`Example: ${example}`}</div>
82
+ <>
83
+ <strong>Example: </strong>
84
+ {example}
85
+ </>
81
86
  ));
82
87
 
83
88
  const renderExamples = guard(examples, (examples) => {
84
89
  const exampleEntries = Object.entries(examples);
85
90
  return (
86
91
  <>
87
- {exampleEntries.map(([k, v]) => (
88
- <div>{`Example (${k}): ${v.value}`}</div>
89
- ))}
92
+ <strong>Examples:</strong>
93
+ <SchemaTabs>
94
+ {exampleEntries.map(([exampleName, exampleProperties]) => (
95
+ <TabItem value={exampleName} label={exampleName}>
96
+ {exampleProperties.summary && <p>{exampleProperties.summary}</p>}
97
+ {exampleProperties.description && (
98
+ <p>
99
+ <strong>Description: </strong>
100
+ <span>{exampleProperties.description}</span>
101
+ </p>
102
+ )}
103
+ <p>
104
+ <strong>Example: </strong>
105
+ <code>{exampleProperties.value}</code>
106
+ </p>
107
+ </TabItem>
108
+ ))}
109
+ </SchemaTabs>
90
110
  </>
91
111
  );
92
112
  });
@@ -445,7 +445,33 @@
445
445
  overflow: auto;
446
446
  }
447
447
 
448
+ .code__tab--java::after {
449
+ content: "";
450
+ width: 28px;
451
+ height: 28px;
452
+ background: url("https://raw.githubusercontent.com/devicons/devicon/master/icons/java/java-original.svg");
453
+ margin-block: auto;
454
+ }
455
+
456
+ .code__tab--java {
457
+ color: var(--ifm-color-warning);
458
+ padding-left: 1.4rem;
459
+ padding-right: 1.4rem;
460
+ padding-top: 1rem !important;
461
+ padding-bottom: 1rem !important;
462
+ }
463
+
464
+ .code__tab--java.tabs__item--active {
465
+ border-bottom-color: var(--ifm-color-warning);
466
+ background-color: var(--ifm-color-emphasis-100);
467
+ }
468
+
469
+ .language-java {
470
+ max-height: 500px;
471
+ overflow: auto;
472
+ }
473
+
448
474
  /* Prism code styles */
449
- .prism-code.language-json {
475
+ .prism-code.language-java {
450
476
  white-space: pre !important;
451
477
  }
@@ -13,6 +13,7 @@ import CodeTabs from "@theme/ApiDemoPanel/CodeTabs";
13
13
  import { useTypedSelector } from "@theme/ApiItem/hooks";
14
14
  import CodeBlock from "@theme/CodeBlock";
15
15
  import clsx from "clsx";
16
+ import merge from "lodash/merge";
16
17
  import styles from "./styles.module.css";
17
18
  export const languageSet = [
18
19
  {
@@ -87,6 +88,16 @@ export const languageSet = [
87
88
  },
88
89
  variant: "cURL",
89
90
  },
91
+ {
92
+ highlight: "java",
93
+ language: "java",
94
+ logoClass: "java",
95
+ options: {
96
+ followRedirect: true,
97
+ trimRequestBody: true,
98
+ },
99
+ variant: "OkHttp",
100
+ },
90
101
  ];
91
102
  function CodeTab({ children, hidden, className, onClick }) {
92
103
  return (
@@ -115,20 +126,35 @@ function Curl({ postman, codeSamples }) {
115
126
  const headerParams = useTypedSelector((state) => state.params.header);
116
127
  const auth = useTypedSelector((state) => state.auth);
117
128
 
118
- // TODO
129
+ // User-defined languages array
130
+ // Can override languageSet, change order of langs, override options and variants
119
131
  const langs = [
120
132
  ...(siteConfig?.themeConfig?.languageTabs ?? languageSet),
121
133
  ...codeSamples,
122
134
  ];
123
- const defaultLang = languageSet.filter(
135
+
136
+ // Filter languageSet by user-defined langs
137
+ const filteredLanguageSet = languageSet.filter((ls) => {
138
+ return langs.some((lang) => {
139
+ return lang.language === ls.language;
140
+ });
141
+ });
142
+
143
+ // Merge user-defined langs into languageSet
144
+ const mergedLangs = merge(filteredLanguageSet, langs);
145
+
146
+ // Read defaultLang from localStorage
147
+ const defaultLang = mergedLangs.filter(
124
148
  (lang) =>
125
149
  lang.language === localStorage.getItem("docusaurus.tab.code-samples")
126
150
  );
127
151
  const [language, setLanguage] = useState(() => {
128
- if (langs.length === 1) {
129
- return langs[0];
152
+ // Return first index if only 1 user-defined language exists
153
+ if (mergedLangs.length === 1) {
154
+ return mergedLangs[0];
130
155
  }
131
- return defaultLang[0] ?? langs[0];
156
+ // Fall back to language in localStorage or first user-defined language
157
+ return defaultLang[0] ?? mergedLangs[0];
132
158
  });
133
159
  const [codeText, setCodeText] = useState("");
134
160
  useEffect(() => {
@@ -159,7 +185,7 @@ function Curl({ postman, codeSamples }) {
159
185
  } else if (language && !!language.source) {
160
186
  setCodeText(language.source);
161
187
  } else if (language && !language.options) {
162
- const langSource = languageSet.filter(
188
+ const langSource = mergedLangs.filter(
163
189
  (lang) => lang.language === language.language
164
190
  );
165
191
 
@@ -208,6 +234,7 @@ function Curl({ postman, codeSamples }) {
208
234
  queryParams,
209
235
  server,
210
236
  auth,
237
+ mergedLangs,
211
238
  ]);
212
239
  if (language === undefined) {
213
240
  return null;
@@ -215,7 +242,7 @@ function Curl({ postman, codeSamples }) {
215
242
  return (
216
243
  <>
217
244
  <CodeTabs groupId="code-samples" action={setLanguage}>
218
- {langs.map((lang) => {
245
+ {mergedLangs.map((lang) => {
219
246
  return (
220
247
  <CodeTab
221
248
  value={lang.language}
@@ -8,6 +8,8 @@
8
8
  import React from "react";
9
9
 
10
10
  import CodeBlock from "@theme/CodeBlock";
11
+ import SchemaTabs from "@theme/SchemaTabs";
12
+ import TabItem from "@theme/TabItem";
11
13
  /* eslint-disable import/no-extraneous-dependencies*/
12
14
  import { createDescription } from "docusaurus-theme-openapi-docs/lib/markdown/createDescription";
13
15
  /* eslint-disable import/no-extraneous-dependencies*/
@@ -77,16 +79,34 @@ function ParamsItem({
77
79
  );
78
80
 
79
81
  const renderExample = guard(example, (example) => (
80
- <div>{`Example: ${example}`}</div>
82
+ <>
83
+ <strong>Example: </strong>
84
+ {example}
85
+ </>
81
86
  ));
82
87
 
83
88
  const renderExamples = guard(examples, (examples) => {
84
89
  const exampleEntries = Object.entries(examples);
85
90
  return (
86
91
  <>
87
- {exampleEntries.map(([k, v]) => (
88
- <div>{`Example (${k}): ${v.value}`}</div>
89
- ))}
92
+ <strong>Examples:</strong>
93
+ <SchemaTabs>
94
+ {exampleEntries.map(([exampleName, exampleProperties]) => (
95
+ <TabItem value={exampleName} label={exampleName}>
96
+ {exampleProperties.summary && <p>{exampleProperties.summary}</p>}
97
+ {exampleProperties.description && (
98
+ <p>
99
+ <strong>Description: </strong>
100
+ <span>{exampleProperties.description}</span>
101
+ </p>
102
+ )}
103
+ <p>
104
+ <strong>Example: </strong>
105
+ <code>{exampleProperties.value}</code>
106
+ </p>
107
+ </TabItem>
108
+ ))}
109
+ </SchemaTabs>
90
110
  </>
91
111
  );
92
112
  });
@@ -445,7 +445,33 @@
445
445
  overflow: auto;
446
446
  }
447
447
 
448
+ .code__tab--java::after {
449
+ content: "";
450
+ width: 28px;
451
+ height: 28px;
452
+ background: url("https://raw.githubusercontent.com/devicons/devicon/master/icons/java/java-original.svg");
453
+ margin-block: auto;
454
+ }
455
+
456
+ .code__tab--java {
457
+ color: var(--ifm-color-warning);
458
+ padding-left: 1.4rem;
459
+ padding-right: 1.4rem;
460
+ padding-top: 1rem !important;
461
+ padding-bottom: 1rem !important;
462
+ }
463
+
464
+ .code__tab--java.tabs__item--active {
465
+ border-bottom-color: var(--ifm-color-warning);
466
+ background-color: var(--ifm-color-emphasis-100);
467
+ }
468
+
469
+ .language-java {
470
+ max-height: 500px;
471
+ overflow: auto;
472
+ }
473
+
448
474
  /* Prism code styles */
449
- .prism-code.language-json {
475
+ .prism-code.language-java {
450
476
  white-space: pre !important;
451
477
  }
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-546",
4
+ "version": "0.0.0-550",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -45,13 +45,13 @@
45
45
  "dependencies": {
46
46
  "@docusaurus/theme-common": "^2.0.1",
47
47
  "@mdx-js/react": "^1.6.21",
48
- "@paloaltonetworks/postman-code-generators": "^1.1.12",
48
+ "@paloaltonetworks/postman-code-generators": "^1.1.15",
49
49
  "@paloaltonetworks/postman-collection": "^4.1.0",
50
50
  "@reduxjs/toolkit": "^1.7.1",
51
51
  "buffer": "^6.0.3",
52
52
  "clsx": "^1.1.1",
53
53
  "crypto-js": "^4.1.1",
54
- "docusaurus-plugin-openapi-docs": "0.0.0-546",
54
+ "docusaurus-plugin-openapi-docs": "^1.5.2",
55
55
  "file-saver": "^2.0.5",
56
56
  "immer": "^9.0.7",
57
57
  "lodash": "^4.17.20",
@@ -73,5 +73,5 @@
73
73
  "engines": {
74
74
  "node": ">=14"
75
75
  },
76
- "gitHead": "046657762bb71c14e7b629e94cbfb1cf1443ddae"
76
+ "gitHead": "a5a66956330a8dad1705e3f9e281b5ecc6c3c42f"
77
77
  }
@@ -15,6 +15,7 @@ import CodeTabs from "@theme/ApiDemoPanel/CodeTabs";
15
15
  import { useTypedSelector } from "@theme/ApiItem/hooks";
16
16
  import CodeBlock from "@theme/CodeBlock";
17
17
  import clsx from "clsx";
18
+ import merge from "lodash/merge";
18
19
 
19
20
  import styles from "./styles.module.css";
20
21
 
@@ -100,6 +101,16 @@ export const languageSet: Language[] = [
100
101
  },
101
102
  variant: "cURL",
102
103
  },
104
+ {
105
+ highlight: "java",
106
+ language: "java",
107
+ logoClass: "java",
108
+ options: {
109
+ followRedirect: true,
110
+ trimRequestBody: true,
111
+ },
112
+ variant: "OkHttp",
113
+ },
103
114
  ];
104
115
 
105
116
  export interface Props {
@@ -136,23 +147,37 @@ function Curl({ postman, codeSamples }: Props) {
136
147
 
137
148
  const auth = useTypedSelector((state: any) => state.auth);
138
149
 
139
- // TODO
150
+ // User-defined languages array
151
+ // Can override languageSet, change order of langs, override options and variants
140
152
  const langs = [
141
153
  ...((siteConfig?.themeConfig?.languageTabs as Language[] | undefined) ??
142
154
  languageSet),
143
155
  ...codeSamples,
144
156
  ];
145
157
 
146
- const defaultLang: Language[] = languageSet.filter(
158
+ // Filter languageSet by user-defined langs
159
+ const filteredLanguageSet = languageSet.filter((ls) => {
160
+ return langs.some((lang) => {
161
+ return lang.language === ls.language;
162
+ });
163
+ });
164
+
165
+ // Merge user-defined langs into languageSet
166
+ const mergedLangs = merge(filteredLanguageSet, langs);
167
+
168
+ // Read defaultLang from localStorage
169
+ const defaultLang: Language[] = mergedLangs.filter(
147
170
  (lang) =>
148
171
  lang.language === localStorage.getItem("docusaurus.tab.code-samples")
149
172
  );
150
173
 
151
174
  const [language, setLanguage] = useState(() => {
152
- if (langs.length === 1) {
153
- return langs[0];
175
+ // Return first index if only 1 user-defined language exists
176
+ if (mergedLangs.length === 1) {
177
+ return mergedLangs[0];
154
178
  }
155
- return defaultLang[0] ?? langs[0];
179
+ // Fall back to language in localStorage or first user-defined language
180
+ return defaultLang[0] ?? mergedLangs[0];
156
181
  });
157
182
 
158
183
  const [codeText, setCodeText] = useState("");
@@ -186,7 +211,7 @@ function Curl({ postman, codeSamples }: Props) {
186
211
  } else if (language && !!language.source) {
187
212
  setCodeText(language.source);
188
213
  } else if (language && !language.options) {
189
- const langSource = languageSet.filter(
214
+ const langSource = mergedLangs.filter(
190
215
  (lang) => lang.language === language.language
191
216
  );
192
217
 
@@ -233,6 +258,7 @@ function Curl({ postman, codeSamples }: Props) {
233
258
  queryParams,
234
259
  server,
235
260
  auth,
261
+ mergedLangs,
236
262
  ]);
237
263
 
238
264
  if (language === undefined) {
@@ -242,7 +268,7 @@ function Curl({ postman, codeSamples }: Props) {
242
268
  return (
243
269
  <>
244
270
  <CodeTabs groupId="code-samples" action={setLanguage}>
245
- {langs.map((lang) => {
271
+ {mergedLangs.map((lang) => {
246
272
  return (
247
273
  <CodeTab
248
274
  value={lang.language}
@@ -8,6 +8,8 @@
8
8
  import React from "react";
9
9
 
10
10
  import CodeBlock from "@theme/CodeBlock";
11
+ import SchemaTabs from "@theme/SchemaTabs";
12
+ import TabItem from "@theme/TabItem";
11
13
  /* eslint-disable import/no-extraneous-dependencies*/
12
14
  import { createDescription } from "docusaurus-theme-openapi-docs/lib/markdown/createDescription";
13
15
  /* eslint-disable import/no-extraneous-dependencies*/
@@ -77,16 +79,34 @@ function ParamsItem({
77
79
  );
78
80
 
79
81
  const renderExample = guard(example, (example) => (
80
- <div>{`Example: ${example}`}</div>
82
+ <>
83
+ <strong>Example: </strong>
84
+ {example}
85
+ </>
81
86
  ));
82
87
 
83
88
  const renderExamples = guard(examples, (examples) => {
84
89
  const exampleEntries = Object.entries(examples);
85
90
  return (
86
91
  <>
87
- {exampleEntries.map(([k, v]) => (
88
- <div>{`Example (${k}): ${v.value}`}</div>
89
- ))}
92
+ <strong>Examples:</strong>
93
+ <SchemaTabs>
94
+ {exampleEntries.map(([exampleName, exampleProperties]) => (
95
+ <TabItem value={exampleName} label={exampleName}>
96
+ {exampleProperties.summary && <p>{exampleProperties.summary}</p>}
97
+ {exampleProperties.description && (
98
+ <p>
99
+ <strong>Description: </strong>
100
+ <span>{exampleProperties.description}</span>
101
+ </p>
102
+ )}
103
+ <p>
104
+ <strong>Example: </strong>
105
+ <code>{exampleProperties.value}</code>
106
+ </p>
107
+ </TabItem>
108
+ ))}
109
+ </SchemaTabs>
90
110
  </>
91
111
  );
92
112
  });
@@ -445,7 +445,33 @@
445
445
  overflow: auto;
446
446
  }
447
447
 
448
+ .code__tab--java::after {
449
+ content: "";
450
+ width: 28px;
451
+ height: 28px;
452
+ background: url("https://raw.githubusercontent.com/devicons/devicon/master/icons/java/java-original.svg");
453
+ margin-block: auto;
454
+ }
455
+
456
+ .code__tab--java {
457
+ color: var(--ifm-color-warning);
458
+ padding-left: 1.4rem;
459
+ padding-right: 1.4rem;
460
+ padding-top: 1rem !important;
461
+ padding-bottom: 1rem !important;
462
+ }
463
+
464
+ .code__tab--java.tabs__item--active {
465
+ border-bottom-color: var(--ifm-color-warning);
466
+ background-color: var(--ifm-color-emphasis-100);
467
+ }
468
+
469
+ .language-java {
470
+ max-height: 500px;
471
+ overflow: auto;
472
+ }
473
+
448
474
  /* Prism code styles */
449
- .prism-code.language-json {
475
+ .prism-code.language-java {
450
476
  white-space: pre !important;
451
477
  }