@gitbook/react-openapi 1.1.9 → 1.2.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 (177) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/InteractiveSection.d.ts +4 -0
  3. package/dist/InteractiveSection.jsx +14 -13
  4. package/dist/OpenAPICodeSample.d.ts +3 -2
  5. package/dist/OpenAPICodeSample.jsx +8 -12
  6. package/dist/OpenAPICodeSampleInteractive.d.ts +3 -0
  7. package/dist/OpenAPICodeSampleInteractive.jsx +37 -49
  8. package/dist/OpenAPICodeSampleSelector.d.ts +14 -0
  9. package/dist/OpenAPICodeSampleSelector.jsx +44 -0
  10. package/dist/OpenAPICopyButton.d.ts +2 -0
  11. package/dist/OpenAPICopyButton.jsx +5 -2
  12. package/dist/OpenAPIDisclosure.d.ts +4 -3
  13. package/dist/OpenAPIDisclosure.jsx +8 -11
  14. package/dist/OpenAPIDisclosureGroup.d.ts +7 -3
  15. package/dist/OpenAPIDisclosureGroup.jsx +18 -18
  16. package/dist/OpenAPIExample.d.ts +16 -0
  17. package/dist/OpenAPIExample.jsx +36 -0
  18. package/dist/OpenAPIMediaType.d.ts +21 -0
  19. package/dist/OpenAPIMediaType.jsx +61 -0
  20. package/dist/OpenAPIOperation.d.ts +3 -2
  21. package/dist/OpenAPIOperation.jsx +9 -72
  22. package/dist/OpenAPIOperationDescription.d.ts +9 -0
  23. package/dist/OpenAPIOperationDescription.jsx +22 -0
  24. package/dist/OpenAPIOperationStability.d.ts +9 -0
  25. package/dist/OpenAPIOperationStability.jsx +27 -0
  26. package/dist/OpenAPIPath.d.ts +12 -2
  27. package/dist/OpenAPIPath.jsx +10 -4
  28. package/dist/OpenAPIRequestBody.d.ts +3 -1
  29. package/dist/OpenAPIRequestBody.jsx +4 -3
  30. package/dist/OpenAPIResponse.d.ts +1 -1
  31. package/dist/OpenAPIResponse.jsx +1 -1
  32. package/dist/OpenAPIResponseExample.d.ts +4 -3
  33. package/dist/OpenAPIResponseExample.jsx +24 -154
  34. package/dist/OpenAPIResponseExampleContent.d.ts +19 -0
  35. package/dist/OpenAPIResponseExampleContent.jsx +57 -0
  36. package/dist/OpenAPIResponses.d.ts +1 -1
  37. package/dist/OpenAPIResponses.jsx +49 -36
  38. package/dist/OpenAPISchema.d.ts +1 -1
  39. package/dist/OpenAPISchema.jsx +121 -20
  40. package/dist/OpenAPISchemaName.d.ts +2 -0
  41. package/dist/OpenAPISchemaName.jsx +21 -17
  42. package/dist/OpenAPISchemaServer.d.ts +1 -1
  43. package/dist/OpenAPISecurities.d.ts +2 -1
  44. package/dist/OpenAPISecurities.jsx +11 -10
  45. package/dist/OpenAPISelect.d.ts +22 -0
  46. package/dist/OpenAPISelect.jsx +43 -0
  47. package/dist/OpenAPISpec.d.ts +3 -2
  48. package/dist/OpenAPISpec.jsx +11 -9
  49. package/dist/OpenAPITabs.jsx +9 -9
  50. package/dist/OpenAPIWebhook.d.ts +10 -0
  51. package/dist/OpenAPIWebhook.jsx +23 -0
  52. package/dist/OpenAPIWebhookExample.d.ts +6 -0
  53. package/dist/OpenAPIWebhookExample.jsx +41 -0
  54. package/dist/ScalarApiButton.d.ts +2 -0
  55. package/dist/ScalarApiButton.jsx +4 -3
  56. package/dist/StaticSection.d.ts +4 -1
  57. package/dist/StaticSection.jsx +13 -4
  58. package/dist/code-samples.js +57 -39
  59. package/dist/common/OpenAPIColumnSpec.d.ts +6 -0
  60. package/dist/common/OpenAPIColumnSpec.jsx +20 -0
  61. package/dist/common/OpenAPIOperationDescription.d.ts +6 -0
  62. package/dist/common/OpenAPIOperationDescription.jsx +19 -0
  63. package/dist/common/OpenAPIStability.d.ts +4 -0
  64. package/dist/common/OpenAPIStability.jsx +15 -0
  65. package/dist/common/OpenAPISummary.d.ts +6 -0
  66. package/dist/common/OpenAPISummary.jsx +30 -0
  67. package/dist/context.d.ts +75 -0
  68. package/dist/context.js +43 -0
  69. package/dist/generateSchemaExample.js +4 -0
  70. package/dist/getOrCreateStoreByKey.d.ts +10 -0
  71. package/dist/getOrCreateStoreByKey.js +19 -0
  72. package/dist/index.d.ts +5 -1
  73. package/dist/index.js +3 -0
  74. package/dist/resolveOpenAPIOperation.js +10 -5
  75. package/dist/resolveOpenAPIWebhook.d.ts +11 -0
  76. package/dist/resolveOpenAPIWebhook.js +127 -0
  77. package/dist/schemas/OpenAPISchemas.d.ts +5 -6
  78. package/dist/schemas/OpenAPISchemas.jsx +52 -49
  79. package/dist/schemas/resolveOpenAPISchemas.d.ts +4 -3
  80. package/dist/schemas/resolveOpenAPISchemas.js +0 -1
  81. package/dist/stringifyOpenAPI.d.ts +1 -1
  82. package/dist/stringifyOpenAPI.js +6 -3
  83. package/dist/translate.d.ts +10 -0
  84. package/dist/translate.jsx +75 -0
  85. package/dist/translations/de.d.ts +37 -0
  86. package/dist/translations/de.js +37 -0
  87. package/dist/translations/en.d.ts +37 -0
  88. package/dist/translations/en.js +37 -0
  89. package/dist/translations/es.d.ts +37 -0
  90. package/dist/translations/es.js +37 -0
  91. package/dist/translations/fr.d.ts +37 -0
  92. package/dist/translations/fr.js +37 -0
  93. package/dist/translations/index.d.ts +341 -0
  94. package/dist/translations/index.js +27 -0
  95. package/dist/translations/ja.d.ts +37 -0
  96. package/dist/translations/ja.js +37 -0
  97. package/dist/translations/nl.d.ts +37 -0
  98. package/dist/translations/nl.js +37 -0
  99. package/dist/translations/no.d.ts +37 -0
  100. package/dist/translations/no.js +37 -0
  101. package/dist/translations/pt-br.d.ts +37 -0
  102. package/dist/translations/pt-br.js +37 -0
  103. package/dist/translations/types.d.ts +5 -0
  104. package/dist/translations/types.js +1 -0
  105. package/dist/translations/zh.d.ts +37 -0
  106. package/dist/translations/zh.js +37 -0
  107. package/dist/tsconfig.build.tsbuildinfo +1 -1
  108. package/dist/types.d.ts +12 -48
  109. package/dist/util/example.d.ts +35 -0
  110. package/dist/util/example.jsx +103 -0
  111. package/dist/utils.d.ts +18 -0
  112. package/dist/utils.js +57 -0
  113. package/package.json +3 -3
  114. package/src/InteractiveSection.tsx +22 -18
  115. package/src/OpenAPICodeSample.tsx +26 -15
  116. package/src/OpenAPICodeSampleInteractive.tsx +67 -70
  117. package/src/OpenAPICodeSampleSelector.tsx +94 -0
  118. package/src/OpenAPICopyButton.tsx +7 -2
  119. package/src/OpenAPIDisclosure.tsx +20 -22
  120. package/src/OpenAPIDisclosureGroup.tsx +40 -22
  121. package/src/OpenAPIExample.tsx +55 -0
  122. package/src/OpenAPIMediaType.tsx +139 -0
  123. package/src/OpenAPIOperation.tsx +11 -104
  124. package/src/OpenAPIOperationDescription.tsx +34 -0
  125. package/src/OpenAPIOperationStability.tsx +39 -0
  126. package/src/OpenAPIPath.tsx +26 -6
  127. package/src/OpenAPIRequestBody.tsx +9 -4
  128. package/src/OpenAPIResponse.tsx +2 -2
  129. package/src/OpenAPIResponseExample.tsx +41 -215
  130. package/src/OpenAPIResponseExampleContent.tsx +123 -0
  131. package/src/OpenAPIResponses.tsx +83 -62
  132. package/src/OpenAPISchema.test.ts +80 -0
  133. package/src/OpenAPISchema.tsx +149 -25
  134. package/src/OpenAPISchemaName.tsx +28 -19
  135. package/src/OpenAPISchemaServer.tsx +1 -1
  136. package/src/OpenAPISecurities.tsx +46 -12
  137. package/src/OpenAPISelect.tsx +96 -0
  138. package/src/OpenAPISpec.tsx +21 -10
  139. package/src/OpenAPITabs.tsx +9 -9
  140. package/src/OpenAPIWebhook.tsx +33 -0
  141. package/src/OpenAPIWebhookExample.tsx +60 -0
  142. package/src/ScalarApiButton.tsx +6 -6
  143. package/src/StaticSection.tsx +37 -5
  144. package/src/code-samples.test.ts +3 -1
  145. package/src/code-samples.ts +67 -54
  146. package/src/common/OpenAPIColumnSpec.tsx +31 -0
  147. package/src/common/OpenAPIOperationDescription.tsx +31 -0
  148. package/src/common/OpenAPIStability.tsx +23 -0
  149. package/src/common/OpenAPISummary.tsx +45 -0
  150. package/src/context.ts +99 -0
  151. package/src/generateSchemaExample.test.ts +1020 -0
  152. package/src/generateSchemaExample.ts +5 -0
  153. package/src/getOrCreateStoreByKey.ts +33 -0
  154. package/src/index.ts +5 -1
  155. package/src/resolveOpenAPIOperation.ts +14 -3
  156. package/src/resolveOpenAPIWebhook.ts +99 -0
  157. package/src/schemas/OpenAPISchemas.tsx +76 -71
  158. package/src/schemas/resolveOpenAPISchemas.ts +4 -5
  159. package/src/stringifyOpenAPI.ts +11 -3
  160. package/src/translate.tsx +80 -0
  161. package/src/translations/de.ts +37 -0
  162. package/src/translations/en.ts +37 -0
  163. package/src/translations/es.ts +37 -0
  164. package/src/translations/fr.ts +37 -0
  165. package/src/translations/index.ts +33 -0
  166. package/src/translations/ja.ts +37 -0
  167. package/src/translations/nl.ts +37 -0
  168. package/src/translations/no.ts +37 -0
  169. package/src/translations/pt-br.ts +37 -0
  170. package/src/translations/types.ts +7 -0
  171. package/src/translations/zh.ts +37 -0
  172. package/src/types.ts +11 -46
  173. package/src/util/example.tsx +129 -0
  174. package/src/utils.ts +67 -0
  175. package/dist/useSyncedTabsGlobalState.d.ts +0 -10
  176. package/dist/useSyncedTabsGlobalState.js +0 -20
  177. package/src/useSyncedTabsGlobalState.ts +0 -35
