docusaurus-theme-openapi-docs 4.0.0 → 4.1.0

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.
Files changed (39) hide show
  1. package/lib/markdown/utils.d.ts +5 -4
  2. package/lib/theme/ApiExplorer/CodeSnippets/code-snippets-types.d.ts +1 -1
  3. package/lib/theme/ApiExplorer/CodeSnippets/index.js +2 -112
  4. package/lib/theme/ApiExplorer/CodeSnippets/languages.d.ts +1 -0
  5. package/lib/theme/ApiExplorer/CodeSnippets/languages.js +30 -6
  6. package/lib/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +146 -2
  7. package/lib/theme/ApiExplorer/CodeTabs/index.js +34 -8
  8. package/lib/theme/ApiExplorer/MethodEndpoint/index.d.ts +2 -1
  9. package/lib/theme/ApiExplorer/MethodEndpoint/index.js +5 -2
  10. package/lib/theme/ApiExplorer/ParamOptions/index.js +1 -0
  11. package/lib/theme/ApiExplorer/Request/_Request.scss +5 -0
  12. package/lib/theme/ApiExplorer/index.js +6 -0
  13. package/lib/theme/ApiItem/Layout/index.d.ts +3 -0
  14. package/lib/theme/ApiItem/Layout/index.js +117 -0
  15. package/lib/theme/ApiItem/Layout/styles.module.css +17 -0
  16. package/lib/theme/ApiItem/index.js +1 -1
  17. package/lib/theme/ParamsItem/index.d.ts +2 -1
  18. package/lib/theme/ParamsItem/index.js +74 -17
  19. package/lib/theme/SchemaItem/index.d.ts +1 -1
  20. package/lib/theme/SchemaItem/index.js +106 -20
  21. package/package.json +6 -5
  22. package/src/markdown/utils.ts +7 -6
  23. package/src/plugin-content-docs.d.ts +2 -0
  24. package/src/theme/ApiExplorer/CodeSnippets/code-snippets-types.ts +2 -0
  25. package/src/theme/ApiExplorer/CodeSnippets/index.tsx +6 -112
  26. package/src/theme/ApiExplorer/CodeSnippets/languages.ts +26 -5
  27. package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +146 -2
  28. package/src/theme/ApiExplorer/CodeTabs/index.tsx +40 -9
  29. package/src/theme/ApiExplorer/MethodEndpoint/index.tsx +7 -3
  30. package/src/theme/ApiExplorer/ParamOptions/index.tsx +1 -0
  31. package/src/theme/ApiExplorer/Request/_Request.scss +5 -0
  32. package/src/theme/ApiExplorer/index.tsx +2 -0
  33. package/src/theme/ApiItem/Layout/index.tsx +82 -0
  34. package/src/theme/ApiItem/Layout/styles.module.css +17 -0
  35. package/src/theme/ApiItem/index.tsx +1 -1
  36. package/src/theme/ParamsItem/index.tsx +75 -15
  37. package/src/theme/SchemaItem/index.tsx +106 -17
  38. package/src/theme-classic.d.ts +0 -2
  39. package/src/theme-openapi.d.ts +4 -0
@@ -0,0 +1,17 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+
8
+ .docItemContainer header + *,
9
+ .docItemContainer article > *:first-child {
10
+ margin-top: 0;
11
+ }
12
+
13
+ @media (min-width: 997px) {
14
+ .docItemCol {
15
+ max-width: 75% !important;
16
+ }
17
+ }
@@ -25,7 +25,7 @@ const useDocusaurusContext_1 = __importDefault(
25
25
  const useIsBrowser_1 = __importDefault(require("@docusaurus/useIsBrowser"));
26
26
  const slice_1 = require("@theme/ApiExplorer/Authorization/slice");
27
27
  const persistanceMiddleware_1 = require("@theme/ApiExplorer/persistanceMiddleware");
28
- const Layout_1 = __importDefault(require("@theme/DocItem/Layout"));
28
+ const Layout_1 = __importDefault(require("@theme/ApiItem/Layout"));
29
29
  const Metadata_1 = __importDefault(require("@theme/DocItem/Metadata"));
30
30
  const clsx_1 = __importDefault(require("clsx"));
31
31
  const react_redux_1 = require("react-redux");
@@ -17,7 +17,8 @@ export interface Props {
17
17
  required: boolean;
18
18
  deprecated: boolean;
19
19
  schema: any;
20
+ enumDescriptions?: [string, string][];
20
21
  };
21
22
  }
