docusaurus-theme-openapi-docs 4.5.1 → 4.7.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 (133) hide show
  1. package/lib/markdown/schema.js +14 -1
  2. package/lib/theme/ApiExplorer/Accept/slice.d.ts +5 -2
  3. package/lib/theme/ApiExplorer/Authorization/index.js +50 -9
  4. package/lib/theme/ApiExplorer/Authorization/slice.d.ts +145 -3
  5. package/lib/theme/ApiExplorer/Authorization/slice.js +3 -1
  6. package/lib/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.d.ts +7 -0
  7. package/lib/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.js +126 -0
  8. package/lib/theme/ApiExplorer/Body/FormBodyItem/index.d.ts +9 -0
  9. package/lib/theme/ApiExplorer/Body/FormBodyItem/index.js +110 -0
  10. package/lib/theme/ApiExplorer/Body/index.js +322 -193
  11. package/lib/theme/ApiExplorer/Body/resolveSchemaWithSelections.d.ts +13 -0
  12. package/lib/theme/ApiExplorer/Body/resolveSchemaWithSelections.js +133 -0
  13. package/lib/theme/ApiExplorer/Body/slice.d.ts +1056 -11
  14. package/lib/theme/ApiExplorer/Body/slice.js +22 -2
  15. package/lib/theme/ApiExplorer/CodeSnippets/index.d.ts +2 -1
  16. package/lib/theme/ApiExplorer/CodeSnippets/index.js +37 -26
  17. package/lib/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +5 -1
  18. package/lib/theme/ApiExplorer/CodeTabs/index.d.ts +3 -3
  19. package/lib/theme/ApiExplorer/CodeTabs/index.js +2 -2
  20. package/lib/theme/ApiExplorer/ContentType/slice.d.ts +5 -2
  21. package/lib/theme/ApiExplorer/FormFileUpload/index.js +6 -1
  22. package/lib/theme/ApiExplorer/FormItem/index.js +6 -1
  23. package/lib/theme/ApiExplorer/FormTextInput/index.d.ts +2 -0
  24. package/lib/theme/ApiExplorer/FormTextInput/index.js +8 -1
  25. package/lib/theme/ApiExplorer/LiveEditor/index.js +11 -4
  26. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.js +15 -5
  27. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.js +11 -3
  28. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.js +12 -4
  29. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.js +11 -2
  30. package/lib/theme/ApiExplorer/ParamOptions/index.js +11 -1
  31. package/lib/theme/ApiExplorer/ParamOptions/slice.d.ts +0 -4
  32. package/lib/theme/ApiExplorer/ParamOptions/slice.js +4 -4
  33. package/lib/theme/ApiExplorer/Request/index.js +110 -17
  34. package/lib/theme/ApiExplorer/Request/makeRequest.d.ts +7 -1
  35. package/lib/theme/ApiExplorer/Request/makeRequest.js +94 -24
  36. package/lib/theme/ApiExplorer/Response/index.js +34 -14
  37. package/lib/theme/ApiExplorer/Response/slice.d.ts +31 -7
  38. package/lib/theme/ApiExplorer/SchemaSelection/index.d.ts +2 -0
  39. package/lib/theme/ApiExplorer/SchemaSelection/index.js +36 -0
  40. package/lib/theme/ApiExplorer/SchemaSelection/slice.d.ts +37 -0
  41. package/lib/theme/ApiExplorer/SchemaSelection/slice.js +39 -0
  42. package/lib/theme/ApiExplorer/SecuritySchemes/index.js +208 -69
  43. package/lib/theme/ApiExplorer/Server/index.js +16 -2
  44. package/lib/theme/ApiExplorer/Server/slice.d.ts +49 -3
  45. package/lib/theme/ApiExplorer/buildPostmanRequest.js +46 -57
  46. package/lib/theme/ApiExplorer/index.js +4 -0
  47. package/lib/theme/ApiExplorer/persistenceMiddleware.d.ts +21 -0
  48. package/lib/theme/ApiExplorer/{persistanceMiddleware.js → persistenceMiddleware.js} +16 -9
  49. package/lib/theme/ApiExplorer/storage-utils.d.ts +2 -2
  50. package/lib/theme/ApiExplorer/storage-utils.js +3 -3
  51. package/lib/theme/ApiItem/Layout/index.d.ts +1 -1
  52. package/lib/theme/ApiItem/hooks.d.ts +10 -9
  53. package/lib/theme/ApiItem/index.js +13 -8
  54. package/lib/theme/ApiItem/store.d.ts +61 -43
  55. package/lib/theme/ApiItem/store.js +6 -2
  56. package/lib/theme/ApiTabs/index.js +6 -1
  57. package/lib/theme/Example/_Example.scss +11 -0
  58. package/lib/theme/Example/index.d.ts +24 -0
  59. package/lib/theme/Example/index.js +170 -0
  60. package/lib/theme/ParamsDetails/index.js +9 -1
  61. package/lib/theme/ParamsItem/index.d.ts +1 -1
  62. package/lib/theme/ParamsItem/index.js +43 -74
  63. package/lib/theme/RequestSchema/index.js +68 -48
  64. package/lib/theme/ResponseExamples/index.js +23 -3
  65. package/lib/theme/ResponseSchema/index.js +97 -82
  66. package/lib/theme/Schema/index.d.ts +6 -0
  67. package/lib/theme/Schema/index.js +240 -31
  68. package/lib/theme/SchemaItem/index.js +64 -36
  69. package/lib/theme/SchemaTabs/index.d.ts +8 -1
  70. package/lib/theme/SchemaTabs/index.js +14 -2
  71. package/lib/theme/StatusCodes/index.d.ts +1 -1
  72. package/lib/theme/StatusCodes/index.js +11 -2
  73. package/lib/theme/styles.scss +15 -0
  74. package/lib/theme/translationIds.d.ts +90 -0
  75. package/lib/theme/translationIds.js +114 -0
  76. package/package.json +28 -28
  77. package/src/markdown/schema.ts +17 -1
  78. package/src/theme/ApiExplorer/Authorization/index.tsx +51 -10
  79. package/src/theme/ApiExplorer/Authorization/slice.ts +1 -1
  80. package/src/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.tsx +77 -0
  81. package/src/theme/ApiExplorer/Body/FormBodyItem/index.tsx +120 -0
  82. package/src/theme/ApiExplorer/Body/index.tsx +262 -198
  83. package/{lib/types.js → src/theme/ApiExplorer/Body/json2xml.d.ts} +2 -2
  84. package/src/theme/ApiExplorer/Body/resolveSchemaWithSelections.ts +155 -0
  85. package/src/theme/ApiExplorer/Body/slice.ts +40 -1
  86. package/src/theme/ApiExplorer/CodeSnippets/index.tsx +43 -29
  87. package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +5 -1
  88. package/src/theme/ApiExplorer/CodeTabs/index.tsx +6 -5
  89. package/src/theme/ApiExplorer/ContentType/index.tsx +1 -1
  90. package/src/theme/ApiExplorer/FormFileUpload/index.tsx +6 -1
  91. package/src/theme/ApiExplorer/FormItem/index.tsx +8 -1
  92. package/src/theme/ApiExplorer/FormTextInput/index.tsx +10 -1
  93. package/src/theme/ApiExplorer/LiveEditor/index.tsx +11 -4
  94. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx +16 -6
  95. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx +12 -4
  96. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx +12 -4
  97. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx +12 -3
  98. package/src/theme/ApiExplorer/ParamOptions/index.tsx +10 -2
  99. package/src/theme/ApiExplorer/ParamOptions/slice.ts +1 -1
  100. package/src/theme/ApiExplorer/Request/index.tsx +108 -17
  101. package/src/theme/ApiExplorer/Request/makeRequest.ts +106 -25
  102. package/src/theme/ApiExplorer/Response/index.tsx +30 -8
  103. package/src/theme/ApiExplorer/SchemaSelection/index.ts +13 -0
  104. package/src/theme/ApiExplorer/SchemaSelection/slice.ts +46 -0
  105. package/src/theme/ApiExplorer/SecuritySchemes/index.tsx +157 -69
  106. package/src/theme/ApiExplorer/Server/index.tsx +12 -4
  107. package/src/theme/ApiExplorer/buildPostmanRequest.ts +47 -63
  108. package/src/theme/ApiExplorer/index.tsx +5 -0
  109. package/src/theme/ApiExplorer/{persistanceMiddleware.ts → persistenceMiddleware.ts} +23 -13
  110. package/src/theme/ApiExplorer/storage-utils.ts +4 -4
  111. package/src/theme/ApiItem/Layout/index.tsx +1 -1
  112. package/src/theme/ApiItem/index.tsx +13 -7
  113. package/src/theme/ApiItem/store.ts +2 -0
  114. package/src/theme/ApiTabs/index.tsx +6 -1
  115. package/src/theme/Example/_Example.scss +11 -0
  116. package/src/theme/Example/index.tsx +168 -0
  117. package/src/theme/Markdown/index.d.ts +8 -0
  118. package/src/theme/ParamsDetails/index.tsx +10 -1
  119. package/src/theme/ParamsItem/index.tsx +38 -54
  120. package/src/theme/RequestSchema/index.tsx +60 -35
  121. package/src/theme/ResponseExamples/index.tsx +23 -3
  122. package/src/theme/ResponseSchema/index.tsx +73 -61
  123. package/src/theme/Schema/index.tsx +307 -55
  124. package/src/theme/SchemaItem/index.tsx +51 -33
  125. package/src/theme/SchemaTabs/index.tsx +19 -5
  126. package/src/theme/StatusCodes/index.tsx +13 -3
  127. package/src/theme/styles.scss +15 -0
  128. package/src/theme/translationIds.ts +111 -0
  129. package/src/theme-openapi.d.ts +7 -275
  130. package/src/{types.ts → types.d.ts} +9 -1
  131. package/tsconfig.tsbuildinfo +1 -1
  132. package/lib/theme/ApiExplorer/persistanceMiddleware.d.ts +0 -3
  133. package/lib/types.d.ts +0 -46