@@ -0,0 +1,139 @@
1
+ 'use client';
2
+
3
+ import type { Key } from 'react-aria';
4
+ import { OpenAPIEmptyExample } from './OpenAPIExample';
5
+ import { OpenAPISelect, OpenAPISelectItem, useSelectState } from './OpenAPISelect';
6
+ import { StaticSection } from './StaticSection';
7
+ import type { OpenAPIClientContext } from './context';
8
+
9
+ type OpenAPIMediaTypeItem = OpenAPISelectItem & {
10
+ body: React.ReactNode;
11
+ examples?: OpenAPIMediaTypeItem[];
12
+ };
13
+
14
+ /**
15
+ * Get the state of the response examples select.
16
+ */
17
+ export function useMediaTypesState(stateKey: string | undefined, initialKey: Key = 'default') {
18
+ return useSelectState(stateKey, initialKey);
19
+ }
20
+
21
+ function useMediaTypeExamplesState(stateKey: string | undefined, initialKey: Key = 'default') {
22
+ return useSelectState(stateKey, initialKey);
23
+ }
24
+
25
+ export function OpenAPIMediaTypeContent(props: {
26
+ items: OpenAPIMediaTypeItem[];
27
+ selectIcon?: React.ReactNode;
28
+ stateKey: string;
29
+ context: OpenAPIClientContext;
30
+ }) {
31
+ const { stateKey, items, selectIcon, context } = props;
32
+ const state = useMediaTypesState(stateKey, items[0]?.key);
33
+
34
+ const examples = items.find((item) => item.key === state.key)?.examples ?? [];
35
+
36
+ if (!items.length && !examples.length) {
37
+ return null;
38
+ }
39
+
40
+ return (
41
+ <StaticSection
42
+ footer={
43
+ items.length > 1 || examples.length > 1 ? (
44
+ <OpenAPIMediaTypeFooter
45
+ items={items}
46
+ examples={examples}
47
+ selectIcon={selectIcon}
48
+ stateKey={stateKey}
49
+ />
50
+ ) : null
51
+ }
52
+ className="openapi-response-media-types-examples"
53
+ >
54
+ <OpenAPIMediaTypeBody
55
+ context={context}
56
+ stateKey={stateKey}
57
+ items={items}
58
+ examples={examples}
59
+ />
60
+ </StaticSection>
61
+ );
62
+ }
63
+
64
+ function OpenAPIMediaTypeFooter(props: {
65
+ items: OpenAPIMediaTypeItem[];
66
+ examples?: OpenAPIMediaTypeItem[];
67
+ selectIcon?: React.ReactNode;
68
+ stateKey: string;
69
+ }) {
70
+ const { items, examples, stateKey, selectIcon } = props;
71
+
72
+ return (
73
+ <>
74
+ {items.length > 1 && (
75
+ <OpenAPISelect
76
+ icon={selectIcon}
77
+ items={items}
78
+ stateKey={stateKey}
79
+ placement="bottom start"
80
+ >
81
+ {items.map((item) => (
82
+ <OpenAPISelectItem key={item.key} id={item.key} value={item}>
83
+ <span>{item.label}</span>
84
+ </OpenAPISelectItem>
85
+ ))}
86
+ </OpenAPISelect>
87
+ )}
88
+
89
+ {examples && examples.length > 1 ? (
90
+ <OpenAPISelect
91
+ icon={selectIcon}
92
+ items={examples}
93
+ stateKey={`${stateKey}-examples`}
94
+ placement="bottom start"
95
+ >
96
+ {examples.map((example) => (
97
+ <OpenAPISelectItem key={example.key} id={example.key} value={example}>
98
+ <span>{example.label}</span>
99
+ </OpenAPISelectItem>
100
+ ))}
101
+ </OpenAPISelect>
102
+ ) : null}
103
+ </>
104
+ );
105
+ }
106
+
107
+ function OpenAPIMediaTypeBody(props: {
108
+ items: OpenAPIMediaTypeItem[];
109
+ examples?: OpenAPIMediaTypeItem[];
110
+ stateKey: string;
111
+ context: OpenAPIClientContext;
112
+ }) {
113
+ const { stateKey, items, examples, context } = props;
114
+ const state = useMediaTypesState(stateKey, items[0]?.key);
115
+
116
+ const selectedItem = items.find((item) => item.key === state.key) ?? items[0];
117
+
118
+ const exampleState = useMediaTypeExamplesState(
119
+ `${stateKey}-examples`,
120
+ selectedItem?.examples?.[0]?.key
121
+ );
122
+
123
+ if (!selectedItem) {
124
+ return null;
125
+ }
126
+
127
+ if (examples) {
128
+ const selectedExample =
129
+ examples.find((example) => example.key === exampleState.key) ?? examples[0];
130
+
131
+ if (!selectedExample) {
132
+ return <OpenAPIEmptyExample context={context} />;
133
+ }
134
+
135
+ return selectedExample.body;
136
+ }
137
+
138
+ return selectedItem.body;
139
+ }
@@ -1,17 +1,10 @@
1
1
  import clsx from 'clsx';
