docusaurus-theme-openapi-docs 4.7.0 → 5.0.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 (148) hide show
  1. package/lib/index.js +2 -0
  2. package/lib/markdown/schema.js +63 -9
  3. package/lib/theme/ApiExplorer/Accept/index.js +2 -1
  4. package/lib/theme/ApiExplorer/Authorization/index.js +12 -18
  5. package/lib/theme/ApiExplorer/Authorization/slice.d.ts +1 -1
  6. package/lib/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.js +0 -4
  7. package/lib/theme/ApiExplorer/Body/FormBodyItem/index.d.ts +6 -2
  8. package/lib/theme/ApiExplorer/Body/FormBodyItem/index.js +191 -38
  9. package/lib/theme/ApiExplorer/Body/index.d.ts +1 -1
  10. package/lib/theme/ApiExplorer/Body/index.js +86 -15
  11. package/lib/theme/ApiExplorer/Body/resolveSchemaWithSelections.d.ts +1 -1
  12. package/lib/theme/ApiExplorer/Body/slice.d.ts +136 -544
  13. package/lib/theme/ApiExplorer/CodeSnippets/index.d.ts +2 -1
  14. package/lib/theme/ApiExplorer/CodeSnippets/index.js +4 -0
  15. package/lib/theme/ApiExplorer/CodeTabs/index.js +15 -16
  16. package/lib/theme/ApiExplorer/ContentType/index.js +7 -2
  17. package/lib/theme/ApiExplorer/EncodingSelection/slice.d.ts +17 -0
  18. package/lib/theme/ApiExplorer/EncodingSelection/slice.js +29 -0
  19. package/lib/theme/ApiExplorer/EncodingSelection/useResolvedEncoding.d.ts +12 -0
  20. package/lib/theme/ApiExplorer/EncodingSelection/useResolvedEncoding.js +39 -0
  21. package/lib/theme/ApiExplorer/FormItem/_FormItem.scss +0 -5
  22. package/lib/theme/ApiExplorer/FormItem/index.d.ts +1 -4
  23. package/lib/theme/ApiExplorer/FormItem/index.js +2 -26
  24. package/lib/theme/ApiExplorer/FormLabel/_FormLabel.scss +4 -0
  25. package/lib/theme/ApiExplorer/FormLabel/index.d.ts +9 -0
  26. package/lib/theme/ApiExplorer/FormLabel/index.js +50 -0
  27. package/lib/theme/ApiExplorer/FormMultiSelect/index.d.ts +4 -1
  28. package/lib/theme/ApiExplorer/FormMultiSelect/index.js +97 -19
  29. package/lib/theme/ApiExplorer/FormSelect/index.d.ts +6 -1
  30. package/lib/theme/ApiExplorer/FormSelect/index.js +96 -15
  31. package/lib/theme/ApiExplorer/FormTextInput/index.d.ts +4 -1
  32. package/lib/theme/ApiExplorer/FormTextInput/index.js +71 -1
  33. package/lib/theme/ApiExplorer/MethodEndpoint/index.js +28 -0
  34. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.d.ts +4 -1
  35. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.js +11 -3
  36. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.d.ts +4 -1
  37. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.js +4 -1
  38. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.d.ts +4 -1
  39. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.js +6 -2
  40. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.d.ts +4 -1
  41. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.js +6 -2
  42. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.d.ts +4 -1
  43. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.js +8 -3
  44. package/lib/theme/ApiExplorer/ParamOptions/_ParamOptions.scss +0 -9
  45. package/lib/theme/ApiExplorer/ParamOptions/index.d.ts +10 -0
  46. package/lib/theme/ApiExplorer/ParamOptions/index.js +55 -5
  47. package/lib/theme/ApiExplorer/ParamOptions/slice.d.ts +1 -1
  48. package/lib/theme/ApiExplorer/Request/_Request.scss +11 -0
  49. package/lib/theme/ApiExplorer/Request/index.d.ts +1 -1
  50. package/lib/theme/ApiExplorer/Request/index.js +19 -5
  51. package/lib/theme/ApiExplorer/Request/makeRequest.d.ts +3 -1
  52. package/lib/theme/ApiExplorer/Request/makeRequest.js +19 -3
  53. package/lib/theme/ApiExplorer/Response/_Response.scss +11 -0
  54. package/lib/theme/ApiExplorer/Response/index.d.ts +1 -1
  55. package/lib/theme/ApiExplorer/Response/index.js +98 -12
  56. package/lib/theme/ApiExplorer/SecuritySchemes/index.js +2 -2
  57. package/lib/theme/ApiExplorer/Server/index.d.ts +4 -1
  58. package/lib/theme/ApiExplorer/Server/index.js +6 -3
  59. package/lib/theme/ApiExplorer/Server/slice.d.ts +1 -1
  60. package/lib/theme/ApiExplorer/buildPostmanRequest.d.ts +5 -2
  61. package/lib/theme/ApiExplorer/buildPostmanRequest.js +46 -5
  62. package/lib/theme/ApiExplorer/index.d.ts +1 -1
  63. package/lib/theme/ApiExplorer/index.js +1 -0
  64. package/lib/theme/ApiExplorer/persistenceMiddleware.d.ts +2 -0
  65. package/lib/theme/ApiItem/hooks.d.ts +1 -0
  66. package/lib/theme/ApiItem/index.js +2 -1
  67. package/lib/theme/ApiItem/store.d.ts +6 -0
  68. package/lib/theme/ApiItem/store.js +11 -7
  69. package/lib/theme/ApiTabs/index.js +10 -11
  70. package/lib/theme/DiscriminatorTabs/index.js +10 -11
  71. package/lib/theme/MimeTabs/index.js +10 -11
  72. package/lib/theme/OperationTabs/index.js +10 -11
  73. package/lib/theme/ParamsDetails/index.js +2 -2
  74. package/lib/theme/ParamsItem/index.js +27 -0
  75. package/lib/theme/RequestSchema/index.d.ts +1 -1
  76. package/lib/theme/RequestSchema/index.js +174 -111
  77. package/lib/theme/ResponseHeaders/index.js +0 -1
  78. package/lib/theme/ResponseSchema/index.d.ts +1 -1
  79. package/lib/theme/Schema/index.d.ts +1 -1
  80. package/lib/theme/Schema/index.js +91 -23
  81. package/lib/theme/SchemaItem/index.js +6 -1
  82. package/lib/theme/SchemaTabs/index.d.ts +1 -1
  83. package/lib/theme/SchemaTabs/index.js +31 -12
  84. package/lib/theme/StatusCodes/index.d.ts +1 -1
  85. package/lib/theme/styles.scss +1 -0
  86. package/lib/theme/translationIds.d.ts +3 -0
  87. package/lib/theme/translationIds.js +3 -0
  88. package/package.json +9 -8
  89. package/src/index.ts +2 -0
  90. package/src/markdown/schema.ts +69 -13
  91. package/src/theme/ApiExplorer/Accept/index.tsx +2 -1
  92. package/src/theme/ApiExplorer/Authorization/index.tsx +27 -33
  93. package/src/theme/ApiExplorer/Authorization/slice.ts +1 -1
  94. package/src/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.tsx +2 -5
  95. package/src/theme/ApiExplorer/Body/FormBodyItem/index.tsx +119 -39
  96. package/src/theme/ApiExplorer/Body/index.tsx +88 -21
  97. package/src/theme/ApiExplorer/Body/resolveSchemaWithSelections.ts +1 -1
  98. package/src/theme/ApiExplorer/CodeSnippets/index.tsx +9 -1
  99. package/src/theme/ApiExplorer/CodeTabs/index.tsx +19 -19
  100. package/src/theme/ApiExplorer/ContentType/index.tsx +7 -4
  101. package/src/theme/ApiExplorer/EncodingSelection/slice.ts +31 -0
  102. package/src/theme/ApiExplorer/EncodingSelection/useResolvedEncoding.ts +43 -0
  103. package/src/theme/ApiExplorer/FormItem/_FormItem.scss +0 -5
  104. package/src/theme/ApiExplorer/FormItem/index.tsx +2 -17
  105. package/src/theme/ApiExplorer/FormLabel/_FormLabel.scss +4 -0
  106. package/src/theme/ApiExplorer/FormLabel/index.tsx +43 -0
  107. package/src/theme/ApiExplorer/FormMultiSelect/index.tsx +40 -20
  108. package/src/theme/ApiExplorer/FormSelect/index.tsx +41 -15
  109. package/src/theme/ApiExplorer/FormTextInput/index.tsx +15 -1
  110. package/src/theme/ApiExplorer/MethodEndpoint/index.tsx +21 -0
  111. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx +13 -2
  112. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx +12 -1
  113. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx +14 -2
  114. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx +14 -2
  115. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.tsx +16 -3
  116. package/src/theme/ApiExplorer/ParamOptions/_ParamOptions.scss +0 -9
  117. package/src/theme/ApiExplorer/ParamOptions/index.tsx +97 -11
  118. package/src/theme/ApiExplorer/ParamOptions/slice.ts +1 -1
  119. package/src/theme/ApiExplorer/Request/_Request.scss +11 -0
  120. package/src/theme/ApiExplorer/Request/index.tsx +22 -10
  121. package/src/theme/ApiExplorer/Request/makeRequest.ts +19 -3
  122. package/src/theme/ApiExplorer/Response/_Response.scss +11 -0
  123. package/src/theme/ApiExplorer/Response/index.tsx +37 -17
  124. package/src/theme/ApiExplorer/SecuritySchemes/index.tsx +2 -3
  125. package/src/theme/ApiExplorer/Server/index.tsx +10 -3
  126. package/src/theme/ApiExplorer/Server/slice.ts +1 -1
  127. package/src/theme/ApiExplorer/buildPostmanRequest.ts +53 -6
  128. package/src/theme/ApiExplorer/index.tsx +2 -1
  129. package/src/theme/ApiItem/index.tsx +3 -2
  130. package/src/theme/ApiItem/store.ts +2 -0
  131. package/src/theme/ApiTabs/index.tsx +14 -19
  132. package/src/theme/DiscriminatorTabs/index.tsx +14 -19
  133. package/src/theme/MimeTabs/index.tsx +15 -19
  134. package/src/theme/OperationTabs/index.tsx +14 -19
  135. package/src/theme/ParamsDetails/index.tsx +2 -3
  136. package/src/theme/ParamsItem/index.tsx +25 -0
  137. package/src/theme/RequestSchema/index.tsx +144 -87
  138. package/src/theme/ResponseHeaders/index.tsx +1 -2
  139. package/src/theme/ResponseSchema/index.tsx +1 -1
  140. package/src/theme/Schema/index.tsx +112 -27
  141. package/src/theme/SchemaItem/index.tsx +6 -1
  142. package/src/theme/SchemaTabs/index.tsx +42 -21
  143. package/src/theme/StatusCodes/index.tsx +1 -1
  144. package/src/theme/styles.scss +1 -0
  145. package/src/theme/translationIds.ts +3 -0
  146. package/src/theme-classic.d.ts +25 -1
  147. package/src/types.d.ts +15 -52
  148. package/tsconfig.tsbuildinfo +1 -1
