docusaurus-theme-openapi-docs 3.0.0-beta.1 → 3.0.0-beta.10
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/markdown/utils.d.ts +3 -2
- package/lib/markdown/utils.js +1 -1
- package/lib/markdown/utils.test.d.ts +1 -0
- package/lib/markdown/utils.test.js +43 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/index.d.ts +13 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/index.js +199 -124
- package/lib/theme/ApiExplorer/Accept/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.d.ts +4 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.js +25 -19
- package/lib/theme/ApiExplorer/ApiCodeBlock/Content/Element.d.ts +4 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/Content/Element.js +27 -16
- package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.d.ts +4 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.js +115 -96
- package/lib/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.d.ts +3 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.js +115 -54
- package/lib/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.d.ts +6 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.js +41 -30
- package/lib/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.d.ts +14 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.js +200 -120
- package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.d.ts +3 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.js +36 -24
- package/lib/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.d.ts +7 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.js +35 -28
- package/lib/theme/ApiExplorer/ApiCodeBlock/index.d.ts +3 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/index.js +72 -14
- package/lib/theme/ApiExplorer/Authorization/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/Authorization/slice.d.ts +1 -1
- package/lib/theme/ApiExplorer/Body/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/Body/index.js +8 -1
- package/lib/theme/ApiExplorer/Body/slice.d.ts +3 -3
- package/lib/theme/ApiExplorer/CodeSnippets/code-snippets-types.d.ts +21 -0
- package/lib/theme/ApiExplorer/CodeSnippets/code-snippets-types.js +8 -0
- package/lib/theme/ApiExplorer/CodeSnippets/index.d.ts +4 -14
- package/lib/theme/ApiExplorer/CodeSnippets/index.js +86 -8
- package/lib/theme/ApiExplorer/CodeSnippets/languages.d.ts +3 -0
- package/lib/theme/ApiExplorer/CodeSnippets/languages.js +48 -0
- package/lib/theme/ApiExplorer/CodeSnippets/languages.json +0 -96
- package/lib/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +18 -2
- package/lib/theme/ApiExplorer/CodeTabs/index.d.ts +15 -0
- package/lib/theme/ApiExplorer/CodeTabs/index.js +131 -76
- package/lib/theme/ApiExplorer/ContentType/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/Export/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/FloatingButton/_FloatingButton.scss +3 -1
- package/lib/theme/ApiExplorer/FloatingButton/index.d.ts +1 -1
- package/lib/theme/ApiExplorer/FormFileUpload/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/FormItem/index.d.ts +1 -1
- package/lib/theme/ApiExplorer/FormMultiSelect/index.d.ts +1 -1
- package/lib/theme/ApiExplorer/FormSelect/index.d.ts +1 -1
- package/lib/theme/ApiExplorer/FormTextInput/index.d.ts +1 -1
- package/lib/theme/ApiExplorer/MethodEndpoint/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.d.ts +2 -2
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.d.ts +2 -2
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.d.ts +2 -2
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.js +4 -4
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.d.ts +2 -2
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.d.ts +2 -2
- package/lib/theme/ApiExplorer/ParamOptions/_ParamOptions.scss +2 -1
- package/lib/theme/ApiExplorer/ParamOptions/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/ParamOptions/slice.d.ts +1 -1
- package/lib/theme/ApiExplorer/Request/_Request.scss +4 -2
- package/lib/theme/ApiExplorer/Request/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/Request/makeRequest.js +50 -1
- package/lib/theme/ApiExplorer/Response/_Response.scss +4 -2
- package/lib/theme/ApiExplorer/Response/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/Response/index.js +19 -19
- package/lib/theme/ApiExplorer/SecuritySchemes/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/Server/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/buildPostmanRequest.d.ts +1 -1
- package/lib/theme/ApiExplorer/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/index.js +1 -1
- package/lib/theme/ApiExplorer/storage-utils.d.ts +1 -1
- package/lib/theme/ApiItem/index.js +28 -3
- package/lib/theme/ApiItem/store.d.ts +6 -6
- package/lib/theme/ApiLogo/index.d.ts +2 -2
- package/lib/theme/ApiTabs/_ApiTabs.scss +3 -1
- package/lib/theme/ApiTabs/index.d.ts +7 -0
- package/lib/theme/ApiTabs/index.js +167 -103
- package/lib/theme/DiscriminatorTabs/index.d.ts +3 -0
- package/lib/theme/DiscriminatorTabs/index.js +152 -98
- package/lib/theme/Markdown/index.js +37 -0
- package/lib/theme/MimeTabs/index.d.ts +6 -0
- package/lib/theme/MimeTabs/index.js +169 -118
- package/lib/theme/OperationTabs/_OperationTabs.scss +71 -0
- package/lib/theme/OperationTabs/index.d.ts +3 -0
- package/lib/theme/OperationTabs/index.js +234 -0
- package/lib/theme/ParamsItem/index.d.ts +23 -0
- package/lib/theme/ParamsItem/index.js +170 -111
- package/lib/theme/ResponseSamples/index.d.ts +8 -0
- package/lib/theme/ResponseSamples/index.js +18 -13
- package/lib/theme/SchemaItem/index.d.ts +12 -0
- package/lib/theme/SchemaItem/index.js +121 -89
- package/lib/theme/SchemaTabs/_SchemaTabs.scss +0 -4
- package/lib/theme/SchemaTabs/index.d.ts +3 -0
- package/lib/theme/SchemaTabs/index.js +148 -95
- package/lib/theme/styles.scss +5 -0
- package/lib/types.d.ts +4 -4
- package/package.json +8 -7
- package/src/markdown/utils.test.ts +49 -0
- package/src/markdown/utils.ts +5 -3
- package/src/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/{index.js → index.tsx} +21 -8
- package/src/theme/ApiExplorer/ApiCodeBlock/Container/{index.js → index.tsx} +6 -3
- package/src/theme/ApiExplorer/ApiCodeBlock/Content/{Element.js → Element.tsx} +5 -1
- package/src/theme/ApiExplorer/ApiCodeBlock/Content/{String.js → String.tsx} +4 -4
- package/src/theme/ApiExplorer/ApiCodeBlock/CopyButton/{index.js → index.tsx} +8 -3
- package/src/theme/ApiExplorer/ApiCodeBlock/ExitButton/{index.js → index.tsx} +9 -1
- package/src/theme/ApiExplorer/ApiCodeBlock/ExpandButton/{index.js → index.tsx} +12 -2
- package/src/theme/ApiExplorer/ApiCodeBlock/Line/{index.js → index.tsx} +2 -1
- package/src/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/{index.js → index.tsx} +11 -1
- package/src/theme/ApiExplorer/ApiCodeBlock/{index.js → index.tsx} +10 -5
- package/src/theme/ApiExplorer/Body/index.tsx +3 -1
- package/src/theme/ApiExplorer/CodeSnippets/code-snippets-types.ts +55 -0
- package/src/theme/ApiExplorer/CodeSnippets/index.tsx +94 -21
- package/src/theme/ApiExplorer/CodeSnippets/languages.json +0 -96
- package/src/theme/ApiExplorer/CodeSnippets/languages.ts +53 -0
- package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +18 -2
- package/src/theme/ApiExplorer/CodeTabs/{index.js → index.tsx} +64 -25
- package/src/theme/ApiExplorer/FloatingButton/_FloatingButton.scss +3 -1
- package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx +4 -4
- package/src/theme/ApiExplorer/ParamOptions/_ParamOptions.scss +2 -1
- package/src/theme/ApiExplorer/Request/_Request.scss +4 -2
- package/src/theme/ApiExplorer/Request/makeRequest.ts +59 -4
- package/src/theme/ApiExplorer/Response/_Response.scss +4 -2
- package/src/theme/ApiExplorer/Response/index.tsx +2 -2
- package/src/theme/ApiExplorer/index.tsx +1 -1
- package/src/theme/ApiItem/index.tsx +22 -3
- package/src/theme/ApiLogo/index.tsx +1 -1
- package/src/theme/ApiTabs/_ApiTabs.scss +3 -1
- package/src/theme/ApiTabs/{index.js → index.tsx} +75 -31
- package/src/theme/DiscriminatorTabs/{index.js → index.tsx} +63 -28
- package/src/theme/Markdown/index.js +37 -0
- package/src/theme/MimeTabs/{index.js → index.tsx} +64 -30
- package/src/theme/OperationTabs/_OperationTabs.scss +71 -0
- package/src/theme/OperationTabs/index.tsx +218 -0
- package/src/theme/ParamsItem/{index.js → index.tsx} +48 -17
- package/src/theme/ResponseSamples/{index.js → index.tsx} +10 -1
- package/src/theme/SchemaItem/{index.js → index.tsx} +24 -18
- package/src/theme/SchemaTabs/_SchemaTabs.scss +0 -4
- package/src/theme/SchemaTabs/{index.js → index.tsx} +62 -29
- package/src/theme/styles.scss +5 -0
- package/src/theme-classic.d.ts +69 -2
- package/src/theme-openapi.d.ts +6 -0
- package/tsconfig.json +4 -1
|
@@ -14,9 +14,19 @@ import CopyButton from "@theme/ApiExplorer/ApiCodeBlock/CopyButton";
|
|
|
14
14
|
import ExitButton from "@theme/ApiExplorer/ApiCodeBlock/ExitButton";
|
|
15
15
|
import Line from "@theme/ApiExplorer/ApiCodeBlock/Line";
|
|
16
16
|
import clsx from "clsx";
|
|
17
|
-
import { Highlight } from "prism-react-renderer";
|
|
17
|
+
import { Highlight, Language } from "prism-react-renderer";
|
|
18
18
|
import Modal from "react-modal";
|
|
19
19
|
|
|
20
|
+
export interface Props {
|
|
21
|
+
readonly code: string;
|
|
22
|
+
readonly className: string;
|
|
23
|
+
readonly language: Language;
|
|
24
|
+
readonly showLineNumbers: boolean;
|
|
25
|
+
readonly blockClassName: string;
|
|
26
|
+
readonly title: string | undefined;
|
|
27
|
+
readonly lineClassNames: { [lineIndex: number]: string[] };
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
export default function ExpandButton({
|
|
21
31
|
code,
|
|
22
32
|
className,
|
|
@@ -25,7 +35,7 @@ export default function ExpandButton({
|
|
|
25
35
|
blockClassName,
|
|
26
36
|
title,
|
|
27
37
|
lineClassNames,
|
|
28
|
-
}) {
|
|
38
|
+
}: Props): React.JSX.Element {
|
|
29
39
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
30
40
|
const prismTheme = usePrismTheme();
|
|
31
41
|
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import React from "react";
|
|
9
9
|
|
|
10
|
+
import { LineProps } from "@docusaurus/theme-common/internal";
|
|
10
11
|
import clsx from "clsx";
|
|
11
12
|
|
|
12
13
|
export default function CodeBlockLine({
|
|
@@ -15,7 +16,7 @@ export default function CodeBlockLine({
|
|
|
15
16
|
showLineNumbers,
|
|
16
17
|
getLineProps,
|
|
17
18
|
getTokenProps,
|
|
18
|
-
}) {
|
|
19
|
+
}: LineProps): React.JSX.Element {
|
|
19
20
|
if (line.length === 1 && line[0].content === "\n") {
|
|
20
21
|
line[0].content = "";
|
|
21
22
|
}
|
|
@@ -10,7 +10,17 @@ import React from "react";
|
|
|
10
10
|
import { translate } from "@docusaurus/Translate";
|
|
11
11
|
import clsx from "clsx";
|
|
12
12
|
|
|
13
|
-
export
|
|
13
|
+
export interface Props {
|
|
14
|
+
readonly className?: string;
|
|
15
|
+
readonly onClick: React.MouseEventHandler;
|
|
16
|
+
readonly isEnabled: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default function WordWrapButton({
|
|
20
|
+
className,
|
|
21
|
+
onClick,
|
|
22
|
+
isEnabled,
|
|
23
|
+
}: Props): React.JSX.Element | null {
|
|
14
24
|
const title = translate({
|
|
15
25
|
id: "theme.CodeBlock.wordWrapToggle",
|
|
16
26
|
message: "Toggle word wrap",
|
|
@@ -5,25 +5,30 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import React, { isValidElement } from "react";
|
|
8
|
+
import React, { isValidElement, ReactNode } from "react";
|
|
9
9
|
|
|
10
|
+
import { CodeBlockProps } from "@docusaurus/theme-common/internal";
|
|
10
11
|
import useIsBrowser from "@docusaurus/useIsBrowser";
|
|
11
12
|
import ElementContent from "@theme/ApiExplorer/ApiCodeBlock/Content/Element";
|
|
12
13
|
import StringContent from "@theme/ApiExplorer/ApiCodeBlock/Content/String";
|
|
14
|
+
|
|
13
15
|
/**
|
|
14
16
|
* Best attempt to make the children a plain string so it is copyable. If there
|
|
15
17
|
* are react elements, we will not be able to copy the content, and it will
|
|
16
18
|
* return `children` as-is; otherwise, it concatenates the string children
|
|
17
19
|
* together.
|
|
18
20
|
*/
|
|
19
|
-
function maybeStringifyChildren(children) {
|
|
21
|
+
function maybeStringifyChildren(children: ReactNode): ReactNode {
|
|
20
22
|
if (React.Children.toArray(children).some((el) => isValidElement(el))) {
|
|
21
23
|
return children;
|
|
22
24
|
}
|
|
23
25
|
// The children is now guaranteed to be one/more plain strings
|
|
24
|
-
return Array.isArray(children) ? children.join("") : children;
|
|
26
|
+
return Array.isArray(children) ? children.join("") : (children as string);
|
|
25
27
|
}
|
|
26
|
-
export default function ApiCodeBlock({
|
|
28
|
+
export default function ApiCodeBlock({
|
|
29
|
+
children: rawChildren,
|
|
30
|
+
...props
|
|
31
|
+
}: CodeBlockProps) {
|
|
27
32
|
// The Prism theme on SSR is always the default theme but the site theme can
|
|
28
33
|
// be in a different mode. React hydration doesn't update DOM styles that come
|
|
29
34
|
// from SSR. Hence force a re-render after mounting to apply the current
|
|
@@ -34,7 +39,7 @@ export default function ApiCodeBlock({ children: rawChildren, ...props }) {
|
|
|
34
39
|
typeof children === "string" ? StringContent : ElementContent;
|
|
35
40
|
return (
|
|
36
41
|
<CodeBlockComp key={String(isBrowser)} {...props}>
|
|
37
|
-
{children}
|
|
42
|
+
{children as string}
|
|
38
43
|
</CodeBlockComp>
|
|
39
44
|
);
|
|
40
45
|
}
|
|
@@ -14,6 +14,7 @@ import FormSelect from "@theme/ApiExplorer/FormSelect";
|
|
|
14
14
|
import FormTextInput from "@theme/ApiExplorer/FormTextInput";
|
|
15
15
|
import LiveApp from "@theme/ApiExplorer/LiveEditor";
|
|
16
16
|
import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
|
|
17
|
+
import Markdown from "@theme/Markdown";
|
|
17
18
|
import SchemaTabs from "@theme/SchemaTabs";
|
|
18
19
|
import TabItem from "@theme/TabItem";
|
|
19
20
|
import { RequestBodyObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
|
|
@@ -303,6 +304,7 @@ function Body({
|
|
|
303
304
|
</TabItem>
|
|
304
305
|
{/* @ts-ignore */}
|
|
305
306
|
<TabItem label="Example" value="example">
|
|
307
|
+
{example.summary && <Markdown children={example.summary} />}
|
|
306
308
|
{exampleBody && (
|
|
307
309
|
<LiveApp
|
|
308
310
|
action={dispatch}
|
|
@@ -340,7 +342,7 @@ function Body({
|
|
|
340
342
|
value={example.label}
|
|
341
343
|
key={example.label}
|
|
342
344
|
>
|
|
343
|
-
{example.summary && <
|
|
345
|
+
{example.summary && <Markdown children={example.summary} />}
|
|
344
346
|
{example.body && (
|
|
345
347
|
<LiveApp action={dispatch} language={language}>
|
|
346
348
|
{example.body}
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
// https://github.com/github-linguist/linguist/blob/master/lib/linguist/popular.yml
|
|
9
|
+
export type CodeSampleLanguage =
|
|
10
|
+
| "C"
|
|
11
|
+
| "C#"
|
|
12
|
+
| "C++"
|
|
13
|
+
| "CoffeeScript"
|
|
14
|
+
| "CSS"
|
|
15
|
+
| "Dart"
|
|
16
|
+
| "DM"
|
|
17
|
+
| "Elixir"
|
|
18
|
+
| "Go"
|
|
19
|
+
| "Groovy"
|
|
20
|
+
| "HTML"
|
|
21
|
+
| "Java"
|
|
22
|
+
| "JavaScript"
|
|
23
|
+
| "Kotlin"
|
|
24
|
+
| "Objective-C"
|
|
25
|
+
| "Perl"
|
|
26
|
+
| "PHP"
|
|
27
|
+
| "PowerShell"
|
|
28
|
+
| "Python"
|
|
29
|
+
| "Ruby"
|
|
30
|
+
| "Rust"
|
|
31
|
+
| "Scala"
|
|
32
|
+
| "Shell"
|
|
33
|
+
| "Swift"
|
|
34
|
+
| "TypeScript";
|
|
35
|
+
|
|
36
|
+
export interface Language {
|
|
37
|
+
highlight: string;
|
|
38
|
+
language: string;
|
|
39
|
+
codeSampleLanguage: CodeSampleLanguage;
|
|
40
|
+
logoClass: string;
|
|
41
|
+
variant: string;
|
|
42
|
+
variants: string[];
|
|
43
|
+
options?: { [key: string]: boolean };
|
|
44
|
+
sample?: string;
|
|
45
|
+
samples?: string[];
|
|
46
|
+
samplesSources?: string[];
|
|
47
|
+
samplesLabels?: string[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// https://redocly.com/docs/api-reference-docs/specification-extensions/x-code-samples
|
|
51
|
+
export interface CodeSample {
|
|
52
|
+
source: string;
|
|
53
|
+
lang: CodeSampleLanguage;
|
|
54
|
+
label?: string;
|
|
55
|
+
}
|
|
@@ -16,20 +16,17 @@ import CodeTabs from "@theme/ApiExplorer/CodeTabs";
|
|
|
16
16
|
import { useTypedSelector } from "@theme/ApiItem/hooks";
|
|
17
17
|
import merge from "lodash/merge";
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
variants: string[];
|
|
25
|
-
options: { [key: string]: boolean };
|
|
26
|
-
source?: string;
|
|
27
|
-
}
|
|
19
|
+
import { CodeSample, Language } from "./code-snippets-types";
|
|
20
|
+
import {
|
|
21
|
+
getCodeSampleSourceFromLanguage,
|
|
22
|
+
mergeCodeSampleLanguage,
|
|
23
|
+
} from "./languages";
|
|
28
24
|
|
|
29
25
|
export const languageSet: Language[] = [
|
|
30
26
|
{
|
|
31
27
|
highlight: "bash",
|
|
32
28
|
language: "curl",
|
|
29
|
+
codeSampleLanguage: "Shell",
|
|
33
30
|
logoClass: "bash",
|
|
34
31
|
options: {
|
|
35
32
|
longFormat: false,
|
|
@@ -42,6 +39,7 @@ export const languageSet: Language[] = [
|
|
|
42
39
|
{
|
|
43
40
|
highlight: "python",
|
|
44
41
|
language: "python",
|
|
42
|
+
codeSampleLanguage: "Python",
|
|
45
43
|
logoClass: "python",
|
|
46
44
|
options: {
|
|
47
45
|
followRedirect: true,
|
|
@@ -53,6 +51,7 @@ export const languageSet: Language[] = [
|
|
|
53
51
|
{
|
|
54
52
|
highlight: "go",
|
|
55
53
|
language: "go",
|
|
54
|
+
codeSampleLanguage: "Go",
|
|
56
55
|
logoClass: "go",
|
|
57
56
|
options: {
|
|
58
57
|
followRedirect: true,
|
|
@@ -64,6 +63,7 @@ export const languageSet: Language[] = [
|
|
|
64
63
|
{
|
|
65
64
|
highlight: "javascript",
|
|
66
65
|
language: "nodejs",
|
|
66
|
+
codeSampleLanguage: "JavaScript",
|
|
67
67
|
logoClass: "nodejs",
|
|
68
68
|
options: {
|
|
69
69
|
ES6_enabled: true,
|
|
@@ -71,11 +71,12 @@ export const languageSet: Language[] = [
|
|
|
71
71
|
trimRequestBody: true,
|
|
72
72
|
},
|
|
73
73
|
variant: "axios",
|
|
74
|
-
variants: ["axios", "native"
|
|
74
|
+
variants: ["axios", "native"],
|
|
75
75
|
},
|
|
76
76
|
{
|
|
77
77
|
highlight: "ruby",
|
|
78
78
|
language: "ruby",
|
|
79
|
+
codeSampleLanguage: "Ruby",
|
|
79
80
|
logoClass: "ruby",
|
|
80
81
|
options: {
|
|
81
82
|
followRedirect: true,
|
|
@@ -87,6 +88,7 @@ export const languageSet: Language[] = [
|
|
|
87
88
|
{
|
|
88
89
|
highlight: "csharp",
|
|
89
90
|
language: "csharp",
|
|
91
|
+
codeSampleLanguage: "C#",
|
|
90
92
|
logoClass: "csharp",
|
|
91
93
|
options: {
|
|
92
94
|
followRedirect: true,
|
|
@@ -98,6 +100,7 @@ export const languageSet: Language[] = [
|
|
|
98
100
|
{
|
|
99
101
|
highlight: "php",
|
|
100
102
|
language: "php",
|
|
103
|
+
codeSampleLanguage: "PHP",
|
|
101
104
|
logoClass: "php",
|
|
102
105
|
options: {
|
|
103
106
|
followRedirect: true,
|
|
@@ -109,6 +112,7 @@ export const languageSet: Language[] = [
|
|
|
109
112
|
{
|
|
110
113
|
highlight: "java",
|
|
111
114
|
language: "java",
|
|
115
|
+
codeSampleLanguage: "Java",
|
|
112
116
|
logoClass: "java",
|
|
113
117
|
options: {
|
|
114
118
|
followRedirect: true,
|
|
@@ -120,6 +124,7 @@ export const languageSet: Language[] = [
|
|
|
120
124
|
{
|
|
121
125
|
highlight: "powershell",
|
|
122
126
|
language: "powershell",
|
|
127
|
+
codeSampleLanguage: "PowerShell",
|
|
123
128
|
logoClass: "powershell",
|
|
124
129
|
options: {
|
|
125
130
|
followRedirect: true,
|
|
@@ -132,10 +137,10 @@ export const languageSet: Language[] = [
|
|
|
132
137
|
|
|
133
138
|
export interface Props {
|
|
134
139
|
postman: sdk.Request;
|
|
135
|
-
codeSamples:
|
|
140
|
+
codeSamples: CodeSample[];
|
|
136
141
|
}
|
|
137
142
|
|
|
138
|
-
function CodeTab({ children, hidden, className
|
|
143
|
+
function CodeTab({ children, hidden, className }: any): JSX.Element {
|
|
139
144
|
return (
|
|
140
145
|
<div role="tabpanel" className={className} {...{ hidden }}>
|
|
141
146
|
{children}
|
|
@@ -165,7 +170,6 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
165
170
|
const langs = [
|
|
166
171
|
...((siteConfig?.themeConfig?.languageTabs as Language[] | undefined) ??
|
|
167
172
|
languageSet),
|
|
168
|
-
...codeSamples,
|
|
169
173
|
];
|
|
170
174
|
|
|
171
175
|
// Filter languageSet by user-defined langs
|
|
@@ -176,14 +180,18 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
176
180
|
});
|
|
177
181
|
|
|
178
182
|
// Merge user-defined langs into languageSet
|
|
179
|
-
const mergedLangs =
|
|
183
|
+
const mergedLangs = mergeCodeSampleLanguage(
|
|
184
|
+
merge(filteredLanguageSet, langs),
|
|
185
|
+
codeSamples
|
|
186
|
+
);
|
|
180
187
|
|
|
181
188
|
// Read defaultLang from localStorage
|
|
182
189
|
const defaultLang: Language[] = mergedLangs.filter(
|
|
183
190
|
(lang) =>
|
|
184
191
|
lang.language === localStorage.getItem("docusaurus.tab.code-samples")
|
|
185
192
|
);
|
|
186
|
-
const [selectedVariant, setSelectedVariant] = useState();
|
|
193
|
+
const [selectedVariant, setSelectedVariant] = useState<string | undefined>();
|
|
194
|
+
const [selectedSample, setSelectedSample] = useState<string | undefined>();
|
|
187
195
|
const [language, setLanguage] = useState(() => {
|
|
188
196
|
// Return first index if only 1 user-defined language exists
|
|
189
197
|
if (mergedLangs.length === 1) {
|
|
@@ -192,9 +200,16 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
192
200
|
// Fall back to language in localStorage or first user-defined language
|
|
193
201
|
return defaultLang[0] ?? mergedLangs[0];
|
|
194
202
|
});
|
|
195
|
-
const [codeText, setCodeText] = useState("");
|
|
203
|
+
const [codeText, setCodeText] = useState<string>("");
|
|
204
|
+
const [codeSampleCodeText, setCodeSampleCodeText] = useState<
|
|
205
|
+
string | (() => string)
|
|
206
|
+
>(() => getCodeSampleSourceFromLanguage(language));
|
|
196
207
|
|
|
197
208
|
useEffect(() => {
|
|
209
|
+
if (language && !!language.sample) {
|
|
210
|
+
setCodeSampleCodeText(getCodeSampleSourceFromLanguage(language));
|
|
211
|
+
}
|
|
212
|
+
|
|
198
213
|
if (language && !!language.options) {
|
|
199
214
|
const postmanRequest = buildPostmanRequest(postman, {
|
|
200
215
|
queryParams,
|
|
@@ -219,8 +234,6 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
219
234
|
setCodeText(snippet);
|
|
220
235
|
}
|
|
221
236
|
);
|
|
222
|
-
} else if (language && !!language.source) {
|
|
223
|
-
setCodeText(language.source);
|
|
224
237
|
} else if (language && !language.options) {
|
|
225
238
|
const langSource = mergedLangs.filter(
|
|
226
239
|
(lang) => lang.language === language.language
|
|
@@ -271,8 +284,8 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
271
284
|
auth,
|
|
272
285
|
mergedLangs,
|
|
273
286
|
]);
|
|
274
|
-
|
|
275
|
-
useEffect(()
|
|
287
|
+
// no dependencies was intentionlly set for this particular hook. it's safe as long as if conditions are set
|
|
288
|
+
useEffect(function onSelectedVariantUpdate() {
|
|
276
289
|
if (selectedVariant && selectedVariant !== language.variant) {
|
|
277
290
|
const postmanRequest = buildPostmanRequest(postman, {
|
|
278
291
|
queryParams,
|
|
@@ -300,6 +313,22 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
300
313
|
}
|
|
301
314
|
});
|
|
302
315
|
|
|
316
|
+
// no dependencies was intentionlly set for this particular hook. it's safe as long as if conditions are set
|
|
317
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
318
|
+
useEffect(function onSelectedSampleUpdate() {
|
|
319
|
+
if (
|
|
320
|
+
language.samples &&
|
|
321
|
+
language.samplesSources &&
|
|
322
|
+
selectedSample &&
|
|
323
|
+
selectedSample !== language.sample
|
|
324
|
+
) {
|
|
325
|
+
const sampleIndex = language.samples.findIndex(
|
|
326
|
+
(smp) => smp === selectedSample
|
|
327
|
+
);
|
|
328
|
+
setCodeSampleCodeText(language.samplesSources[sampleIndex]);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
|
|
303
332
|
if (language === undefined) {
|
|
304
333
|
return null;
|
|
305
334
|
}
|
|
@@ -311,7 +340,9 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
311
340
|
action={{
|
|
312
341
|
setLanguage: setLanguage,
|
|
313
342
|
setSelectedVariant: setSelectedVariant,
|
|
343
|
+
setSelectedSample: setSelectedSample,
|
|
314
344
|
}}
|
|
345
|
+
languageSet={mergedLangs}
|
|
315
346
|
lazy
|
|
316
347
|
>
|
|
317
348
|
{mergedLangs.map((lang) => {
|
|
@@ -324,6 +355,47 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
324
355
|
className: `openapi-tabs__code-item--${lang.logoClass}`,
|
|
325
356
|
}}
|
|
326
357
|
>
|
|
358
|
+
{lang.samples && (
|
|
359
|
+
<CodeTabs
|
|
360
|
+
className="openapi-tabs__code-container-inner"
|
|
361
|
+
action={{
|
|
362
|
+
setLanguage: setLanguage,
|
|
363
|
+
setSelectedSample: setSelectedSample,
|
|
364
|
+
}}
|
|
365
|
+
includeSample={true}
|
|
366
|
+
currentLanguage={lang.language}
|
|
367
|
+
defaultValue={selectedSample}
|
|
368
|
+
languageSet={mergedLangs}
|
|
369
|
+
lazy
|
|
370
|
+
>
|
|
371
|
+
{lang.samples.map((sample, index) => {
|
|
372
|
+
return (
|
|
373
|
+
<CodeTab
|
|
374
|
+
value={sample}
|
|
375
|
+
label={
|
|
376
|
+
lang.samplesLabels
|
|
377
|
+
? lang.samplesLabels[index]
|
|
378
|
+
: sample
|
|
379
|
+
}
|
|
380
|
+
key={`${lang.language}-${lang.sample}`}
|
|
381
|
+
attributes={{
|
|
382
|
+
className: `openapi-tabs__code-item--sample`,
|
|
383
|
+
}}
|
|
384
|
+
>
|
|
385
|
+
{/* @ts-ignore */}
|
|
386
|
+
<ApiCodeBlock
|
|
387
|
+
language={lang.highlight}
|
|
388
|
+
className="openapi-explorer__code-block"
|
|
389
|
+
showLineNumbers={true}
|
|
390
|
+
>
|
|
391
|
+
{codeSampleCodeText}
|
|
392
|
+
</ApiCodeBlock>
|
|
393
|
+
</CodeTab>
|
|
394
|
+
);
|
|
395
|
+
})}
|
|
396
|
+
</CodeTabs>
|
|
397
|
+
)}
|
|
398
|
+
|
|
327
399
|
<CodeTabs
|
|
328
400
|
className="openapi-tabs__code-container-inner"
|
|
329
401
|
action={{
|
|
@@ -333,9 +405,10 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
333
405
|
includeVariant={true}
|
|
334
406
|
currentLanguage={lang.language}
|
|
335
407
|
defaultValue={selectedVariant}
|
|
408
|
+
languageSet={mergedLangs}
|
|
336
409
|
lazy
|
|
337
410
|
>
|
|
338
|
-
{lang.variants.map((variant) => {
|
|
411
|
+
{lang.variants.map((variant, index) => {
|
|
339
412
|
return (
|
|
340
413
|
<CodeTab
|
|
341
414
|
value={variant.toLowerCase()}
|
|
@@ -635,102 +635,6 @@
|
|
|
635
635
|
"description": "Modifies code snippet to incorporate ES6 (EcmaScript) features"
|
|
636
636
|
}
|
|
637
637
|
]
|
|
638
|
-
},
|
|
639
|
-
{
|
|
640
|
-
"key": "Request",
|
|
641
|
-
"options": [
|
|
642
|
-
{
|
|
643
|
-
"name": "Set indentation count",
|
|
644
|
-
"id": "indentCount",
|
|
645
|
-
"type": "positiveInteger",
|
|
646
|
-
"default": 2,
|
|
647
|
-
"description": "Set the number of indentation characters to add per code level"
|
|
648
|
-
},
|
|
649
|
-
{
|
|
650
|
-
"name": "Set indentation type",
|
|
651
|
-
"id": "indentType",
|
|
652
|
-
"type": "enum",
|
|
653
|
-
"availableOptions": ["Tab", "Space"],
|
|
654
|
-
"default": "Space",
|
|
655
|
-
"description": "Select the character used to indent lines of code"
|
|
656
|
-
},
|
|
657
|
-
{
|
|
658
|
-
"name": "Set request timeout",
|
|
659
|
-
"id": "requestTimeout",
|
|
660
|
-
"type": "positiveInteger",
|
|
661
|
-
"default": 0,
|
|
662
|
-
"description": "Set number of milliseconds the request should wait for a response before timing out (use 0 for infinity)"
|
|
663
|
-
},
|
|
664
|
-
{
|
|
665
|
-
"name": "Follow redirects",
|
|
666
|
-
"id": "followRedirect",
|
|
667
|
-
"type": "boolean",
|
|
668
|
-
"default": true,
|
|
669
|
-
"description": "Automatically follow HTTP redirects"
|
|
670
|
-
},
|
|
671
|
-
{
|
|
672
|
-
"name": "Trim request body fields",
|
|
673
|
-
"id": "trimRequestBody",
|
|
674
|
-
"type": "boolean",
|
|
675
|
-
"default": false,
|
|
676
|
-
"description": "Remove white space and additional lines that may affect the server's response"
|
|
677
|
-
},
|
|
678
|
-
{
|
|
679
|
-
"name": "Enable ES6 features",
|
|
680
|
-
"id": "ES6_enabled",
|
|
681
|
-
"type": "boolean",
|
|
682
|
-
"default": false,
|
|
683
|
-
"description": "Modifies code snippet to incorporate ES6 (EcmaScript) features"
|
|
684
|
-
}
|
|
685
|
-
]
|
|
686
|
-
},
|
|
687
|
-
{
|
|
688
|
-
"key": "Unirest",
|
|
689
|
-
"options": [
|
|
690
|
-
{
|
|
691
|
-
"name": "Set indentation count",
|
|
692
|
-
"id": "indentCount",
|
|
693
|
-
"type": "positiveInteger",
|
|
694
|
-
"default": 2,
|
|
695
|
-
"description": "Set the number of indentation characters to add per code level"
|
|
696
|
-
},
|
|
697
|
-
{
|
|
698
|
-
"name": "Set indentation type",
|
|
699
|
-
"id": "indentType",
|
|
700
|
-
"type": "enum",
|
|
701
|
-
"availableOptions": ["Tab", "Space"],
|
|
702
|
-
"default": "Space",
|
|
703
|
-
"description": "Select the character used to indent lines of code"
|
|
704
|
-
},
|
|
705
|
-
{
|
|
706
|
-
"name": "Set request timeout",
|
|
707
|
-
"id": "requestTimeout",
|
|
708
|
-
"type": "positiveInteger",
|
|
709
|
-
"default": 0,
|
|
710
|
-
"description": "Set number of milliseconds the request should wait for a response before timing out (use 0 for infinity)"
|
|
711
|
-
},
|
|
712
|
-
{
|
|
713
|
-
"name": "Follow redirects",
|
|
714
|
-
"id": "followRedirect",
|
|
715
|
-
"type": "boolean",
|
|
716
|
-
"default": true,
|
|
717
|
-
"description": "Automatically follow HTTP redirects"
|
|
718
|
-
},
|
|
719
|
-
{
|
|
720
|
-
"name": "Trim request body fields",
|
|
721
|
-
"id": "trimRequestBody",
|
|
722
|
-
"type": "boolean",
|
|
723
|
-
"default": false,
|
|
724
|
-
"description": "Remove white space and additional lines that may affect the server's response"
|
|
725
|
-
},
|
|
726
|
-
{
|
|
727
|
-
"name": "Enable ES6 features",
|
|
728
|
-
"id": "ES6_enabled",
|
|
729
|
-
"type": "boolean",
|
|
730
|
-
"default": false,
|
|
731
|
-
"description": "Modifies code snippet to incorporate ES6 (EcmaScript) features"
|
|
732
|
-
}
|
|
733
|
-
]
|
|
734
638
|
}
|
|
735
639
|
]
|
|
736
640
|
},
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
import { CodeSample, Language } from "./code-snippets-types";
|
|
9
|
+
|
|
10
|
+
export function mergeCodeSampleLanguage(
|
|
11
|
+
languages: Language[],
|
|
12
|
+
codeSamples: CodeSample[]
|
|
13
|
+
): Language[] {
|
|
14
|
+
return languages.map((language) => {
|
|
15
|
+
const languageCodeSamples = codeSamples.filter(
|
|
16
|
+
({ lang }) => lang === language.codeSampleLanguage
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
if (languageCodeSamples.length) {
|
|
20
|
+
const samples = languageCodeSamples.map(({ lang }) => lang);
|
|
21
|
+
const samplesLabels = languageCodeSamples.map(
|
|
22
|
+
({ label, lang }) => label || lang
|
|
23
|
+
);
|
|
24
|
+
const samplesSources = languageCodeSamples.map(({ source }) => source);
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
...language,
|
|
28
|
+
sample: samples[0],
|
|
29
|
+
samples,
|
|
30
|
+
samplesSources,
|
|
31
|
+
samplesLabels,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return language;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getCodeSampleSourceFromLanguage(language: Language) {
|
|
40
|
+
if (
|
|
41
|
+
language &&
|
|
42
|
+
language.sample &&
|
|
43
|
+
language.samples &&
|
|
44
|
+
language.samplesSources
|
|
45
|
+
) {
|
|
46
|
+
const sampleIndex = language.samples.findIndex(
|
|
47
|
+
(smp) => smp === language.sample
|
|
48
|
+
);
|
|
49
|
+
return language.samplesSources[sampleIndex];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
@@ -18,12 +18,14 @@
|
|
|
18
18
|
background-color: var(--ifm-pre-background);
|
|
19
19
|
border-radius: var(--ifm-global-radius);
|
|
20
20
|
border: 1px solid var(--openapi-explorer-border-color);
|
|
21
|
-
box-shadow:
|
|
21
|
+
box-shadow:
|
|
22
|
+
0 2px 3px hsla(222, 8%, 43%, 0.1),
|
|
22
23
|
0 8px 16px -10px hsla(222, 8%, 43%, 0.2);
|
|
23
24
|
transition: 300ms;
|
|
24
25
|
|
|
25
26
|
&:hover {
|
|
26
|
-
box-shadow:
|
|
27
|
+
box-shadow:
|
|
28
|
+
0 0 0 2px rgba(38, 53, 61, 0.15),
|
|
27
29
|
0 2px 3px hsla(222, 8%, 43%, 0.15),
|
|
28
30
|
0 16px 16px -10px hsla(222, 8%, 43%, 0.2);
|
|
29
31
|
}
|
|
@@ -94,6 +96,20 @@ body[class="ReactModal__Body--open"] {
|
|
|
94
96
|
padding-right: 0.5rem !important;
|
|
95
97
|
}
|
|
96
98
|
|
|
99
|
+
.openapi-tabs__code-item--sample {
|
|
100
|
+
color: var(--ifm-color-secondary);
|
|
101
|
+
|
|
102
|
+
&.active {
|
|
103
|
+
border-color: var(--ifm-toc-border-color);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.openapi-tabs__code-item--sample > span {
|
|
108
|
+
padding-top: unset !important;
|
|
109
|
+
padding-left: 0.5rem !important;
|
|
110
|
+
padding-right: 0.5rem !important;
|
|
111
|
+
}
|
|
112
|
+
|
|
97
113
|
.openapi-tabs__code-item--python {
|
|
98
114
|
color: var(--ifm-color-success);
|
|
99
115
|
|