2
-
3
- import type {
4
- OpenAPICustomOperationProperties,
5
- OpenAPIStability,
6
- OpenAPIV3,
7
- } from '@gitbook/openapi-parser';
8
- import { Markdown } from './Markdown';
9
2
  import { OpenAPICodeSample } from './OpenAPICodeSample';
10
- import { OpenAPIPath } from './OpenAPIPath';
11
3
  import { OpenAPIResponseExample } from './OpenAPIResponseExample';
12
- import { OpenAPISpec } from './OpenAPISpec';
13
- import type { OpenAPIClientContext, OpenAPIContextProps, OpenAPIOperationData } from './types';
14
- import { resolveDescription } from './utils';
4
+ import { OpenAPIColumnSpec } from './common/OpenAPIColumnSpec';
5
+ import { OpenAPISummary } from './common/OpenAPISummary';
6
+ import { type OpenAPIContextInput, resolveOpenAPIContext } from './context';
7
+ import type { OpenAPIOperationData } from './types';
15
8
 
16
9
  /**
17
10
  * Display an interactive OpenAPI operation.
@@ -19,110 +12,24 @@ import { resolveDescription } from './utils';
19
12
  export function OpenAPIOperation(props: {
20
13
  className?: string;
21
14
  data: OpenAPIOperationData;
22
- context: OpenAPIContextProps;
15
+ context: OpenAPIContextInput;
23
16
  }) {
24
- const { className, data, context } = props;
25
- const { operation } = data;
17
+ const { className, data, context: contextInput } = props;
26
18
 
27
- const clientContext: OpenAPIClientContext = {
28
- defaultInteractiveOpened: context.defaultInteractiveOpened,
29
- icons: context.icons,
30
- blockKey: context.blockKey,
31
- };
19
+ const context = resolveOpenAPIContext(contextInput);
32
20
 
33
21
  return (
34
22
  <div className={clsx('openapi-operation', className)}>
35
- <div className="openapi-summary" id={operation.summary ? undefined : context.id}>
36
- {(operation.deprecated || operation['x-stability']) && (
37
- <div className="openapi-summary-tags">
38
- {operation.deprecated && (
39
- <div className="openapi-deprecated">Deprecated</div>
40
- )}
41
- {operation['x-stability'] && (
42
- <OpenAPIOperationStability stability={operation['x-stability']} />
43
- )}
44
- </div>
45
- )}
46
- {operation.summary
47
- ? context.renderHeading({
48
- deprecated: operation.deprecated ?? false,
49
- stability: operation['x-stability'],
50
- title: operation.summary,
51
- })
52
- : null}
53
- <OpenAPIPath data={data} context={context} />
54
- </div>
23
+ <OpenAPISummary data={data} context={context} />
55
24
  <div className="openapi-columns">
56
- <div className="openapi-column-spec">
57
- {operation['x-deprecated-sunset'] ? (
58
- <div className="openapi-deprecated-sunset openapi-description openapi-markdown">
59
- This operation is deprecated and will be sunset on{' '}
60
- <span className="openapi-deprecated-sunset-date">
61
- {operation['x-deprecated-sunset']}
62
- </span>
63
- {'.'}
64
- </div>
65
- ) : null}
66
- <OpenAPIOperationDescription operation={operation} context={context} />
67
- <OpenAPISpec data={data} context={clientContext} />
68
- </div>
25
+ <OpenAPIColumnSpec data={data} context={context} />
69
26
  <div className="openapi-column-preview">
70
27
  <div className="openapi-column-preview-body">
71
- <OpenAPICodeSample {...props} />
72
- <OpenAPIResponseExample {...props} />
28
+ <OpenAPICodeSample data={data} context={context} />
29
+ <OpenAPIResponseExample data={data} context={context} />
73
30
  </div>
74
31
  </div>
75
32
  </div>
76
33
  </div>
77
34
  );
78
35
  }
79
-
80
- function OpenAPIOperationDescription(props: {
81
- operation: OpenAPIV3.OperationObject<OpenAPICustomOperationProperties>;
82
- context: OpenAPIContextProps;
83
- }) {
84
- const { operation } = props;
85
- if (operation['x-gitbook-description-document']) {
86
- return (
87
- <div className="openapi-intro">
88
- {props.context.renderDocument({
89
- document: operation['x-gitbook-description-document'],
90
- })}
91
- </div>
92
- );
93
- }
94
-
95
- const description = resolveDescription(operation);
96
- if (!description) {
97
- return null;
98
- }
99
-
100
- return (
101
- <div className="openapi-intro">
102
- <Markdown className="openapi-description" source={description} />
103
- </div>
104
- );
105
- }
106
-
107
- const stabilityEnum = {
108
- experimental: 'Experimental',
109
- alpha: 'Alpha',
110
- beta: 'Beta',
111
- stable: 'Stable',
112
- } as const;
113
-
114
- function OpenAPIOperationStability(props: { stability: OpenAPIStability }) {
115
- const { stability } = props;
116
-
117
- const foundStability = stabilityEnum[stability];
118
-
119
- if (!foundStability) {
120
- return null;
121
- }
122
-
123
- return (
124
- <div className={`openapi-stability openapi-stability-${foundStability.toLowerCase()}`}>
125
- {foundStability}
126
- </div>
127
- );
128
- }
@@ -0,0 +1,34 @@
1
+ import type { OpenAPICustomOperationProperties, OpenAPIV3 } from '@gitbook/openapi-parser';
2
+ import { Markdown } from './Markdown';
3
+ import type { OpenAPIContext } from './context';
4
+ import { resolveDescription } from './utils';
5
+
6
+ /**
7
+ * Display the description of an OpenAPI operation.
8
+ */
9
+ export function OpenAPIOperationDescription(props: {
10
+ operation: OpenAPIV3.OperationObject<OpenAPICustomOperationProperties>;
11
+ context: OpenAPIContext;
12
+ }) {
13
+ const { operation } = props;
14
+ if (operation['x-gitbook-description-document']) {
15
+ return (
16
+ <div className="openapi-intro">
17
+ {props.context.renderDocument({
18
+ document: operation['x-gitbook-description-document'],
19
+ })}
20
+ </div>
21
+ );
22
+ }
23
+
24
+ const description = resolveDescription(operation);
25
+ if (!description) {
26
+ return null;
27
+ }
28
+
29
+ return (
30
+ <div className="openapi-intro">
31
+ <Markdown className="openapi-description" source={description} />
32
+ </div>
33
+ );
34
+ }
@@ -0,0 +1,39 @@
1
+ import type { OpenAPIStability } from '@gitbook/openapi-parser';
2
+ import type { OpenAPIContext } from './context';
3
+ import { t } from './translate';
4
+
5
+ /**
6
+ * Display the stability of an OpenAPI operation.
7
+ */
8
+ export function OpenAPIOperationStability(props: {
9
+ stability: OpenAPIStability;
10
+ context: OpenAPIContext;
11
+ }) {
12
+ const { stability, context } = props;
13
+
14
+ const stabilityLabel = getStabilityLabel(stability, context);
15
+
16
+ if (!stabilityLabel) {
17
+ return null;
18
+ }
19
+
20
+ return (
21
+ <div className={`openapi-stability openapi-stability-${stability}`}>{stabilityLabel}</div>
22
+ );
23
+ }
24
+
25
+ /**
26
+ * Get the stability label for the given stability level.
27
+ */
28
+ function getStabilityLabel(stability: OpenAPIStability, context: OpenAPIContext) {
29
+ switch (stability) {
30
+ case 'experimental':
31
+ return t(context.translation, 'stability_experimental');
32
+ case 'alpha':
33
+ return t(context.translation, 'stability_alpha');
34
+ case 'beta':
35
+ return t(context.translation, 'stability_beta');
36
+ default:
37
+ return null;
38
+ }
39
+ }
@@ -1,5 +1,6 @@
1
1
  import { OpenAPICopyButton } from './OpenAPICopyButton';