@@ -22,7 +22,7 @@ import type { Props } from "@theme/DocItem";
22
22
  import DocItemMetadata from "@theme/DocItem/Metadata";
23
23
  import SkeletonLoader from "@theme/SkeletonLoader";
24
24
  import clsx from "clsx";
25
- import {
25
+ import type {
26
26
  ParameterObject,
27
27
  ServerObject,
28
28
  } from "docusaurus-plugin-openapi-docs/src/openapi/types";
@@ -122,7 +122,7 @@ export default function ApiItem(props: Props): JSX.Element {
122
122
  (param: { in: "path" | "query" | "header" | "cookie" }) => {
123
123
  const paramType = param.in;
124
124
  const paramsArray: ParameterObject[] = params[paramType];
125
- paramsArray.push(param as ParameterObject);
125
+ paramsArray?.push(param as ParameterObject);
126
126
  }
127
127
  );
128
128
  const auth = createAuth({
@@ -159,6 +159,7 @@ export default function ApiItem(props: Props): JSX.Element {
159
159
  params,
160
160
  auth,
161
161
  schemaSelection: { selections: {} },
162
+ encodingSelection: {},
162
163
  },
163
164
  [persistenceMiddleware]
164
165
  );
@@ -10,6 +10,7 @@ import accept from "@theme/ApiExplorer/Accept/slice";
10
10
  import auth from "@theme/ApiExplorer/Authorization/slice";
11
11
  import body from "@theme/ApiExplorer/Body/slice";
12
12
  import contentType from "@theme/ApiExplorer/ContentType/slice";
13
+ import encodingSelection from "@theme/ApiExplorer/EncodingSelection/slice";
13
14
  import params from "@theme/ApiExplorer/ParamOptions/slice";
14
15
  import response from "@theme/ApiExplorer/Response/slice";
15
16
  import schemaSelection from "@theme/ApiExplorer/SchemaSelection/slice";
@@ -18,6 +19,7 @@ import server from "@theme/ApiExplorer/Server/slice";
18
19
  const rootReducer = combineReducers({
19
20
  accept,
20
21
  contentType,
22
+ encodingSelection,
21
23
  response,
22
24
  server,
23
25
  body,
@@ -15,11 +15,12 @@ import React, {
15
15
 
16
16
  import {
17
17
  sanitizeTabsChildren,
18
+ type TabItemProps,
18
19
  TabProps,
20
+ TabsProvider,
19
21
  useScrollPositionBlocker,
20
- useTabs,
22
+ useTabsContextValue,
21
23
  } from "@docusaurus/theme-common/internal";
22
- import { TabItemProps } from "@docusaurus/theme-common/lib/utils/tabsUtils";
23
24
  import { translate } from "@docusaurus/Translate";
24
25
  import useIsBrowser from "@docusaurus/useIsBrowser";
25
26
  import Heading from "@theme/Heading";
@@ -42,7 +43,7 @@ function TabList({
42
43
  message: "Responses",
43
44
  }),
44
45
  id = "responses",
45
- }: TabListProps & ReturnType<typeof useTabs>) {
46
+ }: TabListProps & ReturnType<typeof useTabsContextValue>) {
46
47
  const tabRefs: (HTMLLIElement | null)[] = [];
47
48
  const { blockElementScrollPositionUntilNextRender } =
48
49
  useScrollPositionBlocker();
@@ -194,7 +195,8 @@ function TabContent({
194
195
  lazy,
195
196
  children,
196
197
  selectedValue,
197
- }: TabProps & ReturnType<typeof useTabs>): React.JSX.Element | null {
198
+ }: TabProps &
199
+ ReturnType<typeof useTabsContextValue>): React.JSX.Element | null {
198
200
  const childTabs = (Array.isArray(children) ? children : [children]).filter(
199
201
  Boolean
200
202
  ) as ReactElement<TabItemProps>[];
@@ -208,24 +210,17 @@ function TabContent({
208
210
  }
209
211
  return cloneElement(selectedTabItem, { className: "margin-top--md" });
210
212
  }
211
- return (
212
- <div className="margin-top--md">
213
- {childTabs.map((tabItem, i) =>
214
- cloneElement(tabItem, {
215
- key: i,
216
- hidden: tabItem.props.value !== selectedValue,
217
- })
218
- )}
219
- </div>
220
- );
213
+ return <div className="margin-top--md">{childTabs}</div>;
221
214
  }
222
215
  function TabsComponent(props: TabListProps): React.JSX.Element {
223
- const tabs = useTabs(props);
216
+ const tabs = useTabsContextValue(props);
224
217
  return (
225
- <div className="openapi-tabs__container">
226
- <TabList {...props} {...tabs} />
227
- <TabContent {...props} {...tabs} />
228
- </div>
218
+ <TabsProvider value={tabs}>
219
+ <div className="openapi-tabs__container">
220
+ <TabList {...props} {...tabs} />
221
+ <TabContent {...props} {...tabs} />
222
+ </div>
223
+ </TabsProvider>
229
224
  );
230
225
  }
231
226
  export default function ApiTabs(props: TabListProps): React.JSX.Element {
@@ -15,11 +15,12 @@ import React, {
15
15
 
16
16
  import {
17
17
  sanitizeTabsChildren,
18
+ type TabItemProps,
18
19
  TabProps,
20
+ TabsProvider,
19
21
  useScrollPositionBlocker,
20
- useTabs,
22
+ useTabsContextValue,
21
23
  } from "@docusaurus/theme-common/internal";
22
- import { TabItemProps } from "@docusaurus/theme-common/lib/utils/tabsUtils";
23
24
  import useIsBrowser from "@docusaurus/useIsBrowser";
24
25
  import clsx from "clsx";
25
26
  import flatten from "lodash/flatten";
@@ -30,7 +31,7 @@ function TabList({
30
31
  selectedValue,
31
32
  selectValue,
32
33
  tabValues,
33
- }: TabProps & ReturnType<typeof useTabs>) {
34
+ }: TabProps & ReturnType<typeof useTabsContextValue>) {
34
35
  const tabRefs: (HTMLLIElement | null)[] = [];
35
36
  const { blockElementScrollPositionUntilNextRender } =
36
37
  useScrollPositionBlocker();
@@ -172,7 +173,8 @@ function TabContent({
172
173
  lazy,
173
174
  children,
174
175
  selectedValue,
175
- }: TabProps & ReturnType<typeof useTabs>): React.JSX.Element | null {
176
+ }: TabProps &
177
+ ReturnType<typeof useTabsContextValue>): React.JSX.Element | null {
176
178
  const childTabs = (Array.isArray(children) ? children : [children]).filter(
177
179
  Boolean
178
180
  ) as ReactElement<TabItemProps>[];
@@ -187,24 +189,17 @@ function TabContent({
187
189
  }
188
190
  return cloneElement(selectedTabItem, { className: "margin-top--md" });
189
191
  }
190
- return (
191
- <div className="margin-top--md">
192
- {childTabs.map((tabItem, i) =>
193
- cloneElement(tabItem, {
194
- key: i,
195
- hidden: tabItem.props.value !== selectedValue,
196
- })
197
- )}
198
- </div>
199
- );
192
+ return <div className="margin-top--md">{childTabs}</div>;
200
193
  }
201
194
  function TabsComponent(props: TabProps): React.JSX.Element {
202
- const tabs = useTabs(props);
195
+ const tabs = useTabsContextValue(props);
203
196
  return (
204
- <div className="openapi-tabs__container">
205
- <TabList {...props} {...tabs} />
206
- <TabContent {...props} {...tabs} />
207
- </div>
197
+ <TabsProvider value={tabs}>
198
+ <div className="openapi-tabs__container">
199
+ <TabList {...props} {...tabs} />
200
+ <TabContent {...props} {...tabs} />
201
+ </div>
202
+ </TabsProvider>
208
203
  );
209
204
  }
210
205
  export default function DiscriminatorTabs(props: TabProps): React.JSX.Element {
@@ -15,11 +15,12 @@ import React, {
15
15
 
16
16
  import {
17
17
  sanitizeTabsChildren,
18
+ type TabItemProps,
18
19
  TabProps,
20
+ TabsProvider,
19
21
  useScrollPositionBlocker,
20
- useTabs,
22
+ useTabsContextValue,
21
23
  } from "@docusaurus/theme-common/internal";
22
- import { TabItemProps } from "@docusaurus/theme-common/lib/utils/tabsUtils";
23
24
  import useIsBrowser from "@docusaurus/useIsBrowser";
24
25
  import { setAccept } from "@theme/ApiExplorer/Accept/slice";
25
26
  import { setContentType } from "@theme/ApiExplorer/ContentType/slice";
@@ -38,7 +39,9 @@ function TabList({
38
39
  selectValue,
39
40
  tabValues,
40
41
  schemaType,
41
- }: Props & TabProps & ReturnType<typeof useTabs>): React.JSX.Element {
42
+ }: Props &
43
+ TabProps &
44
+ ReturnType<typeof useTabsContextValue>): React.JSX.Element {
42
45
  const tabRefs: (HTMLLIElement | null)[] = [];
43
46
  const { blockElementScrollPositionUntilNextRender } =
44
47
  useScrollPositionBlocker();
@@ -208,7 +211,7 @@ function TabContent({
208
211
  lazy,
209
212
  children,
210
213
  selectedValue,
211
- }: Props & TabProps & ReturnType<typeof useTabs>) {
214
+ }: Props & TabProps & ReturnType<typeof useTabsContextValue>) {
212
215
  const childTabs = (Array.isArray(children) ? children : [children]).filter(
213
216
  Boolean
214
217
  ) as ReactElement<TabItemProps>[];
@@ -222,24 +225,17 @@ function TabContent({
222
225
  }
223
226
  return cloneElement(selectedTabItem, { className: "margin-top--md" });
224
227
  }
225
- return (
226
- <div className="margin-top--md">
227
- {childTabs.map((tabItem, i) =>
228
- cloneElement(tabItem, {
229
- key: i,
230
- hidden: tabItem.props.value !== selectedValue,
231
- })
232
- )}
233
- </div>
234
- );
228
+ return <div className="margin-top--md">{childTabs}</div>;
235
229
  }
236
230
  function TabsComponent(props: Props & TabProps): React.JSX.Element {
237
- const tabs = useTabs(props);
231
+ const tabs = useTabsContextValue(props);
238
232
  return (
239
- <div className="tabs-container">
240
- <TabList {...props} {...tabs} />
241
- <TabContent {...props} {...tabs} />
242
- </div>
233
+ <TabsProvider value={tabs}>
234
+ <div className="tabs-container">
235
+ <TabList {...props} {...tabs} />
236
+ <TabContent {...props} {...tabs} />
237
+ </div>
238
+ </TabsProvider>
243
239
  );
244
240
  }
245
241
  export default function MimeTabs(props: Props & TabProps) {
@@ -15,11 +15,12 @@ import React, {
15
15
 
16
16
  import {
17
17
  sanitizeTabsChildren,
18
+ type TabItemProps,
18
19
  TabProps,
20
+ TabsProvider,
19
21
  useScrollPositionBlocker,
20
- useTabs,
22
+ useTabsContextValue,
21
23
  } from "@docusaurus/theme-common/internal";
22
- import { TabItemProps } from "@docusaurus/theme-common/lib/utils/tabsUtils";
23
24
  import useIsBrowser from "@docusaurus/useIsBrowser";
24
25
  import clsx from "clsx";
25
26
 
@@ -29,7 +30,7 @@ function TabList({
29
30
  selectedValue,
30
31
  selectValue,
31
32
  tabValues,
32
- }: TabProps & ReturnType<typeof useTabs>) {
33
+ }: TabProps & ReturnType<typeof useTabsContextValue>) {
33
34
  const tabRefs: (HTMLLIElement | null)[] = [];
34
35
  const { blockElementScrollPositionUntilNextRender } =
35
36
  useScrollPositionBlocker();
@@ -171,7 +172,8 @@ function TabContent({
171
172
  lazy,
172
173
  children,
173
174
  selectedValue,
174
- }: TabProps & ReturnType<typeof useTabs>): React.JSX.Element | null {
175
+ }: TabProps &
176
+ ReturnType<typeof useTabsContextValue>): React.JSX.Element | null {
175
177
  const childTabs = (Array.isArray(children) ? children : [children]).filter(
176
178
  Boolean
177
179
  ) as ReactElement<TabItemProps>[];
@@ -185,24 +187,17 @@ function TabContent({
185
187
  }
186
188
  return cloneElement(selectedTabItem, { className: "margin-top--md" });
187
189
  }
188
- return (
189
- <div className="margin-top--md">
190
- {childTabs.map((tabItem, i) =>
191
- cloneElement(tabItem, {
192
- key: i,
193
- hidden: tabItem.props.value !== selectedValue,
194
- })
195
- )}
196
- </div>
197
- );
190
+ return <div className="margin-top--md">{childTabs}</div>;
198
191
  }
199
192
  function TabsComponent(props: TabProps): React.JSX.Element {
200
- const tabs = useTabs(props);
193
+ const tabs = useTabsContextValue(props);
201
194
  return (
202
- <div className="tabs-container">
203
- <TabList {...props} {...tabs} />
204
- <TabContent {...props} {...tabs} />
205
- </div>
195
+ <TabsProvider value={tabs}>
196
+ <div className="tabs-container">
197
+ <TabList {...props} {...tabs} />
198
+ <TabContent {...props} {...tabs} />
199
+ </div>
200
+ </TabsProvider>
206
201
  );
207
202
  }
208
203
  export default function OperationTabs(props: TabProps): React.JSX.Element {
@@ -7,13 +7,12 @@
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
-
13
10
  import BrowserOnly from "@docusaurus/BrowserOnly";
11
+ import { translate } from "@docusaurus/Translate";
14
12
  import Details from "@theme/Details";
15
13
  import ParamsItem from "@theme/ParamsItem";
16
14
  import SkeletonLoader from "@theme/SkeletonLoader";
15
+ import { OPENAPI_PARAMS_DETAILS } from "@theme/translationIds";
17
16
 
18
17
  interface Props {
19
18
  parameters: any[];
@@ -102,10 +102,34 @@ function ParamsItem({ param, ...rest }: Props) {
102
102
  </span>
103
103
  ));
104
104
 
105
+ const constValue = schema?.const;
106
+
105
107
  const renderQualifier = guard(getQualifierMessage(schema), (qualifier) => (
106
108
  <Markdown>{qualifier}</Markdown>
107
109
  ));
108
110
 
111
+ function renderConstValue() {
112
+ if (constValue === undefined) {
113
+ return undefined;
114
+ }
115
+ const label = translate({
116
+ id: OPENAPI_SCHEMA_ITEM.CONSTANT_VALUE,
117
+ message: "Constant value:",
118
+ });
119
+ return (
120
+ <div>
121
+ <strong>{label} </strong>
122
+ <span>
123
+ <code>
124
+ {typeof constValue === "string"
125
+ ? constValue
126
+ : JSON.stringify(constValue)}
127
+ </code>
128
+ </span>
129
+ </div>
130
+ );
131
+ }
132
+
109
133
  const renderDescription = guard(description, (description) => (
110
134
  <Markdown>{description}</Markdown>
111
135
  ));
@@ -173,6 +197,7 @@ function ParamsItem({ param, ...rest }: Props) {
173
197
  {renderDeprecated}
174
198
  </span>
175
199
  {renderQualifier}
200
+ {renderConstValue()}
176
201
  {renderDescription}
177
202
  {renderEnumDescriptions}
178
203
  {renderDefaultValue()}
@@ -7,17 +7,22 @@
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
-
13
10
  import BrowserOnly from "@docusaurus/BrowserOnly";
11
+ import { translate } from "@docusaurus/Translate";
14
12
  import Details from "@theme/Details";
15
13
  import Markdown from "@theme/Markdown";
16
14
  import MimeTabs from "@theme/MimeTabs"; // Assume these components exist
15
+ import {
16
+ ExampleFromSchema,
17
+ ResponseExample,
18
+ ResponseExamples,
19
+ } from "@theme/ResponseExamples";
17
20
  import SchemaNode from "@theme/Schema";
21
+ import SchemaTabs from "@theme/SchemaTabs";
18
22
  import SkeletonLoader from "@theme/SkeletonLoader";
19
23
  import TabItem from "@theme/TabItem";
20
- import { MediaTypeObject } from "docusaurus-plugin-openapi-docs/lib/openapi/types";
24
+ import { OPENAPI_REQUEST, OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";
25
+ import type { MediaTypeObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
21
26
 
22
27
  interface Props {
23
28
  style?: React.CSSProperties;
@@ -47,7 +52,11 @@ const RequestSchemaComponent: React.FC<Props> = ({ title, body, style }) => {
47
52
  return (
48
53
  <MimeTabs className="openapi-tabs__mime" schemaType="request" lazy>
49
54
  {mimeTypes.map((mimeType) => {
50
- const firstBody = body.content![mimeType].schema;
55
+ const mediaTypeObject = body.content![mimeType];
56
+ const firstBody = mediaTypeObject?.schema;
57
+ const requestExamples = mediaTypeObject?.examples;
58
+ const requestExample = mediaTypeObject?.example;
59
+
51
60
  if (
52
61
  firstBody === undefined ||
53
62
  (firstBody.properties &&
@@ -58,49 +67,73 @@ const RequestSchemaComponent: React.FC<Props> = ({ title, body, style }) => {
58
67
  return (
59
68
  // @ts-ignore
60
69
  <TabItem key={mimeType} label={mimeType} value={mimeType}>
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">
70
+ <SchemaTabs className="openapi-tabs__schema">
71
+ {/* @ts-ignore */}
72
+ <TabItem key={title} label={title} value={title}>
73
+ <div style={{ marginTop: "1rem" }}>
74
+ <Details
75
+ className="openapi-markdown__details mime"
76
+ data-collapsed={false}
77
+ open={true}
78
+ style={style}
79
+ summary={
80
+ <>
81
+ <summary>
82
+ <h3 className="openapi-markdown__details-summary-header-body">
77
83
  {translate({
78
- id: OPENAPI_SCHEMA_ITEM.REQUIRED,
79
- message: "required",
84
+ id: OPENAPI_REQUEST.BODY_TITLE,
85
+ message: title,
80
86
  })}
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>
87
+ {body.required === true && (
88
+ <span className="openapi-schema__required">
89
+ {translate({
90
+ id: OPENAPI_SCHEMA_ITEM.REQUIRED,
91
+ message: "required",
92
+ })}
93
+ </span>
94
+ )}
95
+ </h3>
96
+ </summary>
97
+ </>
98
+ }
99
+ >
100
+ <div style={{ textAlign: "left", marginLeft: "1rem" }}>
101
+ {body.description && (
102
+ <div
103
+ style={{ marginTop: "1rem", marginBottom: "1rem" }}
104
+ >
105
+ <Markdown>{body.description}</Markdown>
106
+ </div>
107
+ )}
92
108
  </div>
93
- )}
109
+ <ul style={{ marginLeft: "1rem" }}>
110
+ <SchemaNode
111
+ schema={firstBody}
112
+ schemaType="request"
113
+ schemaPath="requestBody"
114
+ />
115
+ </ul>
116
+ </Details>
94
117
  </div>
95
- <ul style={{ marginLeft: "1rem" }}>
96
- <SchemaNode
97
- schema={firstBody}
98
- schemaType="request"
99
- schemaPath="requestBody"
100
- />
101
- </ul>
102
- </Details>
103
- </div>
118
+ </TabItem>
119
+ {firstBody &&
120
+ !requestExample &&
121
+ !requestExamples &&
122
+ ExampleFromSchema({
123
+ schema: firstBody,
124
+ mimeType: mimeType,
125
+ })}
126
+ {requestExamples &&
127
+ ResponseExamples({
128
+ responseExamples: requestExamples,
129
+ mimeType,
130
+ })}
131
+ {requestExample &&
132
+ ResponseExample({
133
+ responseExample: requestExample,
134
+ mimeType,
135
+ })}
136
+ </SchemaTabs>
104
137
  </TabItem>
105
138
  );
106
139
  })}
@@ -109,8 +142,10 @@ const RequestSchemaComponent: React.FC<Props> = ({ title, body, style }) => {
109
142
  }
110
143
 
111
144
  const randomFirstKey = mimeTypes[0];
112
- const firstBody =
113
- body.content[randomFirstKey].schema ?? body.content![randomFirstKey];
145
+ const mediaTypeObject = body.content[randomFirstKey];
146
+ const firstBody = mediaTypeObject?.schema ?? body.content![randomFirstKey];
147
+ const requestExamples = mediaTypeObject?.examples;
148
+ const requestExample = mediaTypeObject?.example;
114
149
 
115
150
  if (firstBody === undefined) {
116
151
  return null;
@@ -120,50 +155,72 @@ const RequestSchemaComponent: React.FC<Props> = ({ title, body, style }) => {
120
155
  <MimeTabs className="openapi-tabs__mime" schemaType="request">
121
156
  {/* @ts-ignore */}
122
157
  <TabItem label={randomFirstKey} value={`${randomFirstKey}-schema`}>
123
- <Details
124
- className="openapi-markdown__details mime"
125
- data-collapsed={false}
126
- open={true}
127
- style={style}
128
- summary={
129
- <>
130
- <summary>
131
- <h3 className="openapi-markdown__details-summary-header-body">
132
- {translate({
133
- id: OPENAPI_REQUEST.BODY_TITLE,
134
- message: title,
135
- })}
136
- {firstBody.type === "array" && (
137
- <span style={{ opacity: "0.6" }}> array</span>
138
- )}
139
- {body.required && (
140
- <strong className="openapi-schema__required">
158
+ <SchemaTabs className="openapi-tabs__schema">
159
+ {/* @ts-ignore */}
160
+ <TabItem key={title} label={title} value={title}>
161
+ <Details
162
+ className="openapi-markdown__details mime"
163
+ data-collapsed={false}
164
+ open={true}
165
+ style={style}
166
+ summary={
167
+ <>
168
+ <summary>
169
+ <h3 className="openapi-markdown__details-summary-header-body">
141
170
  {translate({
142
- id: OPENAPI_SCHEMA_ITEM.REQUIRED,
143
- message: "required",
171
+ id: OPENAPI_REQUEST.BODY_TITLE,
172
+ message: title,
144
173
  })}
145
- </strong>
146
- )}
147
- </h3>
148
- </summary>
149
- </>
150
- }
151
- >
152
- <div style={{ textAlign: "left", marginLeft: "1rem" }}>
153
- {body.description && (
154
- <div style={{ marginTop: "1rem", marginBottom: "1rem" }}>
155
- <Markdown>{body.description}</Markdown>
174
+ {firstBody.type === "array" && (
175
+ <span style={{ opacity: "0.6" }}> array</span>
176
+ )}
177
+ {body.required && (
178
+ <strong className="openapi-schema__required">
179
+ {translate({
180
+ id: OPENAPI_SCHEMA_ITEM.REQUIRED,
181
+ message: "required",
182
+ })}
183
+ </strong>
184
+ )}
185
+ </h3>
186
+ </summary>
187
+ </>
188
+ }
189
+ >
190
+ <div style={{ textAlign: "left", marginLeft: "1rem" }}>
191
+ {body.description && (
192
+ <div style={{ marginTop: "1rem", marginBottom: "1rem" }}>
193
+ <Markdown>{body.description}</Markdown>
194
+ </div>
195
+ )}
156
196
  </div>
157
- )}
158
- </div>
159
- <ul style={{ marginLeft: "1rem" }}>
160
- <SchemaNode
161
- schema={firstBody}
162
- schemaType="request"
163
- schemaPath="requestBody"
164
- />
165
- </ul>
166
- </Details>
197
+ <ul style={{ marginLeft: "1rem" }}>
198
+ <SchemaNode
199
+ schema={firstBody}
200
+ schemaType="request"
201
+ schemaPath="requestBody"
202
+ />
203
+ </ul>
204
+ </Details>
205
+ </TabItem>
206
+ {firstBody &&
207
+ !requestExample &&
208
+ !requestExamples &&
209
+ ExampleFromSchema({
210
+ schema: firstBody,
211
+ mimeType: randomFirstKey,
212
+ })}
213
+ {requestExamples &&
214
+ ResponseExamples({
215
+ responseExamples: requestExamples,
216
+ mimeType: randomFirstKey,
217
+ })}
218
+ {requestExample &&
219
+ ResponseExample({
220
+ responseExample: requestExample,
221
+ mimeType: randomFirstKey,
222
+ })}
223
+ </SchemaTabs>
167
224
  </TabItem>
168
225
  </MimeTabs>
169
226
  );
@@ -9,7 +9,7 @@ import React from "react";
9
9
 
10
10
  import SchemaItem from "@theme/SchemaItem";
11
11
 
12
- import { getQualifierMessage, getSchemaName } from "../../markdown/schema";
12
+ import { getSchemaName } from "../../markdown/schema";
13
13
 
14
14
  interface ResponseHeadersProps {
15
15
  description?: string;
@@ -35,7 +35,6 @@ export const ResponseHeaders: React.FC<{
35
35
  name={name}
36
36
  collapsible={false}
37
37
  schemaName={getSchemaName(schema)}
38
- qualifierMessage={getQualifierMessage(schema)}
39
38
  schema={schema}
40
39
  discriminator={false}
41
40
  children={null}