docusaurus-theme-openapi-docs 2.0.3 → 2.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 (58) hide show
  1. package/lib/markdown/utils.d.ts +2 -2
  2. package/lib/markdown/utils.js +4 -4
  3. package/lib/markdown/utils.test.d.ts +1 -0
  4. package/lib/markdown/utils.test.js +43 -0
  5. package/lib/theme/ApiExplorer/Accept/index.d.ts +2 -2
  6. package/lib/theme/ApiExplorer/Authorization/index.d.ts +2 -2
  7. package/lib/theme/ApiExplorer/Authorization/slice.d.ts +1 -1
  8. package/lib/theme/ApiExplorer/Body/index.d.ts +2 -2
  9. package/lib/theme/ApiExplorer/Body/slice.d.ts +3 -3
  10. package/lib/theme/ApiExplorer/CodeSnippets/code-snippets-types.d.ts +21 -0
  11. package/lib/theme/ApiExplorer/CodeSnippets/code-snippets-types.js +8 -0
  12. package/lib/theme/ApiExplorer/CodeSnippets/index.d.ts +4 -14
  13. package/lib/theme/ApiExplorer/CodeSnippets/index.js +86 -8
  14. package/lib/theme/ApiExplorer/CodeSnippets/languages.d.ts +3 -0
  15. package/lib/theme/ApiExplorer/CodeSnippets/languages.js +48 -0
  16. package/lib/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +14 -0
  17. package/lib/theme/ApiExplorer/CodeTabs/index.js +10 -1
  18. package/lib/theme/ApiExplorer/ContentType/index.d.ts +2 -2
  19. package/lib/theme/ApiExplorer/Export/index.d.ts +2 -2
  20. package/lib/theme/ApiExplorer/FloatingButton/index.d.ts +1 -1
  21. package/lib/theme/ApiExplorer/FormFileUpload/index.d.ts +2 -2
  22. package/lib/theme/ApiExplorer/FormItem/index.d.ts +1 -1
  23. package/lib/theme/ApiExplorer/FormMultiSelect/index.d.ts +1 -1
  24. package/lib/theme/ApiExplorer/FormSelect/index.d.ts +1 -1
  25. package/lib/theme/ApiExplorer/FormTextInput/index.d.ts +1 -1
  26. package/lib/theme/ApiExplorer/MethodEndpoint/index.d.ts +2 -2
  27. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.d.ts +2 -2
  28. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.d.ts +2 -2
  29. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.d.ts +2 -2
  30. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.d.ts +2 -2
  31. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.d.ts +2 -2
  32. package/lib/theme/ApiExplorer/ParamOptions/index.d.ts +2 -2
  33. package/lib/theme/ApiExplorer/ParamOptions/slice.d.ts +1 -1
  34. package/lib/theme/ApiExplorer/Request/index.d.ts +2 -2
  35. package/lib/theme/ApiExplorer/Response/index.d.ts +2 -2
  36. package/lib/theme/ApiExplorer/SecuritySchemes/index.d.ts +2 -2
  37. package/lib/theme/ApiExplorer/Server/index.d.ts +2 -2
  38. package/lib/theme/ApiExplorer/buildPostmanRequest.d.ts +1 -1
  39. package/lib/theme/ApiExplorer/index.d.ts +2 -2
  40. package/lib/theme/ApiExplorer/index.js +1 -1
  41. package/lib/theme/ApiExplorer/storage-utils.d.ts +1 -1
  42. package/lib/theme/ApiItem/index.js +24 -0
  43. package/lib/theme/ApiItem/store.d.ts +6 -6
  44. package/lib/theme/SchemaItem/index.js +5 -8
  45. package/lib/types.d.ts +4 -4
  46. package/package.json +3 -3
  47. package/src/markdown/utils.test.ts +48 -0
  48. package/src/markdown/utils.ts +4 -4
  49. package/src/theme/ApiExplorer/CodeSnippets/code-snippets-types.ts +55 -0
  50. package/src/theme/ApiExplorer/CodeSnippets/index.tsx +94 -21
  51. package/src/theme/ApiExplorer/CodeSnippets/languages.ts +53 -0
  52. package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +14 -0
  53. package/src/theme/ApiExplorer/CodeTabs/index.js +10 -1
  54. package/src/theme/ApiExplorer/index.tsx +1 -1
  55. package/src/theme/ApiItem/index.tsx +20 -0
  56. package/src/theme/SchemaItem/index.js +5 -8
  57. package/lib/theme/ApiExplorer/CodeSnippets/languages.json +0 -1386
  58. package/src/theme/ApiExplorer/CodeSnippets/languages.json +0 -1386