@@ -17,10 +17,10 @@ export function hashArray(arr: string[]) {
17
17
  return hash(res);
18
18
  }
19
19
 
20
- type Persistance = false | "localStorage" | "sessionStorage" | undefined;
20
+ type Persistence = false | "localStorage" | "sessionStorage" | undefined;
21
21
 
22
- export function createStorage(persistance: Persistance): Storage {
23
- if (persistance === false) {
22
+ export function createStorage(persistence: Persistence): Storage {
23
+ if (persistence === false) {
24
24
  return {
25
25
  getItem: () => null,
26
26
  setItem: () => {},
@@ -31,7 +31,7 @@ export function createStorage(persistance: Persistance): Storage {
31
31
  };
32
32
  }
33
33
 
34
- if (persistance === "sessionStorage") {
34
+ if (persistence === "sessionStorage") {
35
35
  return sessionStorage;
36
36
  }
37
37
 
@@ -9,11 +9,11 @@ import React, { type JSX } from "react";
9
9
 
10
10
  import { useDoc } from "@docusaurus/plugin-content-docs/client";
11
11
  import { useWindowSize } from "@docusaurus/theme-common";
12
- import type { Props } from "@theme/ApiItem/Layout";
13
12
  import ContentVisibility from "@theme/ContentVisibility";
14
13
  import DocBreadcrumbs from "@theme/DocBreadcrumbs";
15
14
  import DocItemContent from "@theme/DocItem/Content";
16
15
  import DocItemFooter from "@theme/DocItem/Footer";
16
+ import type { Props } from "@theme/DocItem/Layout";
17
17
  import DocItemPaginator from "@theme/DocItem/Paginator";
18
18
  import DocItemTOCDesktop from "@theme/DocItem/TOC/Desktop";
19
19
  import DocItemTOCMobile from "@theme/DocItem/TOC/Mobile";
@@ -14,7 +14,8 @@ import { HtmlClassNameProvider } from "@docusaurus/theme-common";
14
14
  import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
15
15
  import useIsBrowser from "@docusaurus/useIsBrowser";
16
16
  import { createAuth } from "@theme/ApiExplorer/Authorization/slice";
17
- import { createPersistanceMiddleware } from "@theme/ApiExplorer/persistanceMiddleware";
17
+ import { createPersistenceMiddleware } from "@theme/ApiExplorer/persistenceMiddleware";
18
+ import { createStorage } from "@theme/ApiExplorer/storage-utils";
18
19
  import DocItemLayout from "@theme/ApiItem/Layout";
19
20
  import CodeBlock from "@theme/CodeBlock";
20
21
  import type { Props } from "@theme/DocItem";
@@ -90,11 +91,11 @@ export default function ApiItem(props: Props): JSX.Element {
90
91
 
91
92
  // Define store2
92
93
  let store2: any = {};
93
- const persistanceMiddleware = createPersistanceMiddleware(options);
94
+ const persistenceMiddleware = createPersistenceMiddleware(options);
94
95
 
95
96
  // Init store for SSR
96
97
  if (!isBrowser) {
97
- store2 = createStoreWithoutState({}, [persistanceMiddleware]);
98
+ store2 = createStoreWithoutState({}, [persistenceMiddleware]);
98
99
  }
99
100
 
100
101
  // Init store for CSR to hydrate components
@@ -129,11 +130,15 @@ export default function ApiItem(props: Props): JSX.Element {
129
130
  securitySchemes: api?.securitySchemes,
130
131
  options,
131
132
  });
133
+
134
+ const storage = createStorage(options?.authPersistence ?? "sessionStorage");
132
135
  // TODO: determine way to rehydrate without flashing
133
136
  // const acceptValue = window?.sessionStorage.getItem("accept");
134
137
  // const contentTypeValue = window?.sessionStorage.getItem("contentType");
135
- const server = window?.sessionStorage.getItem("server");
136
- const serverObject = (JSON.parse(server!) as ServerObject) ?? {};
138
+ const server = storage.getItem("server");
139
+ const serverObject = server
140
+ ? (JSON.parse(server) as ServerObject)
141
+ : undefined;
137
142
 
138
143
  store2 = createStoreWithState(
139
144
  {
@@ -146,15 +151,16 @@ export default function ApiItem(props: Props): JSX.Element {
146
151
  options: contentTypeArray,
147
152
  },
148
153
  server: {
149
- value: serverObject.url ? serverObject : undefined,
154
+ value: serverObject?.url ? serverObject : undefined,
150
155
  options: servers,
151
156
  },
152
157
  response: { value: undefined },
153
158
  body: { type: "empty" },
154
159
  params,
155
160
  auth,
161
+ schemaSelection: { selections: {} },
156
162
  },
157
- [persistanceMiddleware]
163
+ [persistenceMiddleware]
158
164
  );
159
165
  }
160
166
 
@@ -12,6 +12,7 @@ import body from "@theme/ApiExplorer/Body/slice";
12
12
  import contentType from "@theme/ApiExplorer/ContentType/slice";
13
13
  import params from "@theme/ApiExplorer/ParamOptions/slice";
14
14
  import response from "@theme/ApiExplorer/Response/slice";
15
+ import schemaSelection from "@theme/ApiExplorer/SchemaSelection/slice";
15
16
  import server from "@theme/ApiExplorer/Server/slice";
16
17
 
17
18
  const rootReducer = combineReducers({
@@ -22,6 +23,7 @@ const rootReducer = combineReducers({
22
23
  body,
23
24
  params,
24
25
  auth,
26
+ schemaSelection,
25
27
  });
26
28
 
27
29
  export type RootState = ReturnType<typeof rootReducer>;
@@ -20,8 +20,10 @@ import {
20
20
  useTabs,
21
21
  } from "@docusaurus/theme-common/internal";
22
22
  import { TabItemProps } from "@docusaurus/theme-common/lib/utils/tabsUtils";
23
+ import { translate } from "@docusaurus/Translate";
23
24
  import useIsBrowser from "@docusaurus/useIsBrowser";
24
25
  import Heading from "@theme/Heading";
26
+ import { OPENAPI_TABS } from "@theme/translationIds";
25
27
  import clsx from "clsx";
26
28
 
27
29
  export interface TabListProps extends TabProps {
@@ -35,7 +37,10 @@ function TabList({
35
37
  selectedValue,
36
38
  selectValue,
37
39
  tabValues,
38
- label = "Responses",
40
+ label = translate({
41
+ id: OPENAPI_TABS.RESPONSES_LABEL,
42
+ message: "Responses",
43
+ }),
39
44
  id = "responses",
40
45
  }: TabListProps & ReturnType<typeof useTabs>) {
41
46
  const tabRefs: (HTMLLIElement | null)[] = [];
@@ -0,0 +1,11 @@
1
+ .openapi-examples {
2
+ > .openapi-tabs__schema-container {
3
+ margin: 0.4rem;
4
+
5
+ @layer docusaurus.infima {
6
+ > .margin-top--md {
7
+ margin: 0.2rem !important;
8
+ }
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,168 @@
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 React from "react";
9
+
10
+ import { translate } from "@docusaurus/Translate";
11
+ import { ExampleObject } from "@theme/ParamsItem";
12
+ import SchemaTabs from "@theme/SchemaTabs";
13
+ import TabItem from "@theme/TabItem";
14
+ import { OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";
15
+
16
+ const EXAMPLE_CLASS_NAME = "openapi-example";
17
+ const EXAMPLES_CLASS_NAME = "openapi-examples";
18
+
19
+ type ExampleType = string;
20
+ type ExamplesType = Record<string, ExampleObject> | string[];
21
+
22
+ /**
23
+ * Example Component Props
24
+ */
25
+ type ExampleProps = {
26
+ example?: ExampleType;
27
+ examples?: ExamplesType;
28
+ };
29
+
30
+ /**
31
+ * Example Component
32
+ */
33
+ export const Example = ({ example, examples }: ExampleProps) => {
34
+ if (example !== undefined) {
35
+ return renderExample(example);
36
+ }
37
+ if (examples !== undefined) {
38
+ return renderExamples(examples);
39
+ }
40
+ return undefined;
41
+ };
42
+
43
+ /**
44
+ * Format example value
45
+ *
46
+ * @param example
47
+ * @returns
48
+ */
49
+ const formatExample = (example: any) => {
50
+ if (typeof example === "object" && example !== null) {
51
+ return JSON.stringify(example);
52
+ }
53
+ return String(example);
54
+ };
55
+
56
+ const renderExample = (example: ExampleType) => {
57
+ return (
58
+ <div className={EXAMPLE_CLASS_NAME}>
59
+ <strong>
60
+ {translate({
61
+ id: OPENAPI_SCHEMA_ITEM.EXAMPLE,
62
+ message: "Example:",
63
+ })}{" "}
64
+ </strong>
65
+ <span>
66
+ <code>{formatExample(example)}</code>
67
+ </span>
68
+ </div>
69
+ );
70
+ };
71
+
72
+ const renderExamples = (examples: ExamplesType) => {
73
+ if (Array.isArray(examples)) {
74
+ return renderStringArrayExamples(examples);
75
+ }
76
+ return renderExamplesRecord(examples);
77
+ };
78
+
79
+ /**
80
+ * Render string examples
81
+ *
82
+ * @param examples
83
+ * @returns
84
+ */
85
+ export function renderStringArrayExamples(examples: string[]) {
86
+ if (examples.length === 0) {
87
+ return undefined;
88
+ }
89
+ // If there's only one example, display it without tabs
90
+ if (examples.length === 1) {
91
+ return renderExample(examples[0]);
92
+ }
93
+
94
+ // Multiple examples - use tabs
95
+ const exampleEntries = examples.reduce(
96
+ (acc, example, index) => ({
97
+ ...acc,
98
+ [`Example ${index + 1}`]: {
99
+ value: example,
100
+ },
101
+ }),
102
+ {} as Record<string, ExampleObject>
103
+ );
104
+ return renderExamplesRecord(exampleEntries);
105
+ }
106
+
107
+ export const renderExamplesRecord = (
108
+ examples: Record<string, ExampleObject>
109
+ ) => {
110
+ const exampleEntries = Object.entries(examples);
111
+ // If there's only one example, display it without tabs
112
+ if (exampleEntries.length === 1) {
113
+ const firstExample = exampleEntries[0][1];
114
+ if (!firstExample) {
115
+ return undefined;
116
+ }
117
+ return renderExample(firstExample.value);
118
+ }
119
+
120
+ return (
121
+ <div className={EXAMPLES_CLASS_NAME}>
122
+ <strong>
123
+ {translate({
124
+ id: OPENAPI_SCHEMA_ITEM.EXAMPLES,
125
+ message: "Examples:",
126
+ })}
127
+ </strong>
128
+ <SchemaTabs>
129
+ {exampleEntries.map(([exampleName, exampleProperties]) =>
130
+ renderExampleObject(exampleName, exampleProperties)
131
+ )}
132
+ </SchemaTabs>
133
+ </div>
134
+ );
135
+ };
136
+
137
+ /**
138
+ * Render example object
139
+ *
140
+ * @param exampleName
141
+ * @param exampleProperties
142
+ * @returns
143
+ */
144
+ const renderExampleObject = (
145
+ exampleName: string,
146
+ exampleProperties: ExampleObject
147
+ ) => {
148
+ return (
149
+ // @ts-ignore
150
+ <TabItem value={exampleName} label={exampleName}>
151
+ {exampleProperties.summary && <p>{exampleProperties.summary}</p>}
152
+ {exampleProperties.description && (
153
+ <p>
154
+ <strong>
155
+ {translate({
156
+ id: OPENAPI_SCHEMA_ITEM.DESCRIPTION,
157
+ message: "Description:",
158
+ })}{" "}
159
+ </strong>
160
+ <span>{exampleProperties.description}</span>
161
+ </p>
162
+ )}
163
+ {exampleProperties.value !== undefined
164
+ ? renderExample(exampleProperties.value)
165
+ : undefined}
166
+ </TabItem>
167
+ );
168
+ };
@@ -0,0 +1,8 @@
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
+ export default function Markdown(props: any): JSX.Element;
@@ -7,6 +7,9 @@
7
7
 
8
8
  import React from "react";
9
9
 
10
+ import { translate } from "@docusaurus/Translate";
11
+ import { OPENAPI_PARAMS_DETAILS } from "@theme/translationIds";
12
+
10
13
  import BrowserOnly from "@docusaurus/BrowserOnly";
11
14
  import Details from "@theme/Details";
12
15
  import ParamsItem from "@theme/ParamsItem";
@@ -31,7 +34,13 @@ const ParamsDetailsComponent: React.FC<Props> = ({ parameters }) => {
31
34
  const summaryElement = (
32
35
  <summary>
33
36
  <h3 className="openapi-markdown__details-summary-header-params">
34
- {`${type.charAt(0).toUpperCase() + type.slice(1)} Parameters`}
37
+ {translate(
38
+ {
39
+ id: OPENAPI_PARAMS_DETAILS.PARAMETERS_TITLE,
40
+ message: "{type} Parameters",
41
+ },
42
+ { type: type.charAt(0).toUpperCase() + type.slice(1) }
43
+ )}
35
44
  </h3>
36
45
  </summary>
37
46
  );
@@ -7,14 +7,15 @@
7
7
 
8
8
  import React from "react";
9
9
 
10
+ import { translate } from "@docusaurus/Translate";
11
+ import { Example } from "@theme/Example";
10
12
  import Markdown from "@theme/Markdown";
11
- import SchemaTabs from "@theme/SchemaTabs";
12
- import TabItem from "@theme/TabItem";
13
13
  /* eslint-disable import/no-extraneous-dependencies*/
14
+ import { OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";
14
15
  import clsx from "clsx";
15
16
 
16
17
  import { getQualifierMessage, getSchemaName } from "../../markdown/schema";
17
- import { guard, toString } from "../../markdown/utils";
18
+ import { guard } from "../../markdown/utils";
18
19
 
19
20
  export interface ExampleObject {
20
21
  summary?: string;
@@ -28,7 +29,7 @@ export interface Props {
28
29
  param: {
29
30
  description: string;
30
31
  example: any;
31
- examples: Record<string, ExampleObject>;
32
+ examples: Record<string, ExampleObject> | undefined;
32
33
  name: string;
33
34
  required: boolean;
34
35
  deprecated: boolean;
@@ -39,7 +40,15 @@ export interface Props {
39
40
 
40
41
  const getEnumDescriptionMarkdown = (enumDescriptions?: [string, string][]) => {
41
42
  if (enumDescriptions?.length) {
42
- return `| Enum Value | Description |
43
+ const enumValue = translate({
44
+ id: OPENAPI_SCHEMA_ITEM.ENUM_VALUE,
45
+ message: "Enum Value",
46
+ });
47
+ const description = translate({
48
+ id: OPENAPI_SCHEMA_ITEM.ENUM_DESCRIPTION,
49
+ message: "Description",
50
+ });
51
+ return `| ${enumValue} | ${description} |
43
52
  | ---- | ----- |
44
53
  ${enumDescriptions
45
54
  .map((desc) => {
@@ -53,19 +62,14 @@ ${enumDescriptions
53
62
  };
54
63
 
55
64
  function ParamsItem({ param, ...rest }: Props) {
56
- const {
57
- description,
58
- example,
59
- examples,
60
- name,
61
- required,
62
- deprecated,
63
- enumDescriptions,
64
- } = param;
65
+ const { description, name, required, deprecated, enumDescriptions } = param;
65
66
 
66
67
  let schema = param.schema;
67
68
  let defaultValue: string | undefined;
68
69
 
70
+ let examples = param.examples ?? (schema?.examples as any[] | undefined);
71
+ let example = param.example ?? schema?.example;
72
+
69
73
  if (!schema) {
70
74
  schema = { type: "any" };
71
75
  }
@@ -87,11 +91,15 @@ function ParamsItem({ param, ...rest }: Props) {
87
91
  ));
88
92
 
89
93
  const renderSchemaRequired = guard(required, () => (
90
- <span className="openapi-schema__required">required</span>
94
+ <span className="openapi-schema__required">
95
+ {translate({ id: OPENAPI_SCHEMA_ITEM.REQUIRED, message: "required" })}
96
+ </span>
91
97
  ));
92
98
 
93
99
  const renderDeprecated = guard(deprecated, () => (
94
- <span className="openapi-schema__deprecated">deprecated</span>
100
+ <span className="openapi-schema__deprecated">
101
+ {translate({ id: OPENAPI_SCHEMA_ITEM.DEPRECATED, message: "deprecated" })}
102
+ </span>
95
103
  ));
96
104
 
97
105
  const renderQualifier = guard(getQualifierMessage(schema), (qualifier) => (
@@ -118,7 +126,12 @@ function ParamsItem({ param, ...rest }: Props) {
118
126
  if (typeof defaultValue === "string") {
119
127
  return (
120
128
  <div>
121
- <strong>Default value: </strong>
129
+ <strong>
130
+ {translate({
131
+ id: OPENAPI_SCHEMA_ITEM.DEFAULT_VALUE,
132
+ message: "Default value:",
133
+ })}{" "}
134
+ </strong>
122
135
  <span>
123
136
  <code>{defaultValue}</code>
124
137
  </span>
@@ -127,7 +140,12 @@ function ParamsItem({ param, ...rest }: Props) {
127
140
  }
128
141
  return (
129
142
  <div>
130
- <strong>Default value: </strong>
143
+ <strong>
144
+ {translate({
145
+ id: OPENAPI_SCHEMA_ITEM.DEFAULT_VALUE,
146
+ message: "Default value:",
147
+ })}{" "}
148
+ </strong>
131
149
  <span>
132
150
  <code>{JSON.stringify(defaultValue)}</code>
133
151
  </span>
@@ -137,40 +155,6 @@ function ParamsItem({ param, ...rest }: Props) {
137
155
  return undefined;
138
156
  }
139
157
 
140
- const renderExample = guard(toString(example), (example) => (
141
- <div>
142
- <strong>Example: </strong>
143
- {example}
144
- </div>
145
- ));
146
-
147
- const renderExamples = guard(examples, (examples) => {
148
- const exampleEntries = Object.entries(examples);
149
- return (
150
- <>
151
- <strong>Examples:</strong>
152
- <SchemaTabs>
153
- {exampleEntries.map(([exampleName, exampleProperties]) => (
154
- // @ts-ignore
155
- <TabItem value={exampleName} label={exampleName}>
156
- {exampleProperties.summary && <p>{exampleProperties.summary}</p>}
157
- {exampleProperties.description && (
158
- <p>
159
- <strong>Description: </strong>
160
- <span>{exampleProperties.description}</span>
161
- </p>
162
- )}
163
- <p>
164
- <strong>Example: </strong>
165
- <code>{exampleProperties.value}</code>
166
- </p>
167
- </TabItem>
168
- ))}
169
- </SchemaTabs>
170
- </>
171
- );
172
- });
173
-
174
158
  return (
175
159
  <div className="openapi-params__list-item">
176
160
  <span className="openapi-schema__container">
@@ -192,8 +176,8 @@ function ParamsItem({ param, ...rest }: Props) {
192
176
  {renderDescription}
193
177
  {renderEnumDescriptions}
194
178
  {renderDefaultValue()}
195
- {renderExample}
196
- {renderExamples}
179
+ <Example example={example} />
180
+ <Example examples={examples} />
197
181
  </div>
198
182
  );
199
183
  }
@@ -7,6 +7,9 @@
7
7
 
8
8
  import React from "react";
9
9
 
10
+ import { translate } from "@docusaurus/Translate";
11
+ import { OPENAPI_REQUEST, OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";
12
+
10
13
  import BrowserOnly from "@docusaurus/BrowserOnly";
11
14
  import Details from "@theme/Details";
12
15
  import Markdown from "@theme/Markdown";
@@ -42,7 +45,7 @@ const RequestSchemaComponent: React.FC<Props> = ({ title, body, style }) => {
42
45
 
43
46
  if (mimeTypes.length > 1) {
44
47
  return (
45
- <MimeTabs className="openapi-tabs__mime" schemaType="request">
48
+ <MimeTabs className="openapi-tabs__mime" schemaType="request" lazy>
46
49
  {mimeTypes.map((mimeType) => {
47
50
  const firstBody = body.content![mimeType].schema;
48
51
  if (
@@ -55,37 +58,49 @@ const RequestSchemaComponent: React.FC<Props> = ({ title, body, style }) => {
55
58
  return (
56
59
  // @ts-ignore
57
60
  <TabItem key={mimeType} label={mimeType} value={mimeType}>
58
- <Details
59
- className="openapi-markdown__details mime"
60
- data-collapsed={false}
61
- open={true}
62
- style={style}
63
- summary={
64
- <>
65
- <summary>
66
- <h3 className="openapi-markdown__details-summary-header-body">
67
- {title}
68
- {body.required === true && (
69
- <span className="openapi-schema__required">
70
- required
71
- </span>
72
- )}
73
- </h3>
74
- </summary>
75
- </>
76
- }
77
- >
78
- <div style={{ textAlign: "left", marginLeft: "1rem" }}>
79
- {body.description && (
80
- <div style={{ marginTop: "1rem", marginBottom: "1rem" }}>
81
- <Markdown>{body.description}</Markdown>
82
- </div>
83
- )}
84
- </div>
85
- <ul style={{ marginLeft: "1rem" }}>
86
- <SchemaNode schema={firstBody} schemaType="request" />
87
- </ul>
88
- </Details>
61
+ <div style={{ marginTop: "1rem" }}>
62
+ <Details
63
+ className="openapi-markdown__details mime"
64
+ data-collapsed={false}
65
+ open={true}
66
+ style={style}
67
+ summary={
68
+ <>
69
+ <summary>
70
+ <h3 className="openapi-markdown__details-summary-header-body">
71
+ {translate({
72
+ id: OPENAPI_REQUEST.BODY_TITLE,
73
+ message: title,
74
+ })}
75
+ {body.required === true && (
76
+ <span className="openapi-schema__required">
77
+ {translate({
78
+ id: OPENAPI_SCHEMA_ITEM.REQUIRED,
79
+ message: "required",
80
+ })}
81
+ </span>
82
+ )}
83
+ </h3>
84
+ </summary>
85
+ </>
86
+ }
87
+ >
88
+ <div style={{ textAlign: "left", marginLeft: "1rem" }}>
89
+ {body.description && (
90
+ <div style={{ marginTop: "1rem", marginBottom: "1rem" }}>
91
+ <Markdown>{body.description}</Markdown>
92
+ </div>
93
+ )}
94
+ </div>
95
+ <ul style={{ marginLeft: "1rem" }}>
96
+ <SchemaNode
97
+ schema={firstBody}
98
+ schemaType="request"
99
+ schemaPath="requestBody"
100
+ />
101
+ </ul>
102
+ </Details>
103
+ </div>
89
104
  </TabItem>
90
105
  );
91
106
  })}
@@ -114,13 +129,19 @@ const RequestSchemaComponent: React.FC<Props> = ({ title, body, style }) => {
114
129
  <>
115
130
  <summary>
116
131
  <h3 className="openapi-markdown__details-summary-header-body">
117
- {title}
132
+ {translate({
133
+ id: OPENAPI_REQUEST.BODY_TITLE,
134
+ message: title,
135
+ })}
118
136
  {firstBody.type === "array" && (
119
137
  <span style={{ opacity: "0.6" }}> array</span>
120
138
  )}
121
139
  {body.required && (
122
140
  <strong className="openapi-schema__required">
123
- required
141
+ {translate({
142
+ id: OPENAPI_SCHEMA_ITEM.REQUIRED,
143
+ message: "required",
144
+ })}
124
145
  </strong>
125
146
  )}
126
147
  </h3>
@@ -136,7 +157,11 @@ const RequestSchemaComponent: React.FC<Props> = ({ title, body, style }) => {
136
157
  )}
137
158
  </div>
138
159
  <ul style={{ marginLeft: "1rem" }}>
139
- <SchemaNode schema={firstBody} schemaType="request" />
160
+ <SchemaNode
161
+ schema={firstBody}
162
+ schemaType="request"
163
+ schemaPath="requestBody"
164
+ />
140
165
  </ul>
141
166
  </Details>
142
167
  </TabItem>