2
- import type { OpenAPIContextProps, OpenAPIOperationData } from './types';
2
+ import { type OpenAPIUniversalContext, getOpenAPIClientContext } from './context';
3
+ import type { OpenAPIOperationData } from './types';
3
4
  import { getDefaultServerURL } from './util/server';
4
5
 
5
6
  /**
@@ -7,25 +8,44 @@ import { getDefaultServerURL } from './util/server';
7
8
  */
8
9
  export function OpenAPIPath(props: {
9
10
  data: OpenAPIOperationData;
10
- context: OpenAPIContextProps;
11
+ context: OpenAPIUniversalContext;
12
+ /** Whether to show the server URL.
13
+ * @default true
14
+ */
15
+ withServer?: boolean;
16
+ /**
17
+ * Whether the path is copyable.
18
+ * @default true
19
+ */
20
+ canCopy?: boolean;
11
21
  }) {
12
- const { data } = props;
22
+ const { data, context, withServer = true, canCopy = true } = props;
13
23
  const { method, path, operation } = data;
14
24
 
15
25
  const server = getDefaultServerURL(data.servers);
16
26
  const formattedPath = formatPath(path);
17
27
 
28
+ const element = (() => {
29
+ return (
30
+ <>
31
+ {withServer ? <span className="openapi-path-server">{server}</span> : null}
32
+ {formattedPath}
33
+ </>
34
+ );
35
+ })();
36
+
18
37
  return (
19
38
  <div className="openapi-path">
20
39
  <div className={`openapi-method openapi-method-${method}`}>{method}</div>
21
40
 
22
41
  <OpenAPICopyButton
23
- value={server + path}
42
+ value={`${withServer ? server : ''}${path}`}
24
43
  className="openapi-path-title"
25
44
  data-deprecated={operation.deprecated}
45
+ isDisabled={!canCopy}
46
+ context={getOpenAPIClientContext(context)}
26
47
  >
27
- <span className="openapi-path-server">{server}</span>
28
- {formattedPath}
48
+ {element}
29
49
  </OpenAPICopyButton>
30
50
  </div>
31
51
  );
@@ -1,8 +1,10 @@
1
1
  import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
2
  import { InteractiveSection } from './InteractiveSection';
3
3
  import { OpenAPIRootSchema } from './OpenAPISchemaServer';
4
- import type { OpenAPIClientContext } from './types';
5
- import { checkIsReference } from './utils';
4
+ import type { OpenAPIClientContext } from './context';
5
+ import { t } from './translate';
6
+ import type { OpenAPIOperationData, OpenAPIWebhookData } from './types';
7
+ import { checkIsReference, createStateKey } from './utils';
6
8
 
7
9
  /**
8
10
  * Display an interactive request body.
@@ -10,8 +12,9 @@ import { checkIsReference } from './utils';
10
12
  export function OpenAPIRequestBody(props: {
11
13
  requestBody: OpenAPIV3.RequestBodyObject | OpenAPIV3.ReferenceObject;
12
14
  context: OpenAPIClientContext;
15
+ data: OpenAPIOperationData | OpenAPIWebhookData;
13
16
  }) {
14
- const { requestBody, context } = props;
17
+ const { requestBody, context, data } = props;
15
18
 
16
19
  if (checkIsReference(requestBody)) {
17
20
  return null;
@@ -19,8 +22,10 @@ export function OpenAPIRequestBody(props: {
19
22
 
20
23
  return (
21
24
  <InteractiveSection
22
- header="Body"
25
+ header={t(context.translation, 'name' in data ? 'payload' : 'body')}
23
26
  className="openapi-requestbody"
27
+ stateKey={createStateKey('request-body-media-type', context.blockKey)}
28
+ selectIcon={context.icons.chevronDown}
24
29
  tabs={Object.entries(requestBody.content ?? {}).map(
25
30
  ([contentType, mediaTypeObject]) => {
26
31
  return {
@@ -1,7 +1,7 @@
1
1
  import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
2
  import { OpenAPIDisclosure } from './OpenAPIDisclosure';
3
3
  import { OpenAPISchemaProperties } from './OpenAPISchemaServer';
4
- import type { OpenAPIClientContext } from './types';
4
+ import type { OpenAPIClientContext } from './context';
5
5
  import { parameterToProperty, resolveDescription } from './utils';
6
6
 
7
7
  /**
@@ -27,7 +27,7 @@ export function OpenAPIResponse(props: {
27
27
  return (
28
28
  <div className="openapi-response-body">
29
29
  {headers.length > 0 ? (
30
- <OpenAPIDisclosure context={context} label="Headers">
30
+ <OpenAPIDisclosure icon={context.icons.plus} label="Headers">
31
31
  <OpenAPISchemaProperties
32
32
  properties={headers.map(([name, header]) =>
33
33
  parameterToProperty({ name, ...header })