@@ -1,5 +1,5 @@
1
- export declare type Children = string | undefined | (string | undefined)[];
2
- export declare type Props = Record<string, any> & {
1
+ export type Children = string | undefined | (string | undefined)[];
2
+ export type Props = Record<string, any> & {
3
3
  children?: Children;
4
4
  };
5
5
  export declare function create(tag: string, props: Props): string;
@@ -17,11 +17,11 @@ function create(tag, props) {
17
17
  }
18
18
  exports.create = create;
19
19
  function guard(value, cb) {
20
- if (!!value) {
21
- const children = cb(value);
22
- return render(children);
20
+ if (value === undefined || value === "") {
21
+ return "";
23
22
  }
24
- return "";
23
+ const children = cb(value);
24
+ return render(children);
25
25
  }
26
26
  exports.guard = guard;
27
27
  function render(children) {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const utils_1 = require("./utils");
10
+ describe("guard", () => {
11
+ it("should guard empty strings", () => {
12
+ const actual = (0, utils_1.guard)("", (_) => {
13
+ throw new Error("Should not be called");
14
+ });
15
+ expect(actual).toBe("");
16
+ });
17
+ it("should guard undefined", () => {
18
+ const actual = (0, utils_1.guard)(undefined, (value) => {
19
+ throw new Error("Should not be called");
20
+ });
21
+ expect(actual).toBe("");
22
+ });
23
+ it("should not guard strings", () => {
24
+ const actual = (0, utils_1.guard)("hello", (value) => value);
25
+ expect(actual).toBe("hello");
26
+ });
27
+ it("should not guard numbers", () => {
28
+ const actual = (0, utils_1.guard)(1, (value) => `${value}`);
29
+ expect(actual).toBe("1");
30
+ });
31
+ it("should not guard numbers equals to 0", () => {
32
+ const actual = (0, utils_1.guard)(0, (value) => `${value}`);
33
+ expect(actual).toBe("0");
34
+ });
35
+ it("should not guard false booleans", () => {
36
+ const actual = (0, utils_1.guard)(false, (value) => `${value}`);
37
+ expect(actual).toBe("false");
38
+ });
39
+ it("should not guard true booleans", () => {
40
+ const actual = (0, utils_1.guard)(true, (value) => `${value}`);
41
+ expect(actual).toBe("true");
42
+ });
43
+ });
@@ -1,3 +1,3 @@
1
- /// <reference types="react" />
2
- declare function Accept(): JSX.Element | null;
1
+ import React from "react";
2
+ declare function Accept(): React.JSX.Element | null;
3
3
  export default Accept;
@@ -1,3 +1,3 @@
1
- /// <reference types="react" />
2
- declare function Authorization(): JSX.Element | null;
1
+ import React from "react";
2
+ declare function Authorization(): React.JSX.Element | null;
3
3
  export default Authorization;
@@ -8,7 +8,7 @@ export declare function createAuth({ security, securitySchemes, options, }: {
8
8
  };
9
9
  options?: ThemeConfig["api"];
10
10
  }): AuthState;
11
- export declare type Scheme = {
11
+ export type Scheme = {
12
12
  key: string;
13
13
  scopes: string[];
14
14
  } & SecuritySchemeObject;
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from "react";
2
2
  import { RequestBodyObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
3
3
  export interface Props {
4
4
  jsonRequestBodyExample: string;
@@ -6,5 +6,5 @@ export interface Props {
6
6
  methods?: any;
7
7
  required?: boolean;
8
8
  }
9
- declare function BodyWrap({ requestBodyMetadata, jsonRequestBodyExample, methods, required, }: Props): JSX.Element | null;
9
+ declare function BodyWrap({ requestBodyMetadata, jsonRequestBodyExample, methods, required, }: Props): React.JSX.Element | null;
10
10
  export default BodyWrap;
@@ -10,7 +10,7 @@ export interface StringContent {
10
10
  type: "string";
11
11
  value?: string;
12
12
  }
13
- export declare type Content = FileContent | StringContent | undefined;
13
+ export type Content = FileContent | StringContent | undefined;
14
14
  export interface FormBody {
15
15
  type: "form";
16
16
  content: {
@@ -24,8 +24,8 @@ export interface RawBody {
24
24
  export interface EmptyBody {
25
25
  type: "empty";
26
26
  }
27
- export declare type Body = EmptyBody | FormBody | RawBody;
28
- export declare type State = Body;
27
+ export type Body = EmptyBody | FormBody | RawBody;
28
+ export type State = Body;
29
29
  export declare const slice: import("@reduxjs/toolkit").Slice<EmptyBody | FormBody | RawBody, {
30
30
  clearRawBody: (_state: import("immer/dist/internal").WritableDraft<EmptyBody> | import("immer/dist/internal").WritableDraft<FormBody> | import("immer/dist/internal").WritableDraft<RawBody>) => {
31
31
  type: "empty";
@@ -0,0 +1,21 @@
1
+ export type CodeSampleLanguage = "C" | "C#" | "C++" | "CoffeeScript" | "CSS" | "Dart" | "DM" | "Elixir" | "Go" | "Groovy" | "HTML" | "Java" | "JavaScript" | "Kotlin" | "Objective-C" | "Perl" | "PHP" | "PowerShell" | "Python" | "Ruby" | "Rust" | "Scala" | "Shell" | "Swift" | "TypeScript";
2
+ export interface Language {
3
+ highlight: string;
4
+ language: string;
5
+ codeSampleLanguage: CodeSampleLanguage;
6
+ logoClass: string;
7
+ variant: string;
8
+ variants: string[];
9
+ options?: {
10
+ [key: string]: boolean;
11
+ };
12
+ sample?: string;
13
+ samples?: string[];
14
+ samplesSources?: string[];
15
+ samplesLabels?: string[];
16
+ }
17
+ export interface CodeSample {
18
+ source: string;
19
+ lang: CodeSampleLanguage;
20
+ label?: string;
21
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,20 +1,10 @@
1
- /// <reference types="react" />
1
+ import React from "react";
2
2
  import sdk from "@paloaltonetworks/postman-collection";
3
- export interface Language {
4
- highlight: string;
5
- language: string;
6
- logoClass: string;
7
- variant: string;
8
- variants: string[];
9
- options: {
10
- [key: string]: boolean;
11
- };
12
- source?: string;
13
- }
3
+ import { CodeSample, Language } from "./code-snippets-types";
14
4
  export declare const languageSet: Language[];
15
5
  export interface Props {
16
6
  postman: sdk.Request;
17
- codeSamples: any;
7
+ codeSamples: CodeSample[];
18
8
  }
19
- declare function CodeSnippets({ postman, codeSamples }: Props): JSX.Element | null;
9
+ declare function CodeSnippets({ postman, codeSamples }: Props): React.JSX.Element | null;
20
10
  export default CodeSnippets;
@@ -72,10 +72,12 @@ const buildPostmanRequest_1 = __importDefault(
72
72
  const CodeTabs_1 = __importDefault(require("@theme/ApiExplorer/CodeTabs"));
73
73
  const hooks_1 = require("@theme/ApiItem/hooks");
74
74
  const merge_1 = __importDefault(require("lodash/merge"));
75
+ const languages_1 = require("./languages");
75
76
  exports.languageSet = [
76
77
  {
77
78
  highlight: "bash",
78
79
  language: "curl",
80
+ codeSampleLanguage: "Shell",
79
81
  logoClass: "bash",
80
82
  options: {
81
83
  longFormat: false,
@@ -88,6 +90,7 @@ exports.languageSet = [
88
90
  {
89
91
  highlight: "python",
90
92
  language: "python",
93
+ codeSampleLanguage: "Python",
91
94
  logoClass: "python",
92
95
  options: {
93
96
  followRedirect: true,
@@ -99,6 +102,7 @@ exports.languageSet = [
99
102
  {
100
103
  highlight: "go",
101
104
  language: "go",
105
+ codeSampleLanguage: "Go",
102
106
  logoClass: "go",
103
107
  options: {
104
108
  followRedirect: true,
@@ -110,6 +114,7 @@ exports.languageSet = [
110
114
  {
111
115
  highlight: "javascript",
112
116
  language: "nodejs",
117
+ codeSampleLanguage: "JavaScript",
113
118
  logoClass: "nodejs",
114
119
  options: {
115
120
  ES6_enabled: true,
@@ -117,11 +122,12 @@ exports.languageSet = [
117
122
  trimRequestBody: true,
118
123
  },
119
124
  variant: "axios",
120
- variants: ["axios", "native", "request", "unirest"],
125
+ variants: ["axios", "native"],
121
126
  },
122
127
  {
123
128
  highlight: "ruby",
124
129
  language: "ruby",
130
+ codeSampleLanguage: "Ruby",
125
131
  logoClass: "ruby",
126
132
  options: {
127
133
  followRedirect: true,
@@ -133,6 +139,7 @@ exports.languageSet = [
133
139
  {
134
140
  highlight: "csharp",
135
141
  language: "csharp",
142
+ codeSampleLanguage: "C#",
136
143
  logoClass: "csharp",
137
144
  options: {
138
145
  followRedirect: true,
@@ -144,6 +151,7 @@ exports.languageSet = [
144
151
  {
145
152
  highlight: "php",
146
153
  language: "php",
154
+ codeSampleLanguage: "PHP",
147
155
  logoClass: "php",
148
156
  options: {
149
157
  followRedirect: true,
@@ -155,6 +163,7 @@ exports.languageSet = [
155
163
  {
156
164
  highlight: "java",
157
165
  language: "java",
166
+ codeSampleLanguage: "Java",
158
167
  logoClass: "java",
159
168
  options: {
160
169
  followRedirect: true,
@@ -166,6 +175,7 @@ exports.languageSet = [
166
175
  {
167
176
  highlight: "powershell",
168
177
  language: "powershell",
178
+ codeSampleLanguage: "PowerShell",
169
179
  logoClass: "powershell",
170
180
  options: {
171
181
  followRedirect: true,
@@ -175,7 +185,7 @@ exports.languageSet = [
175
185
  variants: ["restmethod"],
176
186
  },
177
187
  ];
178
- function CodeTab({ children, hidden, className, onClick }) {
188
+ function CodeTab({ children, hidden, className }) {
179
189
  return react_1.default.createElement(
180
190
  "div",
181
191
  { role: "tabpanel", className: className, ...{ hidden } },
@@ -208,7 +218,6 @@ function CodeSnippets({ postman, codeSamples }) {
208
218
  // Can override languageSet, change order of langs, override options and variants
209
219
  const langs = [
210
220
  ...(siteConfig?.themeConfig?.languageTabs ?? exports.languageSet),
211
- ...codeSamples,
212
221
  ];
213
222
  // Filter languageSet by user-defined langs
214
223
  const filteredLanguageSet = exports.languageSet.filter((ls) => {
@@ -217,13 +226,17 @@ function CodeSnippets({ postman, codeSamples }) {
217
226
  });
218
227
  });
219
228
  // Merge user-defined langs into languageSet
220
- const mergedLangs = (0, merge_1.default)(filteredLanguageSet, langs);
229
+ const mergedLangs = (0, languages_1.mergeCodeSampleLanguage)(
230
+ (0, merge_1.default)(filteredLanguageSet, langs),
231
+ codeSamples
232
+ );
221
233
  // Read defaultLang from localStorage
222
234
  const defaultLang = mergedLangs.filter(
223
235
  (lang) =>
224
236
  lang.language === localStorage.getItem("docusaurus.tab.code-samples")
225
237
  );
226
238
  const [selectedVariant, setSelectedVariant] = (0, react_1.useState)();
239
+ const [selectedSample, setSelectedSample] = (0, react_1.useState)();
227
240
  const [language, setLanguage] = (0, react_1.useState)(() => {
228
241
  // Return first index if only 1 user-defined language exists
229
242
  if (mergedLangs.length === 1) {
@@ -233,7 +246,15 @@ function CodeSnippets({ postman, codeSamples }) {
233
246
  return defaultLang[0] ?? mergedLangs[0];
234
247
  });
235
248
  const [codeText, setCodeText] = (0, react_1.useState)("");
249
+ const [codeSampleCodeText, setCodeSampleCodeText] = (0, react_1.useState)(
250
+ () => (0, languages_1.getCodeSampleSourceFromLanguage)(language)
251
+ );
236
252
  (0, react_1.useEffect)(() => {
253
+ if (language && !!language.sample) {
254
+ setCodeSampleCodeText(
255
+ (0, languages_1.getCodeSampleSourceFromLanguage)(language)
256
+ );
257
+ }
237
258
  if (language && !!language.options) {
238
259
  const postmanRequest = (0, buildPostmanRequest_1.default)(postman, {
239
260
  queryParams,
@@ -258,8 +279,6 @@ function CodeSnippets({ postman, codeSamples }) {
258
279
  setCodeText(snippet);
259
280
  }
260
281
  );
261
- } else if (language && !!language.source) {
262
- setCodeText(language.source);
263
282
  } else if (language && !language.options) {
264
283
  const langSource = mergedLangs.filter(
265
284
  (lang) => lang.language === language.language
@@ -308,7 +327,8 @@ function CodeSnippets({ postman, codeSamples }) {
308
327
  auth,
309
328
  mergedLangs,
310
329
  ]);
311
- (0, react_1.useEffect)(() => {
330
+ // no dependencies was intentionlly set for this particular hook. it's safe as long as if conditions are set
331
+ (0, react_1.useEffect)(function onSelectedVariantUpdate() {
312
332
  if (selectedVariant && selectedVariant !== language.variant) {
313
333
  const postmanRequest = (0, buildPostmanRequest_1.default)(postman, {
314
334
  queryParams,
@@ -335,6 +355,21 @@ function CodeSnippets({ postman, codeSamples }) {
335
355
  );
336
356
  }
337
357
  });
358
+ // no dependencies was intentionlly set for this particular hook. it's safe as long as if conditions are set
359
+ // eslint-disable-next-line react-hooks/exhaustive-deps
360
+ (0, react_1.useEffect)(function onSelectedSampleUpdate() {
361
+ if (
362
+ language.samples &&
363
+ language.samplesSources &&
364
+ selectedSample &&
365
+ selectedSample !== language.sample
366
+ ) {
367
+ const sampleIndex = language.samples.findIndex(
368
+ (smp) => smp === selectedSample
369
+ );
370
+ setCodeSampleCodeText(language.samplesSources[sampleIndex]);
371
+ }
372
+ });
338
373
  if (language === undefined) {
339
374
  return null;
340
375
  }
@@ -348,7 +383,9 @@ function CodeSnippets({ postman, codeSamples }) {
348
383
  action: {
349
384
  setLanguage: setLanguage,
350
385
  setSelectedVariant: setSelectedVariant,
386
+ setSelectedSample: setSelectedSample,
351
387
  },
388
+ languageSet: mergedLangs,
352
389
  lazy: true,
353
390
  },
354
391
  mergedLangs.map((lang) => {
@@ -362,6 +399,46 @@ function CodeSnippets({ postman, codeSamples }) {
362
399
  className: `openapi-tabs__code-item--${lang.logoClass}`,
363
400
  },
364
401
  },
402
+ lang.samples &&
403
+ react_1.default.createElement(
404
+ CodeTabs_1.default,
405
+ {
406
+ className: "openapi-tabs__code-container-inner",
407
+ action: {
408
+ setLanguage: setLanguage,
409
+ setSelectedSample: setSelectedSample,
410
+ },
411
+ includeSample: true,
412
+ currentLanguage: lang.language,
413
+ defaultValue: selectedSample,
414
+ languageSet: mergedLangs,
415
+ lazy: true,
416
+ },
417
+ lang.samples.map((sample, index) => {
418
+ return react_1.default.createElement(
419
+ CodeTab,
420
+ {
421
+ value: sample,
422
+ label: lang.samplesLabels
423
+ ? lang.samplesLabels[index]
424
+ : sample,
425
+ key: `${lang.language}-${lang.sample}`,
426
+ attributes: {
427
+ className: `openapi-tabs__code-item--sample`,
428
+ },
429
+ },
430
+ react_1.default.createElement(
431
+ ApiCodeBlock_1.default,
432
+ {
433
+ language: lang.highlight,
434
+ className: "openapi-explorer__code-block",
435
+ showLineNumbers: true,
436
+ },
437
+ codeSampleCodeText
438
+ )
439
+ );
440
+ })
441
+ ),
365
442
  react_1.default.createElement(
366
443
  CodeTabs_1.default,
367
444
  {
@@ -373,9 +450,10 @@ function CodeSnippets({ postman, codeSamples }) {
373
450
  includeVariant: true,
374
451
  currentLanguage: lang.language,
375
452
  defaultValue: selectedVariant,
453
+ languageSet: mergedLangs,
376
454
  lazy: true,
377
455
  },
378
- lang.variants.map((variant) => {
456
+ lang.variants.map((variant, index) => {
379
457
  return react_1.default.createElement(
380
458
  CodeTab,
381
459
  {
@@ -0,0 +1,3 @@
1
+ import { CodeSample, Language } from "./code-snippets-types";
2
+ export declare function mergeCodeSampleLanguage(languages: Language[], codeSamples: CodeSample[]): Language[];
3
+ export declare function getCodeSampleSourceFromLanguage(language: Language): string;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.getCodeSampleSourceFromLanguage = exports.mergeCodeSampleLanguage =
10
+ void 0;
11
+ function mergeCodeSampleLanguage(languages, codeSamples) {
12
+ return languages.map((language) => {
13
+ const languageCodeSamples = codeSamples.filter(
14
+ ({ lang }) => lang === language.codeSampleLanguage
15
+ );
16
+ if (languageCodeSamples.length) {
17
+ const samples = languageCodeSamples.map(({ lang }) => lang);
18
+ const samplesLabels = languageCodeSamples.map(
19
+ ({ label, lang }) => label || lang
20
+ );
21
+ const samplesSources = languageCodeSamples.map(({ source }) => source);
22
+ return {
23
+ ...language,
24
+ sample: samples[0],
25
+ samples,
26
+ samplesSources,
27
+ samplesLabels,
28
+ };
29
+ }
30
+ return language;
31
+ });
32
+ }
33
+ exports.mergeCodeSampleLanguage = mergeCodeSampleLanguage;
34
+ function getCodeSampleSourceFromLanguage(language) {
35
+ if (
36
+ language &&
37
+ language.sample &&
38
+ language.samples &&
39
+ language.samplesSources
40
+ ) {
41
+ const sampleIndex = language.samples.findIndex(
42
+ (smp) => smp === language.sample
43
+ );
44
+ return language.samplesSources[sampleIndex];
45
+ }
46
+ return "";
47
+ }
48
+ exports.getCodeSampleSourceFromLanguage = getCodeSampleSourceFromLanguage;
@@ -94,6 +94,20 @@ body[class="ReactModal__Body--open"] {
94
94
  padding-right: 0.5rem !important;
95
95
  }
96
96
 
97
+ .openapi-tabs__code-item--sample {
98
+ color: var(--ifm-color-secondary);
99
+
100
+ &.active {
101
+ border-color: var(--ifm-toc-border-color);
102
+ }
103
+ }
104
+
105
+ .openapi-tabs__code-item--sample > span {
106
+ padding-top: unset !important;
107
+ padding-left: 0.5rem !important;
108
+ padding-right: 0.5rem !important;
109
+ }
110
+
97
111
  .openapi-tabs__code-item--python {
98
112
  color: var(--ifm-color-success);
99
113
 
@@ -12,13 +12,14 @@ import {
12
12
  useTabs,
13
13
  } from "@docusaurus/theme-common/internal";
14
14
  import useIsBrowser from "@docusaurus/useIsBrowser";
15
- import { languageSet } from "@theme/ApiExplorer/CodeSnippets";
16
15
  import clsx from "clsx";
17
16
 
18
17
  function TabList({
19
18
  action,
20
19
  currentLanguage,
20
+ languageSet,
21
21
  includeVariant,
22
+ includeSample,
22
23
  className,
23
24
  block,
24
25
  selectedValue,
@@ -47,12 +48,20 @@ function TabList({
47
48
  )[0];
48
49
  newLanguage.variant = newTabValue;
49
50
  action.setSelectedVariant(newTabValue.toLowerCase());
51
+ } else if (currentLanguage && includeSample) {
52
+ newLanguage = languageSet.filter(
53
+ (lang) => lang.language === currentLanguage
54
+ )[0];
55
+ newLanguage.sample = newTabValue;
56
+ action.setSelectedSample(newTabValue);
50
57
  } else {
51
58
  newLanguage = languageSet.filter(
52
59
  (lang) => lang.language === newTabValue
53
60
  )[0];
54
61
  action.setSelectedVariant(newLanguage.variant.toLowerCase());
62
+ action.setSelectedSample(newLanguage.sample);
55
63
  }
64
+
56
65
  action.setLanguage(newLanguage);
57
66
  }
58
67
  };
@@ -1,3 +1,3 @@
1
- /// <reference types="react" />
2
- declare function ContentType(): JSX.Element | null;
1
+ import React from "react";
2
+ declare function ContentType(): React.JSX.Element | null;
3
3
  export default ContentType;
@@ -1,3 +1,3 @@
1
- /// <reference types="react" />
2
- declare function Export({ url, proxy }: any): JSX.Element;
1
+ import React from "react";
2
+ declare function Export({ url, proxy }: any): React.JSX.Element;
3
3
  export default Export;
@@ -4,5 +4,5 @@ export interface Props {
4
4
  onClick?: React.MouseEventHandler<HTMLButtonElement>;
5
5
  children?: React.ReactNode;
6
6
  }
7
- declare function FloatingButton({ label, onClick, children }: Props): JSX.Element;
7
+ declare function FloatingButton({ label, onClick, children }: Props): React.JSX.Element;
8
8
  export default FloatingButton;
@@ -1,7 +1,7 @@
1
- /// <reference types="react" />
1
+ import React from "react";
2
2
  export interface Props {
3
3
  placeholder: string;
4
4
  onChange?(file?: File): any;
5
5
  }
6
- declare function FormFileUpload({ placeholder, onChange }: Props): JSX.Element;
6
+ declare function FormFileUpload({ placeholder, onChange }: Props): React.JSX.Element;
7
7
  export default FormFileUpload;
@@ -6,5 +6,5 @@ export interface Props {
6
6
  children?: React.ReactNode;
7
7
  className?: string;
8
8
  }
9
- declare function FormItem({ label, type, required, children, className }: Props): JSX.Element;
9
+ declare function FormItem({ label, type, required, children, className }: Props): React.JSX.Element;
10
10
  export default FormItem;
@@ -5,5 +5,5 @@ export interface Props {
5
5
  onChange?: React.ChangeEventHandler<HTMLSelectElement>;
6
6
  showErrors?: boolean;
7
7
  }
8
- declare function FormMultiSelect({ value, options, onChange, showErrors }: Props): JSX.Element | null;
8
+ declare function FormMultiSelect({ value, options, onChange, showErrors }: Props): React.JSX.Element | null;
9
9
  export default FormMultiSelect;
@@ -4,5 +4,5 @@ export interface Props {
4
4
  options?: string[];
5
5
  onChange?: React.ChangeEventHandler<HTMLSelectElement>;
6
6
  }
7
- declare function FormSelect({ value, options, onChange }: Props): JSX.Element | null;
7
+ declare function FormSelect({ value, options, onChange }: Props): React.JSX.Element | null;
8
8
  export default FormSelect;
@@ -5,5 +5,5 @@ export interface Props {
5
5
  password?: boolean;
6
6
  onChange?: React.ChangeEventHandler<HTMLInputElement>;
7
7
  }
8
- declare function FormTextInput({ isRequired, value, placeholder, password, onChange, paramName, }: Props): JSX.Element;
8
+ declare function FormTextInput({ isRequired, value, placeholder, password, onChange, paramName, }: Props): React.JSX.Element;
9
9
  export default FormTextInput;
@@ -1,7 +1,7 @@
1
- /// <reference types="react" />
1
+ import React from "react";
2
2
  export interface Props {
3
3
  method: string;
4
4
  path: string;
5
5
  }
6
- declare function MethodEndpoint({ method, path }: Props): JSX.Element;
6
+ declare function MethodEndpoint({ method, path }: Props): React.JSX.Element;
7
7
  export default MethodEndpoint;
@@ -1,6 +1,6 @@
1
- /// <reference types="react" />
1
+ import React from "react";
2
2
  import { Param } from "@theme/ApiExplorer/ParamOptions/slice";
3
3
  export interface ParamProps {
4
4
  param: Param;
5
5
  }
6
- export default function ParamArrayFormItem({ param }: ParamProps): JSX.Element;
6
+ export default function ParamArrayFormItem({ param }: ParamProps): React.JSX.Element;
@@ -1,6 +1,6 @@
1
- /// <reference types="react" />
1
+ import React from "react";
2
2
  import { Param } from "@theme/ApiExplorer/ParamOptions/slice";
3
3
  export interface ParamProps {
4
4
  param: Param;
5
5
  }
6
- export default function ParamBooleanFormItem({ param }: ParamProps): JSX.Element;
6
+ export default function ParamBooleanFormItem({ param }: ParamProps): React.JSX.Element;
@@ -1,6 +1,6 @@
1
- /// <reference types="react" />
1
+ import React from "react";
2
2
  import { Param } from "@theme/ApiExplorer/ParamOptions/slice";
3
3
  export interface ParamProps {
4
4
  param: Param;
5
5
  }
6
- export default function ParamMultiSelectFormItem({ param }: ParamProps): JSX.Element;
6
+ export default function ParamMultiSelectFormItem({ param }: ParamProps): React.JSX.Element;
@@ -1,6 +1,6 @@
1
- /// <reference types="react" />
1
+ import React from "react";
2
2
  import { Param } from "@theme/ApiExplorer/ParamOptions/slice";
3
3
  export interface ParamProps {
4
4
  param: Param;
5
5
  }
6
- export default function ParamSelectFormItem({ param }: ParamProps): JSX.Element;
6
+ export default function ParamSelectFormItem({ param }: ParamProps): React.JSX.Element;