22
- declare function ParamsItem({ param: { description, example, examples, name, required, schema, deprecated }, }: Props): React.JSX.Element;
23
+ declare function ParamsItem({ param, ...rest }: Props): React.JSX.Element;
23
24
  export default ParamsItem;
@@ -19,15 +19,45 @@ const TabItem_1 = __importDefault(require("@theme/TabItem"));
19
19
  const clsx_1 = __importDefault(require("clsx"));
20
20
  const react_markdown_1 = __importDefault(require("react-markdown"));
21
21
  const rehype_raw_1 = __importDefault(require("rehype-raw"));
22
+ const remark_gfm_1 = __importDefault(require("remark-gfm"));
22
23
  const createDescription_1 = require("../../markdown/createDescription");
23
24
  const schema_1 = require("../../markdown/schema");
24
25
  const utils_1 = require("../../markdown/utils");
25
- function ParamsItem({
26
- param: { description, example, examples, name, required, schema, deprecated },
27
- }) {
26
+ const getEnumDescriptionMarkdown = (enumDescriptions) => {
27
+ if (enumDescriptions?.length) {
28
+ return `| Enum Value | Description |
29
+ | ---- | ----- |
30
+ ${enumDescriptions
31
+ .map((desc) => {
32
+ return `| ${desc[0]} | ${desc[1]} | `.replaceAll("\n", "<br/>");
33
+ })
34
+ .join("\n")}
35
+ `;
36
+ }
37
+ return "";
38
+ };
39
+ function ParamsItem({ param, ...rest }) {
40
+ const {
41
+ description,
42
+ example,
43
+ examples,
44
+ name,
45
+ required,
46
+ deprecated,
47
+ enumDescriptions,
48
+ } = param;
49
+ let schema = param.schema;
50
+ let defaultValue;
28
51
  if (!schema || !schema?.type) {
29
52
  schema = { type: "any" };
30
53
  }
54
+ if (schema) {
55
+ if (schema.items) {
56
+ defaultValue = schema.items.default;
57
+ } else {
58
+ defaultValue = schema.default;
59
+ }
60
+ }
31
61
  const renderSchemaName = (0, utils_1.guard)(schema, (schema) =>
32
62
  react_1.default.createElement(
33
63
  "span",
@@ -91,21 +121,47 @@ function ParamsItem({
91
121
  })
92
122
  )
93
123
  );
94
- const renderDefaultValue = (0, utils_1.guard)(
95
- schema && schema.items
96
- ? schema.items.default
97
- : schema
98
- ? schema.default
99
- : undefined,
100
- (value) =>
101
- react_1.default.createElement(
124
+ const renderEnumDescriptions = (0, utils_1.guard)(
125
+ getEnumDescriptionMarkdown(enumDescriptions),
126
+ (value) => {
127
+ return react_1.default.createElement(react_markdown_1.default, {
128
+ rehypePlugins: [rehype_raw_1.default],
129
+ remarkPlugins: [remark_gfm_1.default],
130
+ children: value,
131
+ });
132
+ }
133
+ );
134
+ function renderDefaultValue() {
135
+ if (defaultValue !== undefined) {
136
+ if (typeof defaultValue === "string") {
137
+ return react_1.default.createElement(
138
+ "div",
139
+ null,
140
+ react_1.default.createElement("strong", null, "Default value: "),
141
+ react_1.default.createElement(
142
+ "span",
143
+ null,
144
+ react_1.default.createElement("code", null, defaultValue)
145
+ )
146
+ );
147
+ }
148
+ return react_1.default.createElement(
102
149
  "div",
103
150
  null,
104
- react_1.default.createElement(react_markdown_1.default, {
105
- children: `**Default value:** \`${value}\``,
106
- })
107
- )
108
- );
151
+ react_1.default.createElement("strong", null, "Default value: "),
152
+ react_1.default.createElement(
153
+ "span",
154
+ null,
155
+ react_1.default.createElement(
156
+ "code",
157
+ null,
158
+ JSON.stringify(defaultValue)
159
+ )
160
+ )
161
+ );
162
+ }
163
+ return undefined;
164
+ }
109
165
  const renderExample = (0, utils_1.guard)(
110
166
  (0, utils_1.toString)(example),
111
167
  (example) =>
@@ -186,8 +242,9 @@ function ParamsItem({
186
242
  renderDeprecated
187
243
  ),
188
244
  renderSchema,
189
- renderDefaultValue,
190
245
  renderDescription,
246
+ renderEnumDescriptions,
247
+ renderDefaultValue(),
191
248
  renderExample,
192
249
  renderExamples
193
250
  );
@@ -9,4 +9,4 @@ export interface Props {
9
9
  schema: any;
10
10
  discriminator: boolean;
11
11
  }
12
- export default function SchemaItem({ children: collapsibleSchemaContent, collapsible, name, qualifierMessage, required, schemaName, schema, }: Props): React.JSX.Element;
12
+ export default function SchemaItem(props: Props): React.JSX.Element;
@@ -16,25 +16,50 @@ const CodeBlock_1 = __importDefault(require("@theme/CodeBlock"));
16
16
  const clsx_1 = __importDefault(require("clsx"));
17
17
  const react_markdown_1 = __importDefault(require("react-markdown"));
18
18
  const rehype_raw_1 = __importDefault(require("rehype-raw"));
19
+ const remark_gfm_1 = __importDefault(require("remark-gfm"));
19
20
  const createDescription_1 = require("../../markdown/createDescription");
20
21
  const utils_1 = require("../../markdown/utils");
21
- function SchemaItem({
22
- children: collapsibleSchemaContent,
23
- collapsible,
24
- name,
25
- qualifierMessage,
26
- required,
27
- schemaName,
28
- schema,
29
- }) {
22
+ const transformEnumDescriptions = (enumDescriptions) => {
23
+ if (enumDescriptions) {
24
+ return Object.entries(enumDescriptions);
25
+ }
26
+ return [];
27
+ };
28
+ const getEnumDescriptionMarkdown = (enumDescriptions) => {
29
+ if (enumDescriptions?.length) {
30
+ return `| Enum Value | Description |
31
+ | ---- | ----- |
32
+ ${enumDescriptions
33
+ .map((desc) => {
34
+ return `| ${desc[0]} | ${desc[1]} | `.replaceAll("\n", "<br/>");
35
+ })
36
+ .join("\n")}
37
+ `;
38
+ }
39
+ return "";
40
+ };
41
+ function SchemaItem(props) {
42
+ const {
43
+ children: collapsibleSchemaContent,
44
+ collapsible,
45
+ name,
46
+ qualifierMessage,
47
+ required,
48
+ schemaName,
49
+ schema,
50
+ } = props;
30
51
  let deprecated;
31
52
  let schemaDescription;
32
53
  let defaultValue;
54
+ let example;
33
55
  let nullable;
56
+ let enumDescriptions = [];
34
57
  if (schema) {
35
58
  deprecated = schema.deprecated;
36
59
  schemaDescription = schema.description;
60
+ enumDescriptions = transformEnumDescriptions(schema["x-enumDescriptions"]);
37
61
  defaultValue = schema.default;
62
+ example = schema.example;
38
63
  nullable = schema.nullable;
39
64
  }
40
65
  const renderRequired = (0, utils_1.guard)(
@@ -60,6 +85,16 @@ function SchemaItem({
60
85
  "nullable"
61
86
  )
62
87
  );
88
+ const renderEnumDescriptions = (0, utils_1.guard)(
89
+ getEnumDescriptionMarkdown(enumDescriptions),
90
+ (value) => {
91
+ return react_1.default.createElement(react_markdown_1.default, {
92
+ remarkPlugins: [remark_gfm_1.default],
93
+ rehypePlugins: [rehype_raw_1.default],
94
+ children: value,
95
+ });
96
+ }
97
+ );
63
98
  const renderSchemaDescription = (0, utils_1.guard)(
64
99
  schemaDescription,
65
100
  (description) =>
@@ -103,15 +138,64 @@ function SchemaItem({
103
138
  })
104
139
  )
105
140
  );
106
- const renderDefaultValue = (0, utils_1.guard)(defaultValue, (value) =>
107
- react_1.default.createElement(
108
- "div",
109
- { className: "" },
110
- react_1.default.createElement(react_markdown_1.default, {
111
- children: `**Default value:** \`${value}\``,
112
- })
113
- )
114
- );
141
+ function renderDefaultValue() {
142
+ if (defaultValue !== undefined) {
143
+ if (typeof defaultValue === "string") {
144
+ return react_1.default.createElement(
145
+ "div",
146
+ null,
147
+ react_1.default.createElement("strong", null, "Default value: "),
148
+ react_1.default.createElement(
149
+ "span",
150
+ null,
151
+ react_1.default.createElement("code", null, defaultValue)
152
+ )
153
+ );
154
+ }
155
+ return react_1.default.createElement(
156
+ "div",
157
+ null,
158
+ react_1.default.createElement("strong", null, "Default value: "),
159
+ react_1.default.createElement(
160
+ "span",
161
+ null,
162
+ react_1.default.createElement(
163
+ "code",
164
+ null,
165
+ JSON.stringify(defaultValue)
166
+ )
167
+ )
168
+ );
169
+ }
170
+ return undefined;
171
+ }
172
+ function renderExample() {
173
+ if (example !== undefined) {
174
+ if (typeof example === "string") {
175
+ return react_1.default.createElement(
176
+ "div",
177
+ null,
178
+ react_1.default.createElement("strong", null, "Example: "),
179
+ react_1.default.createElement(
180
+ "span",
181
+ null,
182
+ react_1.default.createElement("code", null, example)
183
+ )
184
+ );
185
+ }
186
+ return react_1.default.createElement(
187
+ "div",
188
+ null,
189
+ react_1.default.createElement("strong", null, "Example: "),
190
+ react_1.default.createElement(
191
+ "span",
192
+ null,
193
+ react_1.default.createElement("code", null, JSON.stringify(example))
194
+ )
195
+ );
196
+ }
197
+ return undefined;
198
+ }
115
199
  const schemaContent = react_1.default.createElement(
116
200
  "div",
117
201
  null,
@@ -141,9 +225,11 @@ function SchemaItem({
141
225
  renderRequired,
142
226
  renderDeprecated
143
227
  ),
144
- renderQualifierMessage,
145
- renderDefaultValue,
146
228
  renderSchemaDescription,
229
+ renderEnumDescriptions,
230
+ renderQualifierMessage,
231
+ renderDefaultValue(),
232
+ renderExample(),
147
233
  collapsibleSchemaContent ?? collapsibleSchemaContent
148
234
  );
149
235
  return react_1.default.createElement(
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": "4.0.0",
4
+ "version": "4.1.0",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -28,7 +28,7 @@
28
28
  "watch": "concurrently --names \"lib,lib-next,tsc\" --kill-others \"yarn babel:lib --watch\" \"yarn babel:lib-next --watch\" \"yarn tsc --watch\""
29
29
  },
30
30
  "devDependencies": {
31
- "@docusaurus/types": "^3.0.1",
31
+ "@docusaurus/types": "^3.5.0",
32
32
  "@types/crypto-js": "^4.1.0",
33
33
  "@types/file-saver": "^2.0.5",
34
34
  "@types/lodash": "^4.14.176",
@@ -36,13 +36,13 @@
36
36
  "eslint-plugin-prettier": "^5.0.1"
37
37
  },
38
38
  "dependencies": {
39
- "@docusaurus/theme-common": "^3.0.1",
39
+ "@docusaurus/theme-common": "^3.5.0",
40
40
  "@hookform/error-message": "^2.0.1",
41
41
  "@reduxjs/toolkit": "^1.7.1",
42
42
  "clsx": "^1.1.1",
43
43
  "copy-text-to-clipboard": "^3.1.0",
44
44
  "crypto-js": "^4.1.1",
45
- "docusaurus-plugin-openapi-docs": "^4.0.0",
45
+ "docusaurus-plugin-openapi-docs": "^4.1.0",
46
46
  "docusaurus-plugin-sass": "^0.2.3",
47
47
  "file-saver": "^2.0.5",
48
48
  "lodash": "^4.17.20",
@@ -57,6 +57,7 @@
57
57
  "react-modal": "^3.15.1",
58
58
  "react-redux": "^7.2.0",
59
59
  "rehype-raw": "^6.1.1",
60
+ "remark-gfm": "3.0.1",
60
61
  "sass": "^1.58.1",
61
62
  "sass-loader": "^13.3.2",
62
63
  "webpack": "^5.61.0",
@@ -69,5 +70,5 @@
69
70
  "engines": {
70
71
  "node": ">=14"
71
72
  },
72
- "gitHead": "79d74177cfd54d2750dde1e15c6ea166f9ca4be9"
73
+ "gitHead": "4e771d309f6defe395449b26cc3c65814d72cbcc"
73
74
  }
@@ -7,9 +7,10 @@
7
7
 
8
8
  import { ReactNode } from "react";
9
9
 
10
- export type Children = ReactNode | string | undefined | (string | undefined)[];
10
+ /** @deprecated use ReactNode from React instead */
11
+ export type Children = ReactNode;
11
12
 
12
- export type Props = Record<string, any> & { children?: Children };
13
+ export type Props = Record<string, any> & { children?: ReactNode };
13
14
 
14
15
  export function create(tag: string, props: Props): string {
15
16
  const { children, ...rest } = props;
@@ -24,8 +25,8 @@ export function create(tag: string, props: Props): string {
24
25
 
25
26
  export function guard<T>(
26
27
  value: T | undefined | string,
27
- cb: (value: T) => Children
28
- ): string {
28
+ cb: (value: T) => ReactNode
29
+ ) {
29
30
  if (!!value || value === 0) {
30
31
  const children = cb(value as T);
31
32
  return render(children);
@@ -33,11 +34,11 @@ export function guard<T>(
33
34
  return "";
34
35
  }
35
36
 
36
- export function render(children: Children): string {
37
+ export function render(children: ReactNode) {
37
38
  if (Array.isArray(children)) {
38
39
  return children.filter((c) => c !== undefined).join("");
39
40
  }
40
- return (children as string) ?? "";
41
+ return children ?? "";
41
42
  }
42
43
 
43
44
  export function toString(value: any): string | undefined {
@@ -15,4 +15,6 @@ declare module "@docusaurus/plugin-content-docs/client" {
15
15
  children: ReactNode;
16
16
  content: PropDocContent;
17
17
  });
18
+
19
+ export function useDoc();
18
20
  }
@@ -22,10 +22,12 @@ export type CodeSampleLanguage =
22
22
  | "JavaScript"
23
23
  | "Kotlin"
24
24
  | "Objective-C"
25
+ | "OCaml"
25
26
  | "Perl"
26
27
  | "PHP"
27
28
  | "PowerShell"
28
29
  | "Python"
30
+ | "R"
29
31
  | "Ruby"
30
32
  | "Rust"
31
33
  | "Scala"
@@ -27,120 +27,10 @@ import {
27
27
  getCodeSampleSourceFromLanguage,
28
28
  mergeArraysbyLanguage,
29
29
  mergeCodeSampleLanguage,
30
+ generateLanguageSet,
30
31
  } from "./languages";
31
32
 
32
- export const languageSet: Language[] = [
33
- {
34
- highlight: "bash",
35
- language: "curl",
36
- codeSampleLanguage: "Shell",
37
- logoClass: "bash",
38
- options: {
39
- longFormat: false,
40
- followRedirect: true,
41
- trimRequestBody: true,
42
- },
43
- variant: "cURL",
44
- variants: ["curl"],
45
- },
46
- {
47
- highlight: "python",
48
- language: "python",
49
- codeSampleLanguage: "Python",
50
- logoClass: "python",
51
- options: {
52
- followRedirect: true,
53
- trimRequestBody: true,
54
- },
55
- variant: "requests",
56
- variants: ["requests", "http.client"],
57
- },
58
- {
59
- highlight: "go",
60
- language: "go",
61
- codeSampleLanguage: "Go",
62
- logoClass: "go",
63
- options: {
64
- followRedirect: true,
65
- trimRequestBody: true,
66
- },
67
- variant: "native",
68
- variants: ["native"],
69
- },
70
- {
71
- highlight: "javascript",
72
- language: "nodejs",
73
- codeSampleLanguage: "JavaScript",
74
- logoClass: "nodejs",
75
- options: {
76
- ES6_enabled: true,
77
- followRedirect: true,
78
- trimRequestBody: true,
79
- },
80
- variant: "axios",
81
- variants: ["axios", "native"],
82
- },
83
- {
84
- highlight: "ruby",
85
- language: "ruby",
86
- codeSampleLanguage: "Ruby",
87
- logoClass: "ruby",
88
- options: {
89
- followRedirect: true,
90
- trimRequestBody: true,
91
- },
92
- variant: "Net::HTTP",
93
- variants: ["net::http"],
94
- },
95
- {
96
- highlight: "csharp",
97
- language: "csharp",
98
- codeSampleLanguage: "C#",
99
- logoClass: "csharp",
100
- options: {
101
- followRedirect: true,
102
- trimRequestBody: true,
103
- },
104
- variant: "RestSharp",
105
- variants: ["restsharp", "httpclient"],
106
- },
107
- {
108
- highlight: "php",
109
- language: "php",
110
- codeSampleLanguage: "PHP",
111
- logoClass: "php",
112
- options: {
113
- followRedirect: true,
114
- trimRequestBody: true,
115
- },
116
- variant: "cURL",
117
- variants: ["curl", "guzzle", "pecl_http", "http_request2"],
118
- },
119
- {
120
- highlight: "java",
121
- language: "java",
122
- codeSampleLanguage: "Java",
123
- logoClass: "java",
124
- options: {
125
- followRedirect: true,
126
- trimRequestBody: true,
127
- },
128
- variant: "OkHttp",
129
- variants: ["okhttp", "unirest"],
130
- },
131
- {
132
- highlight: "powershell",
133
- language: "powershell",
134
- codeSampleLanguage: "PowerShell",
135
- logoClass: "powershell",
136
- options: {
137
- followRedirect: true,
138
- trimRequestBody: true,
139
- },
140
- variant: "RestMethod",
141
- variants: ["restmethod"],
142
- },
143
- ];
33
+ export const languageSet: Language[] = generateLanguageSet();
144
34
 
145
35
  export interface Props {
146
36
  postman: sdk.Request;
@@ -339,6 +229,7 @@ function CodeSnippets({ postman, codeSamples }: Props) {
339
229
 
340
230
  return (
341
231
  <>
232
+ {/* Outer language tabs */}
342
233
  <CodeTabs
343
234
  groupId="code-samples"
344
235
  action={{
@@ -347,6 +238,7 @@ function CodeSnippets({ postman, codeSamples }: Props) {
347
238
  setSelectedSample: setSelectedSample,
348
239
  }}
349
240
  languageSet={mergedLangs}
241
+ defaultValue={defaultLang[0]?.language ?? mergedLangs[0].language}
350
242
  lazy
351
243
  >
352
244
  {mergedLangs.map((lang) => {
@@ -359,6 +251,7 @@ function CodeSnippets({ postman, codeSamples }: Props) {
359
251
  className: `openapi-tabs__code-item--${lang.logoClass}`,
360
252
  }}
361
253
  >
254
+ {/* Inner x-codeSamples tabs */}
362
255
  {lang.samples && (
363
256
  <CodeTabs
364
257
  className="openapi-tabs__code-container-inner"
@@ -400,6 +293,7 @@ function CodeSnippets({ postman, codeSamples }: Props) {
400
293
  </CodeTabs>
401
294
  )}
402
295
 
296
+ {/* Inner generated code snippets */}
403
297
  <CodeTabs
404
298
  className="openapi-tabs__code-container-inner"
405
299
  action={{
@@ -6,9 +6,9 @@
6
6
  * ========================================================================== */
7
7
 
8
8
  import find from "lodash/find";
9
- import isArray from "lodash/isArray";
10
9
  import mergeWith from "lodash/mergeWith";
11
10
  import unionBy from "lodash/unionBy";
11
+ import codegen from "postman-code-generators";
12
12
 
13
13
  import { CodeSample, Language } from "./code-snippets-types";
14
14
 
@@ -50,10 +50,7 @@ export const mergeArraysbyLanguage = (arr1: any, arr2: any) => {
50
50
  find(arr2, ["language", item["language"]]),
51
51
  ];
52
52
  return mergeWith({}, ...matchingItems, (objValue: any) => {
53
- if (isArray(objValue)) {
54
- return objValue;
55
- }
56
- return undefined;
53
+ return objValue;
57
54
  });
58
55
  });
59
56
  };
@@ -73,3 +70,27 @@ export function getCodeSampleSourceFromLanguage(language: Language) {
73
70
 
74
71
  return "";
75
72
  }
73
+
74
+ export function generateLanguageSet() {
75
+ const languageSet: Language[] = [];
76
+ codegen.getLanguageList().forEach((language: any) => {
77
+ const variants: any = [];
78
+ language.variants.forEach((variant: any) => {
79
+ variants.push(variant.key);
80
+ });
81
+ languageSet.push({
82
+ highlight: language.syntax_mode,
83
+ language: language.key,
84
+ codeSampleLanguage: language.label,
85
+ logoClass: language.key,
86
+ options: {
87
+ longFormat: false,
88
+ followRedirect: true,
89
+ trimRequestBody: true,
90
+ },
91
+ variant: variants[0],
92
+ variants: variants,
93
+ });
94
+ });
95
+ return languageSet;
96
+ }