docusaurus-theme-openapi-docs 0.0.0-733 → 0.0.0-735
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/CodeSnippets/index.js +13 -7
- package/lib/theme/ApiExplorer/CodeSnippets/languages.d.ts +1 -0
- package/lib/theme/ApiExplorer/CodeSnippets/languages.js +29 -2
- package/package.json +3 -3
- package/src/theme/ApiExplorer/CodeSnippets/index.tsx +22 -16
- package/src/theme/ApiExplorer/CodeSnippets/languages.ts +26 -4
|
@@ -56,6 +56,12 @@ var __importDefault =
|
|
|
56
56
|
};
|
|
57
57
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
58
|
exports.languageSet = void 0;
|
|
59
|
+
/* ============================================================================
|
|
60
|
+
* Copyright (c) Palo Alto Networks
|
|
61
|
+
*
|
|
62
|
+
* This source code is licensed under the MIT license found in the
|
|
63
|
+
* LICENSE file in the root directory of this source tree.
|
|
64
|
+
* ========================================================================== */
|
|
59
65
|
const react_1 = __importStar(require("react"));
|
|
60
66
|
const useDocusaurusContext_1 = __importDefault(
|
|
61
67
|
require("@docusaurus/useDocusaurusContext")
|
|
@@ -68,7 +74,6 @@ const buildPostmanRequest_1 = __importDefault(
|
|
|
68
74
|
);
|
|
69
75
|
const CodeTabs_1 = __importDefault(require("@theme/ApiExplorer/CodeTabs"));
|
|
70
76
|
const hooks_1 = require("@theme/ApiItem/hooks");
|
|
71
|
-
const merge_1 = __importDefault(require("lodash/merge"));
|
|
72
77
|
const postman_code_generators_1 = __importDefault(
|
|
73
78
|
require("postman-code-generators")
|
|
74
79
|
);
|
|
@@ -193,7 +198,6 @@ function CodeTab({ children, hidden, className }) {
|
|
|
193
198
|
);
|
|
194
199
|
}
|
|
195
200
|
function CodeSnippets({ postman, codeSamples }) {
|
|
196
|
-
// TODO: match theme for vscode.
|
|
197
201
|
const { siteConfig } = (0, useDocusaurusContext_1.default)();
|
|
198
202
|
const contentType = (0, hooks_1.useTypedSelector)(
|
|
199
203
|
(state) => state.contentType.value
|
|
@@ -216,20 +220,22 @@ function CodeSnippets({ postman, codeSamples }) {
|
|
|
216
220
|
const auth = (0, hooks_1.useTypedSelector)((state) => state.auth);
|
|
217
221
|
// User-defined languages array
|
|
218
222
|
// Can override languageSet, change order of langs, override options and variants
|
|
219
|
-
const
|
|
220
|
-
...(siteConfig?.themeConfig?.languageTabs ?? exports.languageSet),
|
|
221
|
-
];
|
|
223
|
+
const userDefinedLanguageSet = siteConfig?.themeConfig?.languageTabs;
|
|
222
224
|
// Filter languageSet by user-defined langs
|
|
223
225
|
const filteredLanguageSet = exports.languageSet.filter((ls) => {
|
|
224
|
-
return
|
|
226
|
+
return userDefinedLanguageSet?.some((lang) => {
|
|
225
227
|
return lang.language === ls.language;
|
|
226
228
|
});
|
|
227
229
|
});
|
|
228
230
|
// Merge user-defined langs into languageSet
|
|
229
231
|
const mergedLangs = (0, languages_1.mergeCodeSampleLanguage)(
|
|
230
|
-
(0,
|
|
232
|
+
(0, languages_1.mergeArraysbyLanguage)(
|
|
233
|
+
userDefinedLanguageSet,
|
|
234
|
+
filteredLanguageSet
|
|
235
|
+
),
|
|
231
236
|
codeSamples
|
|
232
237
|
);
|
|
238
|
+
console.log("merged", mergedLangs);
|
|
233
239
|
// Read defaultLang from localStorage
|
|
234
240
|
const defaultLang = mergedLangs.filter(
|
|
235
241
|
(lang) =>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { CodeSample, Language } from "./code-snippets-types";
|
|
2
2
|
export declare function mergeCodeSampleLanguage(languages: Language[], codeSamples: CodeSample[]): Language[];
|
|
3
|
+
export declare const mergeArraysbyLanguage: (arr1: any, arr2: any) => any[];
|
|
3
4
|
export declare function getCodeSampleSourceFromLanguage(language: Language): string;
|
|
@@ -5,9 +5,20 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
* ========================================================================== */
|
|
8
|
+
var __importDefault =
|
|
9
|
+
(this && this.__importDefault) ||
|
|
10
|
+
function (mod) {
|
|
11
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
12
|
+
};
|
|
8
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getCodeSampleSourceFromLanguage =
|
|
10
|
-
|
|
14
|
+
exports.getCodeSampleSourceFromLanguage =
|
|
15
|
+
exports.mergeArraysbyLanguage =
|
|
16
|
+
exports.mergeCodeSampleLanguage =
|
|
17
|
+
void 0;
|
|
18
|
+
const find_1 = __importDefault(require("lodash/find"));
|
|
19
|
+
const isArray_1 = __importDefault(require("lodash/isArray"));
|
|
20
|
+
const mergeWith_1 = __importDefault(require("lodash/mergeWith"));
|
|
21
|
+
const unionBy_1 = __importDefault(require("lodash/unionBy"));
|
|
11
22
|
function mergeCodeSampleLanguage(languages, codeSamples) {
|
|
12
23
|
return languages.map((language) => {
|
|
13
24
|
const languageCodeSamples = codeSamples.filter(
|
|
@@ -31,6 +42,22 @@ function mergeCodeSampleLanguage(languages, codeSamples) {
|
|
|
31
42
|
});
|
|
32
43
|
}
|
|
33
44
|
exports.mergeCodeSampleLanguage = mergeCodeSampleLanguage;
|
|
45
|
+
const mergeArraysbyLanguage = (arr1, arr2) => {
|
|
46
|
+
const mergedArray = (0, unionBy_1.default)(arr1, arr2, "language");
|
|
47
|
+
return mergedArray.map((item) => {
|
|
48
|
+
const matchingItems = [
|
|
49
|
+
(0, find_1.default)(arr1, ["language", item["language"]]),
|
|
50
|
+
(0, find_1.default)(arr2, ["language", item["language"]]),
|
|
51
|
+
];
|
|
52
|
+
return (0, mergeWith_1.default)({}, ...matchingItems, (objValue) => {
|
|
53
|
+
if ((0, isArray_1.default)(objValue)) {
|
|
54
|
+
return objValue;
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
exports.mergeArraysbyLanguage = mergeArraysbyLanguage;
|
|
34
61
|
function getCodeSampleSourceFromLanguage(language) {
|
|
35
62
|
if (
|
|
36
63
|
language &&
|
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-
|
|
4
|
+
"version": "0.0.0-735",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"clsx": "^1.1.1",
|
|
42
42
|
"copy-text-to-clipboard": "^3.1.0",
|
|
43
43
|
"crypto-js": "^4.1.1",
|
|
44
|
-
"docusaurus-plugin-openapi-docs": "0.0.0-
|
|
44
|
+
"docusaurus-plugin-openapi-docs": "0.0.0-735",
|
|
45
45
|
"docusaurus-plugin-sass": "^0.2.3",
|
|
46
46
|
"file-saver": "^2.0.5",
|
|
47
47
|
"lodash": "^4.17.20",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"engines": {
|
|
69
69
|
"node": ">=14"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "0aacbd3243e7d31d391ed5b15216f54b142c9fa2"
|
|
72
72
|
}
|
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
+
/* ============================================================================
|
|
9
|
+
* Copyright (c) Palo Alto Networks
|
|
10
|
+
*
|
|
11
|
+
* This source code is licensed under the MIT license found in the
|
|
12
|
+
* LICENSE file in the root directory of this source tree.
|
|
13
|
+
* ========================================================================== */
|
|
14
|
+
|
|
8
15
|
import React, { useState, useEffect } from "react";
|
|
9
16
|
|
|
10
17
|
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
@@ -12,13 +19,13 @@ import ApiCodeBlock from "@theme/ApiExplorer/ApiCodeBlock";
|
|
|
12
19
|
import buildPostmanRequest from "@theme/ApiExplorer/buildPostmanRequest";
|
|
13
20
|
import CodeTabs from "@theme/ApiExplorer/CodeTabs";
|
|
14
21
|
import { useTypedSelector } from "@theme/ApiItem/hooks";
|
|
15
|
-
import merge from "lodash/merge";
|
|
16
22
|
import codegen from "postman-code-generators";
|
|
17
23
|
import sdk from "postman-collection";
|
|
18
24
|
|
|
19
25
|
import { CodeSample, Language } from "./code-snippets-types";
|
|
20
26
|
import {
|
|
21
27
|
getCodeSampleSourceFromLanguage,
|
|
28
|
+
mergeArraysbyLanguage,
|
|
22
29
|
mergeCodeSampleLanguage,
|
|
23
30
|
} from "./languages";
|
|
24
31
|
|
|
@@ -149,8 +156,6 @@ function CodeTab({ children, hidden, className }: any): JSX.Element {
|
|
|
149
156
|
}
|
|
150
157
|
|
|
151
158
|
function CodeSnippets({ postman, codeSamples }: Props) {
|
|
152
|
-
// TODO: match theme for vscode.
|
|
153
|
-
|
|
154
159
|
const { siteConfig } = useDocusaurusContext();
|
|
155
160
|
|
|
156
161
|
const contentType = useTypedSelector((state: any) => state.contentType.value);
|
|
@@ -167,28 +172,29 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
167
172
|
|
|
168
173
|
// User-defined languages array
|
|
169
174
|
// Can override languageSet, change order of langs, override options and variants
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
];
|
|
175
|
+
const userDefinedLanguageSet = siteConfig?.themeConfig?.languageTabs as
|
|
176
|
+
| Language[]
|
|
177
|
+
| undefined;
|
|
174
178
|
|
|
175
179
|
// Filter languageSet by user-defined langs
|
|
176
180
|
const filteredLanguageSet = languageSet.filter((ls) => {
|
|
177
|
-
return
|
|
181
|
+
return userDefinedLanguageSet?.some((lang) => {
|
|
178
182
|
return lang.language === ls.language;
|
|
179
183
|
});
|
|
180
184
|
});
|
|
181
185
|
|
|
182
186
|
// Merge user-defined langs into languageSet
|
|
183
187
|
const mergedLangs = mergeCodeSampleLanguage(
|
|
184
|
-
|
|
185
|
-
codeSamples
|
|
188
|
+
mergeArraysbyLanguage(userDefinedLanguageSet, filteredLanguageSet),
|
|
189
|
+
codeSamples,
|
|
186
190
|
);
|
|
187
191
|
|
|
192
|
+
console.log("merged", mergedLangs);
|
|
193
|
+
|
|
188
194
|
// Read defaultLang from localStorage
|
|
189
195
|
const defaultLang: Language[] = mergedLangs.filter(
|
|
190
196
|
(lang) =>
|
|
191
|
-
lang.language === localStorage.getItem("docusaurus.tab.code-samples")
|
|
197
|
+
lang.language === localStorage.getItem("docusaurus.tab.code-samples"),
|
|
192
198
|
);
|
|
193
199
|
const [selectedVariant, setSelectedVariant] = useState<string | undefined>();
|
|
194
200
|
const [selectedSample, setSelectedSample] = useState<string | undefined>();
|
|
@@ -232,11 +238,11 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
232
238
|
return;
|
|
233
239
|
}
|
|
234
240
|
setCodeText(snippet);
|
|
235
|
-
}
|
|
241
|
+
},
|
|
236
242
|
);
|
|
237
243
|
} else if (language && !language.options) {
|
|
238
244
|
const langSource = mergedLangs.filter(
|
|
239
|
-
(lang) => lang.language === language.language
|
|
245
|
+
(lang) => lang.language === language.language,
|
|
240
246
|
);
|
|
241
247
|
|
|
242
248
|
// Merges user-defined language with default languageSet
|
|
@@ -265,7 +271,7 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
265
271
|
return;
|
|
266
272
|
}
|
|
267
273
|
setCodeText(snippet);
|
|
268
|
-
}
|
|
274
|
+
},
|
|
269
275
|
);
|
|
270
276
|
} else {
|
|
271
277
|
setCodeText("");
|
|
@@ -308,7 +314,7 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
308
314
|
return;
|
|
309
315
|
}
|
|
310
316
|
setCodeText(snippet);
|
|
311
|
-
}
|
|
317
|
+
},
|
|
312
318
|
);
|
|
313
319
|
}
|
|
314
320
|
});
|
|
@@ -323,7 +329,7 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
323
329
|
selectedSample !== language.sample
|
|
324
330
|
) {
|
|
325
331
|
const sampleIndex = language.samples.findIndex(
|
|
326
|
-
(smp) => smp === selectedSample
|
|
332
|
+
(smp) => smp === selectedSample,
|
|
327
333
|
);
|
|
328
334
|
setCodeSampleCodeText(language.samplesSources[sampleIndex]);
|
|
329
335
|
}
|
|
@@ -5,21 +5,26 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
+
import find from "lodash/find";
|
|
9
|
+
import isArray from "lodash/isArray";
|
|
10
|
+
import mergeWith from "lodash/mergeWith";
|
|
11
|
+
import unionBy from "lodash/unionBy";
|
|
12
|
+
|
|
8
13
|
import { CodeSample, Language } from "./code-snippets-types";
|
|
9
14
|
|
|
10
15
|
export function mergeCodeSampleLanguage(
|
|
11
16
|
languages: Language[],
|
|
12
|
-
codeSamples: CodeSample[]
|
|
17
|
+
codeSamples: CodeSample[],
|
|
13
18
|
): Language[] {
|
|
14
19
|
return languages.map((language) => {
|
|
15
20
|
const languageCodeSamples = codeSamples.filter(
|
|
16
|
-
({ lang }) => lang === language.codeSampleLanguage
|
|
21
|
+
({ lang }) => lang === language.codeSampleLanguage,
|
|
17
22
|
);
|
|
18
23
|
|
|
19
24
|
if (languageCodeSamples.length) {
|
|
20
25
|
const samples = languageCodeSamples.map(({ lang }) => lang);
|
|
21
26
|
const samplesLabels = languageCodeSamples.map(
|
|
22
|
-
({ label, lang }) => label || lang
|
|
27
|
+
({ label, lang }) => label || lang,
|
|
23
28
|
);
|
|
24
29
|
const samplesSources = languageCodeSamples.map(({ source }) => source);
|
|
25
30
|
|
|
@@ -36,6 +41,23 @@ export function mergeCodeSampleLanguage(
|
|
|
36
41
|
});
|
|
37
42
|
}
|
|
38
43
|
|
|
44
|
+
export const mergeArraysbyLanguage = (arr1: any, arr2: any) => {
|
|
45
|
+
const mergedArray = unionBy(arr1, arr2, "language");
|
|
46
|
+
|
|
47
|
+
return mergedArray.map((item: any) => {
|
|
48
|
+
const matchingItems = [
|
|
49
|
+
find(arr1, ["language", item["language"]]),
|
|
50
|
+
find(arr2, ["language", item["language"]]),
|
|
51
|
+
];
|
|
52
|
+
return mergeWith({}, ...matchingItems, (objValue: any) => {
|
|
53
|
+
if (isArray(objValue)) {
|
|
54
|
+
return objValue;
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
39
61
|
export function getCodeSampleSourceFromLanguage(language: Language) {
|
|
40
62
|
if (
|
|
41
63
|
language &&
|
|
@@ -44,7 +66,7 @@ export function getCodeSampleSourceFromLanguage(language: Language) {
|
|
|
44
66
|
language.samplesSources
|
|
45
67
|
) {
|
|
46
68
|
const sampleIndex = language.samples.findIndex(
|
|
47
|
-
(smp) => smp === language.sample
|
|
69
|
+
(smp) => smp === language.sample,
|
|
48
70
|
);
|
|
49
71
|
return language.samplesSources[sampleIndex];
|
|
50
72
|
}
|